public void Should_Return_True_If_UpgradeRequired_Is_True() { // Arrange _applicationSettings.UpgradeRequired = true; OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = new AuthorizationProviderMock(); attribute.ApplicationSettings = _applicationSettings; attribute.UserService = _userService; IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act bool isAuthorized = attribute.CallAuthorize(context); // Assert Assert.That(isAuthorized, Is.True); }
public void Should_Use_AuthorizationProvider_For_Admin_When_PublicSite_Is_False() { // Arrange User adminUser = CreateAdminUser(); OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = new AuthorizationProviderMock() { IsEditorResult = true }; attribute.ApplicationSettings = _applicationSettings; attribute.UserService = _userService; IdentityStub identity = new IdentityStub() { Name = adminUser.Id.ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act bool isAuthorized = attribute.CallAuthorize(context); // Assert Assert.That(isAuthorized, Is.True); }
public void Should_Return_True_If_Installed_Is_False() { // Arrange _applicationSettings.Installed = false; OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = new AuthorizationProviderMock(); attribute.ApplicationSettings = _applicationSettings; attribute.UserService = _userService; IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act bool isAuthorized = attribute.CallAuthorize(context); // Assert Assert.That(isAuthorized, Is.True); }
public void Should_Throw_SecurityException_When_AuthorizationProvider_Is_Null() { // Arrange OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = null; IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act + Assert attribute.CallAuthorize(context); }
public void Should_Throw_SecurityException_When_AuthorizationProvider_Is_Null() { // Arrange OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = null; IdentityStub identity = new IdentityStub() { Name = Guid.NewGuid().ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act + Assert attribute.CallAuthorize(context); }
public void Should_Use_AuthorizationProvider_For_Admin_When_PublicSite_Is_False() { // Arrange User adminUser = CreateAdminUser(); OptionalAuthorizationAttributeMock attribute = new OptionalAuthorizationAttributeMock(); attribute.AuthorizationProvider = new AuthorizationProviderMock() { IsEditorResult = true }; attribute.ApplicationSettings = _applicationSettings; attribute.UserService = _userService; IdentityStub identity = new IdentityStub() { Name = adminUser.Id.ToString(), IsAuthenticated = true }; PrincipalStub principal = new PrincipalStub() { Identity = identity }; HttpContextBase context = GetHttpContext(principal); // Act bool isAuthorized = attribute.CallAuthorize(context); // Assert Assert.That(isAuthorized, Is.True); }