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);
}
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));
}
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);
}
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();
}
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();
}
Aggregations