protected void Application_AuthenticateRequest() { var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { var authTicket = FormsAuthentication.Decrypt(authCookie.Value); var genericIdentity = new GenericIdentity(authTicket.Name, "Custom"); var roles = new[] { authTicket.UserData }; var genericPrincipal = new GenericPrincipal(genericIdentity, roles); Context.User = genericPrincipal; } }
public void IPricincipal_IsInAnyRoleOrUserList_Should_Return_True_For_Matching_Username_And_Role() { var actualUsersRoles = new[] { "username", "Role1" }; var expectedResult = _user.Object.IsInAnyRoleOrUserList(actualUsersRoles); Assert.IsTrue(expectedResult); }
public void IPricincipal_IsInUserList_Should_Return_False_For_No_Matching_Username() { var actualUsernames = new[] { "username1", "username2" }; var expectedResult = _user.Object.IsInUserList(actualUsernames); Assert.IsFalse(expectedResult); }
public void IPricincipal_IsInAnyRoles_Should_Return_False_For_No_Matching_Role() { var actualRoles = new[] { "Role2", "Role2" }; var expectedResult = _user.Object.IsInAnyRole(actualRoles); Assert.IsFalse(expectedResult); }