Package waffle.mock.http

Examples of waffle.mock.http.SimpleHttpRequest


        assertTrue(header.isNtlmType1Message());
    }

    @Test
    public void testIsNtlmType1PostAuthorizationHeader() {
        SimpleHttpRequest request = new SimpleHttpRequest();
        request.setContentLength(0);
        request.addHeader("Authorization", "NTLM TlRMTVNTUAABAAAABzIAAAYABgArAAAACwALACAAAABXT1JLU1RBVElPTkRPTUFJTg==");
        // GET
        request.setMethod("GET");
        AuthorizationHeader header = new AuthorizationHeader(request);
        assertFalse(header.isNtlmType1PostAuthorizationHeader());
        // POST
        request.setMethod("POST");
        assertTrue(header.isNtlmType1PostAuthorizationHeader());
        // PUT
        request.setMethod("PUT");
        assertTrue(header.isNtlmType1PostAuthorizationHeader());
    }
View Full Code Here


        assertTrue(header.isNtlmType1PostAuthorizationHeader());
    }

    @Test
    public void testIsSPNegoMessage() {
        SimpleHttpRequest request = new SimpleHttpRequest();
        AuthorizationHeader header = new AuthorizationHeader(request);
        assertFalse(header.isSPNegoMessage());
        request.addHeader("Authorization", "");
        assertFalse(header.isSPNegoMessage());
        request.addHeader(
                "Authorization",
                "Negotiate YHYGBisGAQUFAqBsMGqgMDAuBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHqI2BDROVExNU1NQAAEAAACXsgjiAwADADEAAAAJAAkAKAAAAAYBsR0AAAAPR0xZQ0VSSU5FU0FE");
        assertTrue(header.isSPNegoMessage());
    }
View Full Code Here

        assertTrue(header.isSPNegoMessage());
    }

    @Test
    public void testIsSPNegoPostAuthorizationHeader() {
        SimpleHttpRequest request = new SimpleHttpRequest();
        request.setContentLength(0);
        request.addHeader(
                "Authorization",
                "Negotiate YHYGBisGAQUFAqBsMGqgMDAuBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHqI2BDROVExNU1NQAAEAAACXsgjiAwADADEAAAAJAAkAKAAAAAYBsR0AAAAPR0xZQ0VSSU5FU0FE");
        // GET
        request.setMethod("GET");
        AuthorizationHeader header = new AuthorizationHeader(request);
        assertFalse(header.isNtlmType1PostAuthorizationHeader());
        // POST
        request.setMethod("POST");
        assertTrue(header.isNtlmType1PostAuthorizationHeader());
        // PUT
        request.setMethod("PUT");
        assertTrue(header.isNtlmType1PostAuthorizationHeader());
    }
View Full Code Here

public class NtlmServletRequestTests {

    @Test
    public void testGetConnectionId() {
        SimpleHttpRequest.resetRemotePort();
        SimpleHttpRequest request1 = new SimpleHttpRequest();
        assertEquals(":1", NtlmServletRequest.getConnectionId(request1));
        SimpleHttpRequest request2 = new SimpleHttpRequest();
        assertEquals(":2", NtlmServletRequest.getConnectionId(request2));
        request2.setRemoteAddr("192.168.1.1");
        assertEquals("192.168.1.1:2", NtlmServletRequest.getConnectionId(request2));
        request2.setRemoteHost("codeplex.com");
        assertEquals("codeplex.com:2", NtlmServletRequest.getConnectionId(request2));
    }
View Full Code Here

        assertTrue(provider.getByClassName("waffle.servlet.spi.NegotiateSecurityFilterProvider") instanceof NegotiateSecurityFilterProvider);
    }

    @Test
    public void testNoChallengeGET() throws IOException, ServletException {
        final SimpleHttpRequest request = new SimpleHttpRequest();
        request.setMethod("GET");
        final SimpleHttpResponse response = new SimpleHttpResponse();
        final SimpleFilterChain chain = new SimpleFilterChain();
        this.filter.doFilter(request, response, chain);
        // unlike servlet filters, it's a passthrough
        assertEquals(500, response.getStatus());
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testNegotiate() throws IOException, ServletException {
        final String securityPackage = "Negotiate";
        final SimpleFilterChain filterChain = new SimpleFilterChain();
        final SimpleHttpRequest request = new SimpleHttpRequest();

        final String clientToken = BaseEncoding.base64().encode(
                WindowsAccountImpl.getCurrentUsername().getBytes(Charsets.UTF_8));
        request.addHeader("Authorization", securityPackage + " " + clientToken);

        final SimpleHttpResponse response = new SimpleHttpResponse();
        this.filter.doFilter(request, response, filterChain);

        final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
View Full Code Here

    }

    @Test
    public void testUnsupportedSecurityPackagePassthrough() throws IOException, ServletException {
        final SimpleFilterChain filterChain = new SimpleFilterChain();
        final SimpleHttpRequest request = new SimpleHttpRequest();
        request.addHeader("Authorization", "Unsupported challenge");
        final SimpleHttpResponse response = new SimpleHttpResponse();
        this.filter.doFilter(request, response, filterChain);
        // the filter should ignore authorization for an unsupported security package, ie. not return a 401
        assertEquals(500, response.getStatus());
    }
View Full Code Here

    @Test
    public void testGuestIsDisabled() throws IOException, ServletException {
        final String securityPackage = "Negotiate";
        final SimpleFilterChain filterChain = new SimpleFilterChain();
        final SimpleHttpRequest request = new SimpleHttpRequest();

        final String clientToken = BaseEncoding.base64().encode("Guest".getBytes(Charsets.UTF_8));
        request.addHeader("Authorization", securityPackage + " " + clientToken);

        final SimpleHttpResponse response = new SimpleHttpResponse();
        this.filter.doFilter(request, response, filterChain);

        assertEquals(401, response.getStatus());
View Full Code Here

    public void testImpersonateEnabled() throws IOException, ServletException {

        assertFalse("Current user shouldn't be the test user prior to the test",
                Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME));

        final SimpleHttpRequest request = new SimpleHttpRequest();
        request.setMethod("GET");
        final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
        final String basicAuthHeader = "Basic "
                + BaseEncoding.base64().encode(userHeaderValue.getBytes(Charsets.UTF_8));
        request.addHeader("Authorization", basicAuthHeader);

        final SimpleHttpResponse response = new SimpleHttpResponse();
        final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain();

        AutoDisposableWindowsPrincipal windowsPrincipal = null;
        try {
            this.filter.setImpersonate(true);
            this.filter.doFilter(request, response, filterChain);

            final Subject subject = (Subject) request.getSession().getAttribute("javax.security.auth.subject");
            final boolean authenticated = (subject != null && subject.getPrincipals().size() > 0);
            assertTrue("Test user should be authenticated", authenticated);

            if (subject == null) {
                return;
View Full Code Here

    @Test
    public void testImpersonateDisabled() throws IOException, ServletException {

        assertFalse("Current user shouldn't be the test user prior to the test",
                Advapi32Util.getUserName().equals(MockWindowsAccount.TEST_USER_NAME));
        final SimpleHttpRequest request = new SimpleHttpRequest();
        request.setMethod("GET");
        final String userHeaderValue = MockWindowsAccount.TEST_USER_NAME + ":" + MockWindowsAccount.TEST_PASSWORD;
        final String basicAuthHeader = "Basic "
                + BaseEncoding.base64().encode(userHeaderValue.getBytes(Charsets.UTF_8));
        request.addHeader("Authorization", basicAuthHeader);
        final SimpleHttpResponse response = new SimpleHttpResponse();
        final RecordUserNameFilterChain filterChain = new RecordUserNameFilterChain();

        WindowsPrincipal windowsPrincipal = null;
        try {
            this.filter.setImpersonate(false);
            this.filter.doFilter(request, response, filterChain);

            final Subject subject = (Subject) request.getSession().getAttribute("javax.security.auth.subject");
            final boolean authenticated = (subject != null && subject.getPrincipals().size() > 0);
            assertTrue("Test user should be authenticated", authenticated);

            if (subject == null) {
                return;
View Full Code Here

TOP

Related Classes of waffle.mock.http.SimpleHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.