use of com.google.api.client.testing.http.FixedClock in project google-auth-library-java by google.
the class ServiceAccountCredentialsTest method refreshAccessToken_tokenExpiry.
@Test
public void refreshAccessToken_tokenExpiry() throws IOException {
final String tokenString = "1/MkSJoj1xsli0AccessToken_NKPY2";
MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
MockTokenServerTransport transport = transportFactory.transport;
ServiceAccountCredentials credentials = ServiceAccountCredentials.fromPkcs8(SA_CLIENT_ID, SA_CLIENT_EMAIL, SA_PRIVATE_KEY_PKCS8, SA_PRIVATE_KEY_ID, SCOPES, transportFactory, null);
credentials.clock = new FixedClock(0L);
transport.addServiceAccount(SA_CLIENT_EMAIL, tokenString);
AccessToken accessToken = credentials.refreshAccessToken();
assertEquals(tokenString, accessToken.getTokenValue());
assertEquals(3600 * 1000L, accessToken.getExpirationTimeMillis().longValue());
// Test for large expires_in values (should not overflow).
transport.setExpiresInSeconds(3600 * 1000);
accessToken = credentials.refreshAccessToken();
assertEquals(tokenString, accessToken.getTokenValue());
assertEquals(3600 * 1000 * 1000L, accessToken.getExpirationTimeMillis().longValue());
}
use of com.google.api.client.testing.http.FixedClock in project google-api-java-client by google.
the class GoogleIdTokenVerifierTest method testBuilder.
public void testBuilder() throws Exception {
GoogleIdTokenVerifier.Builder builder = new GoogleIdTokenVerifier.Builder(new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory()).setIssuer(ISSUER).setAudience(TRUSTED_CLIENT_IDS);
assertEquals(Clock.SYSTEM, builder.getClock());
assertEquals(ISSUER, builder.getIssuer());
assertTrue(TRUSTED_CLIENT_IDS.equals(builder.getAudience()));
Clock clock = new FixedClock(4);
builder.setClock(clock);
assertEquals(clock, builder.getClock());
IdTokenVerifier verifier = builder.build();
assertEquals(clock, verifier.getClock());
assertEquals(ISSUER, verifier.getIssuer());
assertEquals(TRUSTED_CLIENT_IDS, Lists.newArrayList(verifier.getAudience()));
}
use of com.google.api.client.testing.http.FixedClock in project google-api-java-client by google.
the class GooglePublicKeysManagerTest method testLoadCerts_cache.
public void testLoadCerts_cache() throws Exception {
PublicCertsMockHttpTransport transport = new PublicCertsMockHttpTransport();
transport.useAgeHeader = true;
GooglePublicKeysManager certs = new GooglePublicKeysManager.Builder(transport, new JacksonFactory()).setClock(new FixedClock(100)).build();
certs.refresh();
assertEquals(2, certs.getPublicKeys().size());
assertEquals(100 + (MAX_AGE - AGE) * 1000, certs.getExpirationTimeMilliseconds());
}
Aggregations