public void Setup() { this.Valid = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = "Password Hash" } }; }
public void TestNullTokenReturnedWhenAccountEmpty() { AccessTokenModel accessToken = new AccessTokenModel(); var token = accessToken.Generate(TestGenerate.Identifer); Assert.IsNull(token); }
public void TestCannotAuthenticateAgainstDifferentTokenId() { const string identifier = "192.168.1.1"; AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { Username = "******", 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); }
public void TestNullTokenReturnedWhenIdentiferEmpty() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = "password" } }; var token = accessToken.Generate(""); Assert.IsNull(token); }
public void TestNullTokenReturnedWhenAccountHashNull() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = null } }; var token = accessToken.Generate(TestGenerate.Identifer); Assert.IsNull(token); }
public void TestAllValuesDefaulted() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel(), TokenHash = "Something", LastTouched = DateTime.Now, Id = Guid.NewGuid() }; accessToken.Dispose(); Assert.IsNull(accessToken.Account); Assert.IsNull(accessToken.TokenHash); Assert.AreEqual(Guid.Empty, accessToken.Id); }
/// <summary> /// Helper for creating an access token. /// </summary> /// <param name="account">The account to create the access token for</param> /// <param name="identifier">The identifying peice of information to mixin with the token</param> /// <returns>An access token for transport, or null if the user can't have tokens or something went wrong while making the token.</returns> protected AccessTokenTransportModel GenerateAccessToken(AccountModel account, String identifier) { AccessTokenTransportModel accessTokenTransport = null; var accessToken = new AccessTokenModel() { Account = account, ExpiredWindowSeconds = this.Shared.Variables.Get(CommonVariableNames.SecurityMaximumAccessTokenLastTouchedLengthSeconds, 172800) }; var token = accessToken.Generate(identifier); if (String.IsNullOrEmpty(token) == false) { // Save the token hash for future authentication. this.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken(account.Username, accessToken.Id, accessToken.TokenHash, accessToken.LastTouched).SetOrigin(CommandOrigin.Local)); accessTokenTransport = new AccessTokenTransportModel() { Id = accessToken.Id, Token = token }; } return accessTokenTransport; }
public void TestGoodTokenReturnedWhenAllCredentialsPassed() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = "password" } }; var token = accessToken.Generate("192.168.1.1"); Assert.IsNotNull(token); }
public void TestLastTouchedResetToCurrentDateTime() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = "password" }, LastTouched = DateTime.Now.AddDays(-1) }; var token = accessToken.Generate("192.168.1.1"); Assert.IsNotNull(token); Assert.GreaterOrEqual(accessToken.LastTouched, DateTime.Now.AddMinutes(-1)); }
public void TestReturnedTokenIsRandom() { AccessTokenModel accessToken = new AccessTokenModel() { Account = new AccountModel() { PasswordHash = "password" } }; var tokenA = accessToken.Generate("192.168.1.1"); var tokenB = accessToken.Generate("192.168.1.1"); Assert.IsNotNull(tokenA); Assert.IsNotNull(tokenB); Assert.AreNotEqual(tokenA, tokenB); }