/// <exception cref="System.Exception"/>
        public virtual void TestRequestWithAuthorization()
        {
            string              token    = KerberosTestUtils.DoAsClient(new _Callable_225());
            HttpServletRequest  request  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            Org.Mockito.Mockito.When(request.GetHeader(KerberosAuthenticator.Authorization)).
            ThenReturn(KerberosAuthenticator.Negotiate + " " + token);
            Org.Mockito.Mockito.When(request.GetServerName()).ThenReturn("localhost");
            AuthenticationToken authToken = handler.Authenticate(request, response);

            if (authToken != null)
            {
                Org.Mockito.Mockito.Verify(response).SetHeader(Org.Mockito.Mockito.Eq(KerberosAuthenticator
                                                                                      .WwwAuthenticate), Org.Mockito.Mockito.Matches(KerberosAuthenticator.Negotiate +
                                                                                                                                     " .*"));
                Org.Mockito.Mockito.Verify(response).SetStatus(HttpServletResponse.ScOk);
                Assert.Equal(KerberosTestUtils.GetClientPrincipal(), authToken
                             .GetName());
                Assert.True(KerberosTestUtils.GetClientPrincipal().StartsWith(authToken
                                                                              .GetUserName()));
                Assert.Equal(GetExpectedType(), authToken.GetType());
            }
            else
            {
                Org.Mockito.Mockito.Verify(response).SetHeader(Org.Mockito.Mockito.Eq(KerberosAuthenticator
                                                                                      .WwwAuthenticate), Org.Mockito.Mockito.Matches(KerberosAuthenticator.Negotiate +
                                                                                                                                     " .*"));
                Org.Mockito.Mockito.Verify(response).SetStatus(HttpServletResponse.ScUnauthorized
                                                               );
            }
        }
예제 #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestNonDefaultNonBrowserUserAgentAsBrowser()
        {
            HttpServletRequest  request  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            if (handler != null)
            {
                handler.Destroy();
                handler = null;
            }
            handler = GetNewAuthenticationHandler();
            Properties props = GetDefaultProperties();

            props.SetProperty("alt-kerberos.non-browser.user-agents", "foo, bar");
            try
            {
                handler.Init(props);
            }
            catch (Exception ex)
            {
                handler = null;
                throw;
            }
            // Pretend we're something that will not match with "foo" (or "bar")
            Org.Mockito.Mockito.When(request.GetHeader("User-Agent")).ThenReturn("blah");
            // Should use alt authentication
            AuthenticationToken token = handler.Authenticate(request, response);

            Assert.Equal("A", token.GetUserName());
            Assert.Equal("B", token.GetName());
            Assert.Equal(GetExpectedType(), token.GetType());
        }
예제 #3
0
        /// <exception cref="System.Exception"/>
        private void _testUserName(bool anonymous)
        {
            PseudoAuthenticationHandler handler = new PseudoAuthenticationHandler();

            try
            {
                Properties props = new Properties();
                props.SetProperty(PseudoAuthenticationHandler.AnonymousAllowed, bool.ToString(anonymous
                                                                                              ));
                handler.Init(props);
                HttpServletRequest  request  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
                HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
                Org.Mockito.Mockito.When(request.GetQueryString()).ThenReturn(PseudoAuthenticator
                                                                              .UserName + "=" + "user");
                AuthenticationToken token = handler.Authenticate(request, response);
                NUnit.Framework.Assert.IsNotNull(token);
                Assert.Equal("user", token.GetUserName());
                Assert.Equal("user", token.GetName());
                Assert.Equal(PseudoAuthenticationHandler.Type, token.GetType()
                             );
            }
            finally
            {
                handler.Destroy();
            }
        }
예제 #4
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAlternateAuthenticationAsBrowser()
        {
            HttpServletRequest  request  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            // By default, a User-Agent without "java", "curl", "wget", or "perl" in it
            // is considered a browser
            Org.Mockito.Mockito.When(request.GetHeader("User-Agent")).ThenReturn("Some Browser"
                                                                                 );
            AuthenticationToken token = handler.Authenticate(request, response);

            Assert.Equal("A", token.GetUserName());
            Assert.Equal("B", token.GetName());
            Assert.Equal(GetExpectedType(), token.GetType());
        }