Package org.pac4j.core.context

Examples of org.pac4j.core.context.MockWebContext


        assertEquals(CALLBACK_URL, context.getResponseLocation());
    }
   
    public void testGetCredentialsMissingHeader() {
        final BasicAuthClient basicAuthClient = getBasicAuthClient();
        final MockWebContext context = MockWebContext.create();
        try {
            basicAuthClient.getCredentials(context);
            fail("should throw RequiresHttpAction");
        } catch (final RequiresHttpAction e) {
            assertEquals(401, context.getResponseStatus());
            assertEquals("Basic realm=\"authentication required\"",
                         context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
            assertEquals("Requires basic auth (no basic auth header found)", e.getMessage());
        }
    }
View Full Code Here


        }
    }
   
    public void testGetCredentialsNotABasicHeader() {
        final BasicAuthClient basicAuthClient = getBasicAuthClient();
        final MockWebContext context = MockWebContext.create();
        try {
            basicAuthClient.getCredentials(context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "fakeHeader"));
            fail("should throw RequiresHttpAction");
        } catch (final RequiresHttpAction e) {
            assertEquals(401, context.getResponseStatus());
            assertEquals("Basic realm=\"authentication required\"",
                         context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
            assertEquals("Requires basic auth (no basic auth header found)", e.getMessage());
        }
    }
View Full Code Here

    }
   
    public void testGetCredentialsBadCredentials() {
        final BasicAuthClient basicAuthClient = getBasicAuthClient();
        final String header = USERNAME + ":" + PASSWORD;
        final MockWebContext context = MockWebContext.create();
        try {
            basicAuthClient
                .getCredentials(context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER,
                                                         "Basic " + Base64.encodeBase64String(header.getBytes())));
            fail("should throw RequiresHttpAction");
        } catch (final RequiresHttpAction e) {
            assertEquals(401, context.getResponseStatus());
            assertEquals("Basic realm=\"authentication required\"",
                         context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
            assertEquals("Requires basic auth (credentials validation fails)", e.getMessage());
        }
    }
View Full Code Here

        return new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator(), new UsernameProfileCreator());
    }
   
    public void testRedirectionUrl() throws RequiresHttpAction {
        final FormClient formClient = getFormClient();
        MockWebContext context = MockWebContext.create();
        formClient.redirect(context, false, false);
        assertEquals(LOGIN_URL, context.getResponseLocation());
    }
View Full Code Here

        assertEquals(LOGIN_URL, context.getResponseLocation());
    }
   
    public void testGetCredentialsMissingUsername() {
        final FormClient formClient = getFormClient();
        final MockWebContext context = MockWebContext.create();
        try {
            formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME));
            fail("should fail");
        } catch (final RequiresHttpAction e) {
            assertEquals("Username and password cannot be blank -> return to the form with error", e.getMessage());
            assertEquals(302, context.getResponseStatus());
            assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=" + USERNAME + "&"
                         + FormClient.ERROR_PARAMETER + "=" + FormClient.MISSING_FIELD_ERROR, context
                .getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
        }
    }
View Full Code Here

        }
    }
   
    public void testGetCredentialsMissingPassword() {
        final FormClient formClient = getFormClient();
        final MockWebContext context = MockWebContext.create();
        try {
            formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD));
            fail("should fail");
        } catch (final RequiresHttpAction e) {
            assertEquals("Username and password cannot be blank -> return to the form with error", e.getMessage());
            assertEquals(302, context.getResponseStatus());
            assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=&" + FormClient.ERROR_PARAMETER + "="
                             + FormClient.MISSING_FIELD_ERROR,
                         context.getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
        }
    }
View Full Code Here

        }
    }
   
    public void testGetCredentials() {
        final FormClient formClient = getFormClient();
        final MockWebContext context = MockWebContext.create();
        try {
            formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME)
                .addRequestParameter(formClient.getPasswordParameter(), PASSWORD));
            fail("should fail");
        } catch (final RequiresHttpAction e) {
            assertEquals("Credentials validation fails -> return to the form with error", e.getMessage());
            assertEquals(302, context.getResponseStatus());
            assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=" + USERNAME + "&"
                         + FormClient.ERROR_PARAMETER + "=" + CredentialsException.class.getSimpleName(), context
                .getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
        }
    }
View Full Code Here

        assertEquals(USERNAME, credentials.getPassword());
    }
   
    public void testGetUserProfile() {
        final FormClient formClient = getFormClient();
        final MockWebContext context = MockWebContext.create();
        final HttpProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME,
                                                                                              formClient.getName()),
                                                              context);
        assertEquals(USERNAME, profile.getId());
        assertEquals(HttpProfile.class.getSimpleName() + UserProfile.SEPARATOR + USERNAME, profile.getTypedId());
View Full Code Here

   
    public void testRenew() throws RequiresHttpAction {
        final CasClient casClient = new CasClient();
        casClient.setCallbackUrl(CALLBACK_URL);
        casClient.setCasLoginUrl(LOGIN_URL);
        MockWebContext context = MockWebContext.create();
    casClient.redirect(context, false, false);
        assertFalse(context.getResponseLocation().indexOf("renew=true") >= 0);
        casClient.setRenew(true);
        casClient.reinit();
        context = MockWebContext.create();
        casClient.redirect(context, false, false);
        assertTrue(context.getResponseLocation().indexOf("renew=true") >= 0);
    }
View Full Code Here

   
    public void testGateway() throws RequiresHttpAction {
        final CasClient casClient = new CasClient();
        casClient.setCallbackUrl(CALLBACK_URL);
        casClient.setCasLoginUrl(LOGIN_URL);
        final MockWebContext context = MockWebContext.create();
        casClient.redirect(context, false, false);
        assertFalse(context.getResponseLocation().indexOf("gateway=true") >= 0);
        casClient.setGateway(true);
        casClient.reinit();
        casClient.redirect(context, false, false);
        assertTrue(context.getResponseLocation().indexOf("gateway=true") >= 0);
        final CasCredentials credentials = casClient.getCredentials(context);
        assertNull(credentials);
    }
View Full Code Here

TOP

Related Classes of org.pac4j.core.context.MockWebContext

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.