本文整理汇总了C#中Potato.Core.Security.SecurityController类的典型用法代码示例。如果您正苦于以下问题:C# SecurityController类的具体用法?C# SecurityController怎么用?C# SecurityController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityController类属于Potato.Core.Security命名空间,在下文中一共展示了SecurityController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPluginEnableAlreadyEnabled
public void TestPluginEnableAlreadyEnabled() {
var security = new SecurityController();
var plugins = (CorePluginController)new CorePluginController() {
Shared = {
Security = security
}
}.Execute();
plugins.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.PluginsEnable,
Scope = {
PluginGuid = plugins.LoadedPlugins.First().PluginGuid
}
});
ICommandResult result = plugins.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.PluginsEnable,
Scope = {
PluginGuid = plugins.LoadedPlugins.First().PluginGuid
}
});
Assert.IsFalse(result.Success);
Assert.AreEqual(CommandResultType.Failed, result.CommandResultType);
}
示例2: TestCannotAuthenticateAgainstDifferentTokenId
public void TestCannotAuthenticateAgainstDifferentTokenId() {
const string identifier = "192.168.1.1";
AccessTokenModel accessToken = new AccessTokenModel() {
Account = new AccountModel() {
Username = "Phogue",
PasswordHash = "MyPasswordHash"
}
};
var token = accessToken.Generate(identifier);
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupAddAccount("GroupName", "Phogue").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityAccountSetPasswordHash("Phogue", "MyPasswordHash").SetOrigin(CommandOrigin.Local));
// Now append the token onto the account.
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", accessToken.Id, accessToken.TokenHash, accessToken.LastTouched).SetOrigin(CommandOrigin.Local));
// Now validate that we can authenticate against the newly appended token hash
ICommandResult result = security.Tunnel(CommandBuilder.SecurityAccountAuthenticateToken(Guid.NewGuid(), token, identifier).SetOrigin(CommandOrigin.Local));
Assert.IsFalse(result.Success);
Assert.AreEqual(CommandResultType.Failed, result.CommandResultType);
}
示例3: TestSecurityAddGroupDuplicateGroupName
public void TestSecurityAddGroupDuplicateGroupName() {
var security = new SecurityController();
ICommandResult result = security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAddGroup,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName"
})
});
// Test that the group was initially added.
Assert.AreEqual(security.Groups.Last().Name, "GroupName");
// Now readd the same group name.
result = security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAddGroup,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName"
})
});
// Test the second result, make sure it failed.
Assert.IsFalse(result.Success);
Assert.AreEqual(result.CommandResultType, CommandResultType.AlreadyExists);
}
示例4: TestCheckByAccountUsernameIsIdentical
public void TestCheckByAccountUsernameIsIdentical() {
var security = new SecurityController();
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAddGroup,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName"
})
});
// Now add a user.
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityGroupAddAccount,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName",
"Phogue"
})
});
// Now change the language of the account.
ICommandResult result = security.DispatchIdentityCheck(new Command() {
Authentication = {
Username = "Phogue"
}
}, "Phogue");
// Make sure it was successful.
Assert.IsTrue(result.Success);
Assert.AreEqual(result.CommandResultType, CommandResultType.Success);
}
示例5: TestGroupDoesNotExist
public void TestGroupDoesNotExist() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("ThisIsValid").SetOrigin(CommandOrigin.Local));
ICommandResult result = security.Tunnel(CommandBuilder.SecurityGroupRemovePermissionTrait("ThisIsNotValid", CommandType.VariablesSet.ToString(), PermissionTraitsType.Boolean).SetOrigin(CommandOrigin.Local));
Assert.IsFalse(result.Success);
Assert.AreEqual(CommandResultType.DoesNotExists, result.CommandResultType);
}
示例6: TestGroupDoesNotExist
public void TestGroupDoesNotExist() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("ThisIsValid").SetOrigin(CommandOrigin.Local));
ICommandResult result = security.Tunnel(CommandBuilder.SecuritySetPredefinedStreamPermissions("ThisIsNotValid").SetOrigin(CommandOrigin.Local));
Assert.IsFalse(result.Success);
Assert.AreEqual(CommandResultType.DoesNotExists, result.CommandResultType);
}
示例7: TestGuestGroupFailure
public void TestGuestGroupFailure() {
var security = new SecurityController();
ICommandResult result = security.Tunnel(CommandBuilder.SecuritySetPredefinedStreamPermissions("Guest").SetOrigin(CommandOrigin.Local));
// Make sure it was not successful.
Assert.IsFalse(result.Success);
Assert.AreEqual(CommandResultType.InvalidParameter, result.CommandResultType);
}
示例8: TestPermissionsdescriptionAppended
public void TestPermissionsdescriptionAppended() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupSetPermissionDescription("GroupName", CommandType.VariablesSet.ToString(), "Description!").SetOrigin(CommandOrigin.Local));
var group = security.Groups.First(item => item.Name == "GroupName");
Assert.AreEqual("Description!", group.Permissions.First(permission => permission.CommandType == CommandType.VariablesSet).Description);
}
示例9: TestEmptyUid
public void TestEmptyUid() {
var security = new SecurityController();
// Remove a player, though no accounts/players/groups exist.
ICommandResult result = security.Tunnel(CommandBuilder.SecurityRemovePlayer(CommonProtocolType.DiceBattlefield3, String.Empty).SetOrigin(CommandOrigin.Local));
// Validate the command failed and returned the correct error status.
Assert.IsFalse(result.Success);
Assert.AreEqual(result.CommandResultType, CommandResultType.InvalidParameter);
Assert.IsNull(security.Groups.SelectMany(group => group.Accounts).SelectMany(account => account.Players).FirstOrDefault());
}
示例10: TestEmptyUsername
public void TestEmptyUsername() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
// Now add the user.
ICommandResult result = security.Tunnel(CommandBuilder.SecurityGroupAddAccount("GroupName", String.Empty).SetOrigin(CommandOrigin.Local));
// Make sure the account was successfully created.
Assert.IsFalse(result.Success);
Assert.AreEqual(result.CommandResultType, CommandResultType.InvalidParameter);
}
示例11: TestSuccess
public void TestSuccess() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
ICommandResult result = security.Tunnel(CommandBuilder.SecuritySetPredefinedStreamPermissions("GroupName").SetOrigin(CommandOrigin.Local));
// Make sure it was not successful.
Assert.IsTrue(result.Success);
Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
}
示例12: TestTwoExpiredTwoRemoved
public void TestTwoExpiredTwoRemoved() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupAddAccount("GroupName", "Phogue").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.NewGuid(), "Token Hash One", DateTime.Now.AddDays(-3)).SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.NewGuid(), "Token Hash Two", DateTime.Now.AddDays(-3)).SetOrigin(CommandOrigin.Local));
security.Poke();
Assert.IsEmpty(security.Groups.First(group => group.Name == "GroupName").Accounts.First().AccessTokens);
}
示例13: TestRemoveAccountByLocalSuccess
public void TestRemoveAccountByLocalSuccess() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupAddAccount("GroupName", "Phogue").SetOrigin(CommandOrigin.Local));
ICommandResult result = security.Tunnel(CommandBuilder.SecurityRemoveAccount("Phogue").SetOrigin(CommandOrigin.Local));
// Make sure the command failed. The user cannot remove their own account.
Assert.IsTrue(result.Success);
Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
}
示例14: TestPermissionsTraitAppended
public void TestPermissionsTraitAppended() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupAppendPermissionTrait("GroupName", CommandType.VariablesSet.ToString(), PermissionTraitsType.Boolean).SetOrigin(CommandOrigin.Local));
var group = security.Groups.First(item => item.Name == "GroupName");
Assert.AreEqual(new List<String>() { PermissionTraitsType.Boolean }, group.Permissions.First(permission => permission.CommandType == CommandType.VariablesSet).Traits);
}
示例15: TestNoneExpiredNoneRemoved
public void TestNoneExpiredNoneRemoved() {
var security = new SecurityController();
security.Tunnel(CommandBuilder.SecurityAddGroup("GroupName").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityGroupAddAccount("GroupName", "Phogue").SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.NewGuid(), "Token Hash One", DateTime.Now).SetOrigin(CommandOrigin.Local));
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.NewGuid(), "Token Hash Two", DateTime.Now).SetOrigin(CommandOrigin.Local));
security.Poke();
Assert.AreEqual(2, security.Groups.First(group => group.Name == "GroupName").Accounts.First().AccessTokens.Count);
}