public void AuthenticateWithEmptyToken() { //-- Arrange var userName = "******"; var password = "******"; var roles = new string[] { "Tester" }; var token = string.Empty; var externalAuthorization = new ExternalAuthenticator() { Token = token }; authService.ExternalAuthorization = externalAuthorization; authService.UserRepository.Create(userName, new UserData(userName, password, roles.ToList())); authService.AuthenticateUser(userName, password); authService.ExternalAuthorization.RequestTokenChange(); authService.DeAuthenticateCurrentUser(); externalAuthorization.Token = string.Empty; authService.ExternalAuthorization.RequestAuthorization(); AppPrincipal customPrincipal = Thread.CurrentPrincipal as AppPrincipal; Assert.AreEqual(string.Empty, customPrincipal.Identity.Name); Assert.AreEqual(0, customPrincipal.Identity.Roles.Length); Assert.AreEqual(string.Empty, customPrincipal.Identity.Level); }
public void AddExistingToken() { var token = "sameToken"; var externalAuthorization = new ExternalAuthenticator() { Token = token }; authService.ExternalAuthorization = externalAuthorization; authService.UserRepository.Create("ExistingToken1", new UserData("ExistingToken1", "halabala", new string[] { "Tester" })); authService.UserRepository.Create("ExistingToken2", new UserData("ExistingToken2", "halabala", new string[] { "Tester" })); authService.AuthenticateUser("ExistingToken1", "halabala"); authService.ExternalAuthorization.RequestTokenChange(); authService.DeAuthenticateCurrentUser(); authService.AuthenticateUser("ExistingToken2", "halabala"); Assert.Throws(typeof(ExistingTokenException), () => authService.ExternalAuthorization.RequestTokenChange()); }