Search in sources :

Example 6 with FleetEngineToken

use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.

the class FleetEngineTokenFactoryTest method createTrustedDriverToken_whenVehicleClaimsAndTaskClaimsSet_claimValuesCorrect.

@Test
public void createTrustedDriverToken_whenVehicleClaimsAndTaskClaimsSet_claimValuesCorrect() {
    FleetEngineTokenFactorySettings settings = FleetEngineTokenFactorySettings.builder().setAudience(FAKE_AUDIENCE).build();
    FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, settings);
    FleetEngineToken token = factory.createTrustedDeliveryDriverToken(DeliveryVehicleClaims.create(TEST_VEHICLE_ID), TaskClaims.create(TEST_TASK_ID));
    assertThat(token.authorizationClaims().toMap()).containsEntry(CLAIM_DELIVERY_VEHICLE_ID, TEST_VEHICLE_ID);
    assertThat(token.authorizationClaims().toMap()).containsEntry(CLAIM_TASK_ID, TEST_TASK_ID);
}
Also used : FleetEngineToken(com.google.fleetengine.auth.token.FleetEngineToken) Test(org.junit.Test)

Example 7 with FleetEngineToken

use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.

the class FleetEngineTokenFactoryTest method createServerToken_returnsSameValues.

@Test
public void createServerToken_returnsSameValues() {
    // Puts the JWT on the fleet engine token
    FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, FleetEngineTokenFactorySettings.builder().build());
    FleetEngineToken token = factory.createServerToken();
    assertThat(token.tokenType()).isEqualTo(SERVER);
    assertThat(token.authorizationClaims()).isEqualTo(ServerTokenClaims.create());
    assertThat(token.creationTimestamp().toInstant()).isEqualTo(ISSUED_INSTANT);
    assertThat(token.expirationTimestamp().toInstant()).isEqualTo(ISSUED_INSTANT.plus(TOKEN_EXPIRATION));
}
Also used : FleetEngineToken(com.google.fleetengine.auth.token.FleetEngineToken) Test(org.junit.Test)

Example 8 with FleetEngineToken

use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.

the class FleetEngineTokenFactoryTest method createTripToken_returnsAudienceFromSettings.

@Test
public void createTripToken_returnsAudienceFromSettings() {
    FleetEngineTokenFactorySettings settings = FleetEngineTokenFactorySettings.builder().setAudience(FAKE_AUDIENCE).build();
    FleetEngineTokenFactory factory = new FleetEngineTokenFactory(clock, settings);
    FleetEngineToken signedToken = factory.createConsumerToken(TripClaims.create());
    assertThat(signedToken.audience()).isEqualTo(FAKE_AUDIENCE);
}
Also used : FleetEngineToken(com.google.fleetengine.auth.token.FleetEngineToken) Test(org.junit.Test)

Example 9 with FleetEngineToken

use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.

the class FleetEngineTokenExpiryValidatorTest method isTokenExpired_whenAfterExpiration_tokenIsExpired.

@Test
public void isTokenExpired_whenAfterExpiration_tokenIsExpired() {
    // Expiration window irrelevant since we are testing AFTER expiration
    Duration expirationWindowDuration = Duration.ZERO;
    FleetEngineToken expiredToken = defaultToken.toBuilder().setExpirationTimestamp(parseDate("2020-06-15")).build();
    Instant now = parseDate("2020-06-16").toInstant();
    when(fakeNowClock.instant()).thenReturn(now);
    FleetEngineTokenExpiryValidator expiryValidator = new FleetEngineTokenExpiryValidator(fakeNowClock);
    boolean isTokenExpired = expiryValidator.isTokenExpired(expiredToken, expirationWindowDuration);
    assertThat(isTokenExpired).isTrue();
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) FleetEngineToken(com.google.fleetengine.auth.token.FleetEngineToken) Test(org.junit.Test)

Example 10 with FleetEngineToken

use of com.google.fleetengine.auth.token.FleetEngineToken in project java-fleetengine-auth by googlemaps.

the class FleetEngineTokenExpiryValidatorTest method isTokenExpired_whenInExpirationWindow_tokenIsExpired.

@Test
public void isTokenExpired_whenInExpirationWindow_tokenIsExpired() {
    Duration expirationWindowDuration = Duration.ofDays(1);
    FleetEngineToken expiredToken = defaultToken.toBuilder().setExpirationTimestamp(parseDate("2020-06-15")).build();
    Instant now = parseDateTime("2020-06-15T01:00:00.00Z").toInstant();
    when(fakeNowClock.instant()).thenReturn(now);
    FleetEngineTokenExpiryValidator expiryValidator = new FleetEngineTokenExpiryValidator(fakeNowClock);
    boolean isTokenExpired = expiryValidator.isTokenExpired(expiredToken, expirationWindowDuration);
    assertThat(isTokenExpired).isTrue();
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) FleetEngineToken(com.google.fleetengine.auth.token.FleetEngineToken) Test(org.junit.Test)

Aggregations

FleetEngineToken (com.google.fleetengine.auth.token.FleetEngineToken)30 Test (org.junit.Test)27 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)6 Gson (com.google.gson.Gson)5 Duration (java.time.Duration)3 Instant (java.time.Instant)3 SigningTokenException (com.google.fleetengine.auth.token.factory.signer.SigningTokenException)2 Algorithm (com.auth0.jwt.algorithms.Algorithm)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FleetEngineTokenType (com.google.fleetengine.auth.token.FleetEngineTokenType)1 ImpersonatedAccountSignerCredentials (com.google.fleetengine.auth.token.factory.signer.ImpersonatedSigner.ImpersonatedAccountSignerCredentials)1 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1