Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of root flags in RequirePermissionsOr #700

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 106 additions & 1 deletion managed/CounterStrikeSharp.API.Tests/AdminTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void ShouldAddPlayerToGroup()
AdminManager.AddPlayerToGroup(new SteamID("STEAM_0:1:3"), "#css/root");
var adminData = AdminManager.GetPlayerAdminData(new SteamID("STEAM_0:1:3"));
Assert.NotNull(adminData);
Assert.True(adminData.Groups.Any());
Assert.Equal("#css/root", adminData.Groups.Single());
}

Expand Down Expand Up @@ -116,4 +117,108 @@ public void ShouldAddCommandPermissionOverridesWithEmpty()
Assert.True(AdminManager.CommandIsOverriden("runtime_command_b"));
Assert.False(AdminManager.GetPermissionOverrides("runtime_command_b").Any());
}
}

[Fact]
public void ShouldAllowRootFlagInRequiresPermissions()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265732, "@css/root"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265732, "@css/root");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265732, "@css/root"));

var adminData = AdminManager.GetPlayerAdminData((SteamID)76561197960265732);
Assert.NotNull(adminData);
Assert.True(adminData.DomainHasRootFlag("css"));

var requirePerms = new RequiresPermissions("@css/ban");
Assert.NotNull(requirePerms);
Assert.True(requirePerms.CanExecuteCommand((SteamID)76561197960265732));
}

[Fact]
public void ShouldRequiresPermissionsPass()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265738, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265738, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265738, "@css/ban"));

var requirePerms = new RequiresPermissions("@css/ban");
Assert.NotNull(requirePerms);
Assert.True(requirePerms.CanExecuteCommand((SteamID)76561197960265738));
}

[Fact]
public void ShouldRequiresPermissionsOrPassSameDomain()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265739, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265739, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265739, "@css/ban"));

var requirePerms = new RequiresPermissionsOr("@css/ban", "@css/kick");
Assert.NotNull(requirePerms);
Assert.True(requirePerms.CanExecuteCommand((SteamID)76561197960265739));
}

[Fact]
public void ShouldRequiresPermissionsOrPassDifferentDomains()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265740, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265740, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265740, "@css/ban"));

var requirePerms = new RequiresPermissionsOr("@css/ban", "@domain2/flag");
Assert.NotNull(requirePerms);
Assert.True(requirePerms.CanExecuteCommand((SteamID)76561197960265740));
}

[Fact]
public void ShouldRequiresPermissionsCheckFail()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265735, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265735, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265735, "@css/ban"));

var requirePerms = new RequiresPermissions("@css/kick");
Assert.NotNull(requirePerms);
Assert.False(requirePerms.CanExecuteCommand((SteamID)76561197960265735));
}

[Fact]
public void ShouldRequiresPermissionsOrCheckFailSameDomain()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265736, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265736, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265736, "@css/ban"));

var requirePerms = new RequiresPermissionsOr("@css/kick", "@css/vote");
Assert.NotNull(requirePerms);
Assert.False(requirePerms.CanExecuteCommand((SteamID)76561197960265736));
}

[Fact]
public void ShouldRequiresPermissionsOrCheckFailDifferentDomains()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265737, "@css/ban"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265737, "@css/ban");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265737, "@css/ban"));

var requirePerms = new RequiresPermissionsOr("@css/kick", "@domain2/flag");
Assert.NotNull(requirePerms);
Assert.False(requirePerms.CanExecuteCommand((SteamID)76561197960265737));
}

[Fact]
public void ShouldAllowRootFlagInRequiresPermissionsOr()
{
Assert.False(AdminManager.PlayerHasPermissions((SteamID)76561197960265733, "@css/root"));
AdminManager.AddPlayerPermissions((SteamID)76561197960265733, "@css/root");
Assert.True(AdminManager.PlayerHasPermissions((SteamID)76561197960265733, "@css/root"));

var adminData = AdminManager.GetPlayerAdminData((SteamID)76561197960265733);
Assert.NotNull(adminData);
Assert.True(adminData.DomainHasRootFlag("css"));

var requirePerms = new RequiresPermissionsOr("@css/ban", "@css/kick", "@domain2/flag");
Assert.NotNull(requirePerms);
Assert.True(requirePerms.CanExecuteCommand((SteamID)76561197960265733));
}
}
Loading
Loading