Search in sources :

Example 1 with GetAccessTokenRequest

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");
}
Also used : GetAccessTokenResponse(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenResponse) GetAccessTokenRequest(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest) Test(org.junit.Test)

Example 2 with GetAccessTokenRequest

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);
}
Also used : GetAccessTokenResponse(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenResponse) GetAccessTokenRequest(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest) Test(org.junit.Test)

Example 3 with GetAccessTokenRequest

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);
}
Also used : GetAccessTokenResponse(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenResponse) GetAccessTokenRequest(com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

GetAccessTokenRequest (com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenRequest)3 GetAccessTokenResponse (com.google.appengine.api.appidentity.AppIdentityServicePb.GetAccessTokenResponse)3 Test (org.junit.Test)3 IOException (java.io.IOException)1