use of org.sdase.commons.server.auth.service.testsources.JwksTestKeySource in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndNoIssuerButConfiguredRequiredIssuer.
@Test
void validTokenWithKeyIdAndNoIssuerButConfiguredRequiredIssuer() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, null, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), null, KEY_ID));
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER)).isNull();
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
use of org.sdase.commons.server.auth.service.testsources.JwksTestKeySource in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndIssuerAndAndFutureNotBeforeFailed.
@Test
void validTokenWithKeyIdAndIssuerAndAndFutureNotBeforeFailed() throws InterruptedException {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 2, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), ISSUER, KEY_ID));
assertThatThrownBy(() -> this.service.auth(token)).isInstanceOf(JwtAuthException.class);
TimeUnit.SECONDS.sleep(2);
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER).asString()).isEqualTo(ISSUER);
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
use of org.sdase.commons.server.auth.service.testsources.JwksTestKeySource in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndNoIssuerAndRequiredIssuerButJwks.
@Test
void validTokenWithKeyIdAndNoIssuerAndRequiredIssuerButJwks() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(null, keyPair.getRight(), ISSUER, KEY_ID));
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER).asString()).isEqualTo(ISSUER);
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
use of org.sdase.commons.server.auth.service.testsources.JwksTestKeySource in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndCorrectIssuerAndWrongConfiguredRequiredIssuer.
@Test
void validTokenWithKeyIdAndCorrectIssuerAndWrongConfiguredRequiredIssuer() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), "https://www.google.de", KEY_ID));
assertThatThrownBy(() -> this.service.auth(token)).isInstanceOf(JwtAuthException.class);
}
use of org.sdase.commons.server.auth.service.testsources.JwksTestKeySource in project sda-dropwizard-commons by SDA-SE.
the class AuthRSA256ServiceTest method validTokenWithKeyIdAndIssuerAndConfiguredRequiredIssuer.
@Test
void validTokenWithKeyIdAndIssuerAndConfiguredRequiredIssuer() {
final Pair<RSAPrivateKey, RSAPublicKey> keyPair = createKeyPair(RSA_PRIVATE_KEY);
String token = createToken(keyPair, ISSUER, KEY_ID, 0, 30);
keyLoader.addKeySource(new JwksTestKeySource(ISSUER, keyPair.getRight(), ISSUER, KEY_ID));
final Map<String, Claim> claims = this.service.auth(token);
assertThat(claims.get(CLAIM_ISSUER).asString()).isEqualTo(ISSUER);
assertThat(claims.get(CLAIM_NOT_BEFORE).asLong() * 1000L).isLessThan(new Date().getTime());
assertThat(claims.get(CLAIM_EXPIRE).asLong() * 1000L).isGreaterThan(new Date().getTime());
}
Aggregations