public async Task GetProfileDataAsync_NoProfileNameSpecified_ClaimsMapForUserGenerated() { // Assert var identityWithAdditionalClaimsProfileService = new IdentityWithAdditionalClaimsProfileService(fakeUserManager, mockUserClaimsPrincipalFactory, mockLogger, mockProfileRepository, mockApplicationDataPolicyRepository, mockPermissionRepository, mockTeamRepository); fakeUserManager.SetUserModel(userModel); mockUserClaimsPrincipalFactory.CreateAsync(userModel).Returns(profileDataRequestContext.Subject); mockPermissionRepository.GetListAsync(Arg.Any <Guid>()).Returns(new List <PermissionModel>() { new PermissionModel() { Name = "Permission 1" }, new PermissionModel() { Name = "Permission 2" } }); mockApplicationDataPolicyRepository.GetListAsync(Arg.Any <Guid>()).Returns(new List <ApplicationDataPolicyModel>() { new ApplicationDataPolicyModel() { Name = "DP 1" } }); mockTeamRepository.GetListAsync(Arg.Any <Guid>()).Returns(new List <TeamModel>() { new TeamModel() { Name = "Name 1" }, new TeamModel() { Name = "Name 2" } }); // Act await identityWithAdditionalClaimsProfileService.GetProfileDataAsync(profileDataRequestContext); // Assert Assert.True(profileDataRequestContext.IssuedClaims.Count > 0, "Issued claims must be greater than 0."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == "permission" && x.Value == "Permission 1"), "Permission 1 claim must be present and correct."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == "permission" && x.Value == "Permission 2"), "Permission 2 claim must be present and correct."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == IdentityServerConstants.StandardScopes.Email && x.Value == userModel.Email), "Email claim must be present and correct."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == "username" && x.Value == userModel.UserName), "Username claim must be present and correct."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == "given_name" && x.Value == userModel.FirstName), "Given Name claim must be present and correct."); Assert.True(profileDataRequestContext.IssuedClaims.Exists(x => x.Type == "family_name" && x.Value == userModel.Surname), "Family Name claim must be present and correct."); }
public async Task Login_GivenLoginInputModelAndLoginButton2FACompulsary_RedirectToActionResultReturned() { using var accountController = new AccountController(fakeUserManager, fakeSignInManager, mockIdentityServerInteractionService, mockClientStore, mockAuthenticationSchemeProvider, mockEventService, urlTestEncoder, mockConfiguration); mockIdentityServerInteractionService.GetAuthorizationContextAsync(Arg.Any <string>()).Returns(authorizationRequest); var inputModel = new LoginInputModel() { Username = "******", Password = "******", RememberLogin = false, ReturnUrl = RETURN_URL }; fakeSignInManager.SetSignInSuccessful(true); fakeUserManager.SetUserModel(userModel); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables(); var config = builder.Build(); config.GetSection("TwoFactorAuthentication")["OrganizationEnforced"] = "true"; config.GetSection("TwoFactorAuthentication")["AuthenticatorEnabled"] = "false"; mockConfiguration.GetSection("TwoFactorAuthentication").Returns(config.GetSection("TwoFactorAuthentication")); // Act var actionResult = await accountController.Login(inputModel, "login"); // Assert var viewResult = actionResult as RedirectToActionResult; Assert.NotNull(viewResult); Assert.True(viewResult.ActionName == "Register2FA", "Action Name must be 'Register2FA'."); }
public async Task Index_ExecutedWithOutstandingAgreements_ViewResultReturned() { //Arrange var id = Guid.NewGuid().ToString(); using var termsOfServiceController = new TermsOfServiceController(fakeUserManager, termsOfServiceRepository, mockConfiguration, mockIdentityServerInteractionService, mockEventService, mockClientStore, fakeSignInManager) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "example name"), new Claim(ClaimTypes.NameIdentifier, id), new Claim("sub", id), new Claim("custom-claim", "example claim value"), }, "mock")), } } }; fakeUserManager.SetUserModel(userModel); termsOfServiceRepository.GetAllOutstandingAgreementsByUserAsync(Arg.Any <Guid>()) .Returns(new List <Guid>() { Guid.NewGuid(), Guid.NewGuid() }); termsOfServiceRepository.GetByIdAsync(Arg.Any <Guid>(), Arg.Any <bool>(), Arg.Any <bool>()).Returns(termsOfServiceModel); // Act var actionResult = await termsOfServiceController.Index(RETURN_URL, 0); // Assert var viewResult = actionResult as ViewResult; Assert.NotNull(viewResult); var model = viewResult.Model as TermsOfServiceViewModel; Assert.True(model.AgreementName == termsOfServiceModel.AgreementName, $"Model field AgreementName '{model.AgreementName}' should be '{termsOfServiceModel.AgreementName}'."); Assert.True(model.AgreementCount == 2, $"Model field AgreementCount '{model.AgreementCount}' should be '2'."); }