use of com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalAppIdentityServiceTest method testLocalGetAccessTokenWithApplicationCreadentials.
@Test
public void testLocalGetAccessTokenWithApplicationCreadentials() throws Exception {
LocalAppIdentityService service = new LocalAppIdentityService() {
@Override
String getApplicationDefaultToken(GetAccessTokenRequest request) throws IOException {
return "accessToken: xyz";
}
};
GetAccessTokenRequest.Builder requestBuilder = GetAccessTokenRequest.newBuilder();
requestBuilder.addScope("scope1");
GetAccessTokenResponse response = service.getAccessToken(status, requestBuilder.build());
assertThat(response.getAccessToken()).isEqualTo("accessToken: xyz");
}
use of com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalAppIdentityServiceTest method testNullLocalGetAccessTokenApplicationCredentials.
@Test
public void testNullLocalGetAccessTokenApplicationCredentials() throws Exception {
LocalAppIdentityService service = new LocalAppIdentityService() {
@Override
String getApplicationDefaultToken(GetAccessTokenRequest request) throws IOException {
return null;
}
};
service.setClock(clock);
// arbitrary seconds since epoch.
long now = 10002;
clock.setCurrentTime(now * 1000);
GetAccessTokenRequest.Builder requestBuilder = GetAccessTokenRequest.newBuilder();
requestBuilder.addScope("scope1");
GetAccessTokenResponse response = service.getAccessToken(status, requestBuilder.build());
// 2000 is 'now' in ms % 10000.
assertThat(response.getAccessToken()).isEqualTo("InvalidToken:scope1:2000");
long expectedTime = now + 1800;
assertThat(response.getExpirationTime()).isEqualTo(expectedTime);
}
use of com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest in project appengine-java-standard by GoogleCloudPlatform.
the class LocalAppIdentityServiceTest method testLocalGetAccessTokenNoApplicationCreadentials.
@Test
public void testLocalGetAccessTokenNoApplicationCreadentials() throws Exception {
LocalAppIdentityService service = new LocalAppIdentityService() {
@Override
String getApplicationDefaultToken(GetAccessTokenRequest request) throws IOException {
throw new IOException("Cannot get application default credentials");
}
};
service.setClock(clock);
// arbitrary seconds since epoch.
long now = 10002;
clock.setCurrentTime(now * 1000);
GetAccessTokenRequest.Builder requestBuilder = GetAccessTokenRequest.newBuilder();
requestBuilder.addScope("scope1");
GetAccessTokenResponse response = service.getAccessToken(status, requestBuilder.build());
// 2000 is 'now' in ms % 10000.
assertThat(response.getAccessToken()).isEqualTo("InvalidToken:scope1:2000");
long expectedTime = now + 1800;
assertThat(response.getExpirationTime()).isEqualTo(expectedTime);
}
Aggregations