use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultCasAuthorizationGeneratorTests method testNoAttribute.
@Test
public void testNoAttribute() {
final AuthorizationGenerator generator = new DefaultCasAuthorizationGenerator();
final Map<String, Object> attributes = new HashMap<>();
final var profile = new CasProfile();
profile.build(ID, attributes);
generator.generate(null, new MockSessionStore(), profile);
assertEquals(false, profile.isRemembered());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CasProxyReceptorTests method testMissingPgt.
@Test
public void testMissingPgt() {
final var client = new CasProxyReceptor();
client.setCallbackUrl(CALLBACK_URL);
final var context = MockWebContext.create();
final var action = (HttpAction) TestsHelper.expectException(() -> client.getCredentials(context.addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET, VALUE), new MockSessionStore()));
assertEquals(200, action.getCode());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectCasProxyClientTests method testNoTicket.
@Test
public void testNoTicket() {
final var configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
configuration.setProtocol(CasProtocol.CAS20_PROXY);
final var client = new DirectCasProxyClient(configuration, CALLBACK_URL);
assertFalse(client.getCredentials(MockWebContext.create(), new MockSessionStore()).isPresent());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class X509ClientTests method testOk.
@Test
public void testOk() throws CertificateException {
final var context = MockWebContext.create();
final var certificateData = Base64.getDecoder().decode(CERTIFICATE);
final var cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(certificateData));
final var certs = new X509Certificate[1];
certs[0] = cert;
context.setRequestAttribute(X509CredentialsExtractor.CERTIFICATE_REQUEST_ATTRIBUTE, certs);
final var credentials = (X509Credentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (X509Profile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals("jerome", profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IndirectBasicAuthClientTests method verifyGetCredentialsFailsWithAuthenticationRequired.
private void verifyGetCredentialsFailsWithAuthenticationRequired(IndirectBasicAuthClient basicAuthClient, MockWebContext context) {
try {
basicAuthClient.getCredentials(context, new MockSessionStore());
fail("should throw HttpAction");
} catch (final HttpAction e) {
assertEquals(401, e.getCode());
assertEquals("Basic realm=\"authentication required\"", context.getResponseHeaders().get(HttpConstants.AUTHENTICATE_HEADER));
}
}
Aggregations