use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IndirectBasicAuthClientTests method testRedirectionUrl.
@Test
public void testRedirectionUrl() {
final var basicAuthClient = getBasicAuthClient();
var context = MockWebContext.create();
final var action = (FoundAction) basicAuthClient.getRedirectionAction(context, new MockSessionStore()).get();
assertEquals(CALLBACK_URL + "?" + Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER + "=" + basicAuthClient.getName(), action.getLocation());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class RestAuthenticatorIT method testProfileOk.
@Test
public void testProfileOk() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=ok");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNotNull(profile);
assertEquals(ID, profile.getId());
assertEquals(1, profile.getRoles().size());
assertEquals(ROLE, profile.getRoles().iterator().next());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class RestAuthenticatorIT method testHttps.
@Test
public void testHttps() {
final var authenticator = new RestAuthenticator("https://www.google.com");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class RestAuthenticatorIT method testNotFound.
@Test
public void testNotFound() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=notfound");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNull(profile);
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IpExtractorTests method testRetrieveIpFromHeaderWithProxyIpCheck.
@Test
public void testRetrieveIpFromHeaderWithProxyIpCheck() {
final var context = MockWebContext.create().addRequestHeader(HEADER_NAME, GOOD_IP).setRemoteAddress(LOCALHOST);
final var ipExtractor = new IpExtractor();
ipExtractor.setProxyIp(LOCALHOST);
// test for varargs
ipExtractor.setAlternateIpHeaders("fooBar", HEADER_NAME, "barFoo");
final var credentials = (TokenCredentials) ipExtractor.extract(context, new MockSessionStore()).get();
assertEquals(GOOD_IP, credentials.getToken());
// test for edge case of 1 header
ipExtractor.setAlternateIpHeaders(HEADER_NAME);
final var credentials2 = (TokenCredentials) ipExtractor.extract(context, new MockSessionStore()).get();
assertEquals(GOOD_IP, credentials2.getToken());
}
Aggregations