mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 23:17:20 +01:00
Merge pull request #587 from Cyberboss/FixRightOverlap [NugetDeploy]
Fix rights overlap for ChatBotRights. Add unit test to prevent it
This commit is contained in:
@@ -37,16 +37,16 @@ namespace Tgstation.Server.Api.Rights
|
||||
/// </summary>
|
||||
Read = 32,
|
||||
/// <summary>
|
||||
/// User can change <see cref="Models.Internal.ChatBot.Name"/>
|
||||
/// </summary>
|
||||
WriteName = 32,
|
||||
/// <summary>
|
||||
/// User can create new <see cref="Models.ChatBot"/>
|
||||
/// </summary>
|
||||
Create = 64,
|
||||
/// <summary>
|
||||
/// User can delete <see cref="Models.ChatBot"/>
|
||||
/// </summary>
|
||||
Delete = 128
|
||||
Delete = 128,
|
||||
/// <summary>
|
||||
/// User can change <see cref="Models.Internal.ChatBot.Name"/>
|
||||
/// </summary>
|
||||
WriteName = 256,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ namespace Tgstation.Server.Api.Rights
|
||||
/// <summary>
|
||||
/// User may list files
|
||||
/// </summary>
|
||||
List = 3
|
||||
List = 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<FileVersion>4.0.0.0</FileVersion>
|
||||
<PackageTags>json web api tgstation-server tgstation ss13 byond</PackageTags>
|
||||
<PackageReleaseNotes>Prototype release</PackageReleaseNotes>
|
||||
<Version>4.0.0.0-preview4</Version>
|
||||
<Version>4.0.0.0-preview5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DebugType>Full</DebugType>
|
||||
<Version>4.0.0.0-preview9</Version>
|
||||
<Version>4.0.0.0-preview10</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>Cyberboss</Authors>
|
||||
<Company>/tg/station 13</Company>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Tgstation.Server.Api.Rights.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for <see cref="Rights"/>
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class TestRights
|
||||
{
|
||||
[TestMethod]
|
||||
public void TestAllPowerOfTwo()
|
||||
{
|
||||
var ulongType = typeof(ulong);
|
||||
foreach (var I in Enum.GetValues(typeof(RightsType)).Cast<RightsType>())
|
||||
{
|
||||
var expectedLog = -1;
|
||||
var rightType = RightsHelper.RightToType(I);
|
||||
foreach (var J in Enum.GetValues(rightType))
|
||||
{
|
||||
Assert.AreEqual(ulongType, Enum.GetUnderlyingType(rightType));
|
||||
var asUlong = (ulong)J;
|
||||
var isOne = asUlong == 1;
|
||||
if(!isOne)
|
||||
Assert.AreEqual(0U, asUlong % 2, String.Format("Enum {0} of {1} is not a power of 2!", Enum.GetName(rightType, asUlong), rightType));
|
||||
|
||||
if (expectedLog > -1)
|
||||
{
|
||||
var log = Math.Log(asUlong, 2);
|
||||
if (log != expectedLog)
|
||||
Assert.Fail(String.Format("Expected Log2({1}) == {0} to come next for {2}, got {3} instead!", expectedLog, Enum.GetName(rightType, asUlong), rightType, log));
|
||||
}
|
||||
++expectedLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user