Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.google.api.gax.rpc.testing.FakeClientSettings;
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth;
import java.io.ByteArrayInputStream;
Expand All @@ -69,7 +70,7 @@ class ClientSettingsTest {
"quota_project_id_from_credentials";
private static final String QUOTA_PROJECT_ID_FROM_CONTEXT =
"quota_project_id_from_client_context";
private static final String JSON_KEY_QUOTA_PROJECT_ID =
private static final String SA_JSON_KEY_QUOTA_PROJECT_ID =
"{\n"
+ " \"private_key_id\": \"somekeyid\",\n"
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
Expand Down Expand Up @@ -102,7 +103,7 @@ class ClientSettingsTest {
+ "}";

private static final GoogleCredentials credentialsWithQuotaProject =
loadCredentials(JSON_KEY_QUOTA_PROJECT_ID);
loadServiceAccountCredentials(SA_JSON_KEY_QUOTA_PROJECT_ID);

@Test
void testEmptyBuilder() throws Exception {
Expand Down Expand Up @@ -321,10 +322,10 @@ void testApplyToAllUnaryMethods() throws Exception {
.containsExactly(StatusCode.Code.DEADLINE_EXCEEDED);
}

static GoogleCredentials loadCredentials(String credentialFile) {
static GoogleCredentials loadServiceAccountCredentials(String serviceAccountCredentialFile) {
try {
InputStream keyStream = new ByteArrayInputStream(credentialFile.getBytes());
return GoogleCredentials.fromStream(keyStream);
InputStream keyStream = new ByteArrayInputStream(serviceAccountCredentialFile.getBytes());
return ServiceAccountCredentials.fromStream(keyStream);
} catch (IOException e) {
fail("Couldn't create fake JSON credentials.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.api.core.ApiClock;
import com.google.api.core.CurrentMillisClock;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.spi.ServiceRpcFactory;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
Expand All @@ -58,7 +59,7 @@ class ServiceOptionsTest {
private static GoogleCredentials credentialsWithQuotaProject;
private static GoogleCredentials credentialsNotInGDU;

private static final String JSON_KEY =
private static final String SA_JSON_KEY =
"{\n"
+ " \"private_key_id\": \"somekeyid\",\n"
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
Expand Down Expand Up @@ -87,7 +88,7 @@ class ServiceOptionsTest {
+ " \"universe_domain\": \"googleapis.com\"\n"
+ "}";

private static final String JSON_KEY_PROJECT_ID =
private static final String SA_JSON_KEY_PROJECT_ID =
"{\n"
+ " \"private_key_id\": \"somekeyid\",\n"
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
Expand Down Expand Up @@ -117,7 +118,7 @@ class ServiceOptionsTest {
+ " \"universe_domain\": \"googleapis.com\"\n"
+ "}";

private static final String JSON_KEY_QUOTA_PROJECT_ID =
private static final String SA_JSON_KEY_QUOTA_PROJECT_ID =
"{\n"
+ " \"private_key_id\": \"somekeyid\",\n"
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
Expand Down Expand Up @@ -149,7 +150,7 @@ class ServiceOptionsTest {
+ "}";

// Key added by copying the keys above and adding in the universe domain field
private static final String JSON_KEY_NON_GDU =
private static final String SA_JSON_KEY_NON_GDU =
"{\n"
+ " \"private_key_id\": \"somekeyid\",\n"
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
Expand Down Expand Up @@ -179,16 +180,16 @@ class ServiceOptionsTest {
+ "}";

static {
credentials = loadCredentials(JSON_KEY);
credentialsWithProjectId = loadCredentials(JSON_KEY_PROJECT_ID);
credentialsWithQuotaProject = loadCredentials(JSON_KEY_QUOTA_PROJECT_ID);
credentialsNotInGDU = loadCredentials(JSON_KEY_NON_GDU);
credentials = loadServiceAccountCredentials(SA_JSON_KEY);
credentialsWithProjectId = loadServiceAccountCredentials(SA_JSON_KEY_PROJECT_ID);
credentialsWithQuotaProject = loadServiceAccountCredentials(SA_JSON_KEY_QUOTA_PROJECT_ID);
credentialsNotInGDU = loadServiceAccountCredentials(SA_JSON_KEY_NON_GDU);
}

static GoogleCredentials loadCredentials(String credentialFile) {
static GoogleCredentials loadServiceAccountCredentials(String credentialFile) {
try {
InputStream keyStream = new ByteArrayInputStream(credentialFile.getBytes());
return GoogleCredentials.fromStream(keyStream);
return ServiceAccountCredentials.fromStream(keyStream);
} catch (IOException e) {
fail("Couldn't create fake JSON credentials.");
}
Expand Down
Loading