Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
		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);
		}
Exemplo n.º 6
0
		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);
		}