Package org.pac4j.core.context

Examples of org.pac4j.core.context.MockWebContext


    public void testGetCredentialError() throws RequiresHttpAction {
        final BaseOAuthClient client = new GitHubClient();
        client.setKey(KEY);
        client.setSecret(SECRET);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create().addRequestParameter(BaseOAuth20Client.OAUTH_CODE,
                                                                                   FAKE_VALUE);
        for (final String key : OAuthCredentialsException.ERROR_NAMES) {
            context.addRequestParameter(key, FAKE_VALUE);
        }
        try {
            client.getCredentials(context);
            fail("should not get credentials");
        } catch (final TechnicalException e) {
View Full Code Here


    }

    public void testDirectClient() throws RequiresHttpAction {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        client.redirect(context, false, false);
        final String redirectionUrl = context.getResponseLocation();
        assertEquals(LOGIN_URL, redirectionUrl);
        final Credentials credentials = client.getCredentials(context);
        assertNull(credentials);
    }
View Full Code Here

    }

    public void testIndirectClient() throws RequiresHttpAction {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        client.redirect(context, false, false);
        final String redirectionUrl = context.getResponseLocation();
        assertEquals(CommonHelper.addParameter(CALLBACK_URL, BaseClient.NEEDS_CLIENT_REDIRECTION_PARAMETER, "true"),
                redirectionUrl);
        context.addRequestParameter(BaseClient.NEEDS_CLIENT_REDIRECTION_PARAMETER, "true");
        try {
            client.getCredentials(context);
            fail("should throw RequiresHttpAction");
        } catch (final RequiresHttpAction e) {
            assertEquals(302, context.getResponseStatus());
            assertEquals(LOGIN_URL, context.getResponseHeaders().get("Location"));
            assertEquals("Needs client redirection", e.getMessage());
        }
    }
View Full Code Here

    }

    public void testIndirectClientWithImmediate() throws RequiresHttpAction {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        client.redirect(context, true, false);
        final String redirectionUrl = context.getResponseLocation();
        assertEquals(LOGIN_URL, redirectionUrl);
    }
View Full Code Here

        assertEquals(LOGIN_URL, redirectionUrl);
    }

    public void testNullCredentials() throws RequiresHttpAction {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        final MockWebContext context = MockWebContext.create();
        client.setCallbackUrl(CALLBACK_URL);
        assertNull(client.getUserProfile(null, context));
    }
View Full Code Here

    public void testPrependHostToUrlIfNotPresent_whenHostIsNotPresent() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setEnableContextualRedirects(true);

        final MockWebContext context = MockWebContext.create();
        context.setServerName("pac4j.com");

        String result = client.prependHostToUrlIfNotPresent("/cas/login", context);

        assertEquals("http://pac4j.com/cas/login", result);
    }
View Full Code Here

    public void testPrependHostToUrlIfNotPresent_whenHostIsPresent() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setEnableContextualRedirects(true);

        final MockWebContext context = MockWebContext.create();
        context.setServerName("pac4j.com");

        String result = client.prependHostToUrlIfNotPresent("http://cashost.com/cas/login", context);

        assertEquals("http://cashost.com/cas/login", result);
    }
View Full Code Here

    public void testPrependHostToUrlIfNotPresent_whenServerIsNotUsingDefaultHttpPort() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setEnableContextualRedirects(true);

        final MockWebContext context = MockWebContext.create();
        context.setServerName("pac4j.com");
        context.setServerPort(8080);

        String result = client.prependHostToUrlIfNotPresent("/cas/login", context);

        assertEquals("http://pac4j.com:8080/cas/login", result);
    }
View Full Code Here

    public void testPrependHostToUrlIfNotPresent_whenRequestIsSecure() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setEnableContextualRedirects(true);

        final MockWebContext context = MockWebContext.create();
        context.setScheme("https");

        String result = client.prependHostToUrlIfNotPresent("/cas/login", context);

        assertEquals("https://localhost/cas/login", result);
    }
View Full Code Here

    public void testPrependHostToUrlIfNotPresent_whenContextualRedirectsAreDisabled() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE, false);
        client.setEnableContextualRedirects(false);

        final MockWebContext context = MockWebContext.create();

        String result = client.prependHostToUrlIfNotPresent("/cas/login", context);

        assertEquals("/cas/login", result);
    }
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.