Skip to content

Commit a57def2

Browse files
committed
Finalizing GDCH credentials support by addressing reviewer comments
1 parent 00ff824 commit a57def2

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ public Builder setCaCertPath(String caCertPath) {
570570
return this;
571571
}
572572

573+
/**
574+
* Sets the intended audience for GDCH credentials.
575+
*
576+
* @param apiAudience The audience string. Cannot be null or empty.
577+
* @return this builder.
578+
* @throws IllegalArgumentException if the audience is null or empty.
579+
*/
573580
@CanIgnoreReturnValue
574581
public Builder setGdchAudience(String apiAudience) {
575582
if (Strings.isNullOrEmpty(apiAudience)) {

oauth2_http/javatests/com/google/auth/oauth2/DefaultCredentialsProviderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class DefaultCredentialsProviderTest {
8383
private static final String SA_PRIVATE_KEY_ID = "d84a4fefcf50791d4a90f2d7af17469d6282df9d";
8484
private static final String SA_PRIVATE_KEY_PKCS8 =
8585
ServiceAccountCredentialsTest.PRIVATE_KEY_PKCS8;
86-
private static final String GDCH_SA_FORMAT_VERSION =
87-
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION;
86+
8887
private static final String GDCH_SA_PROJECT_ID = "gdch-service-account-project-id";
8988
private static final String GDCH_SA_PRIVATE_KEY_ID = "d84a4fefcf50791d4a90f2d7af17469d6282df9d";
9089
private static final String GDCH_SA_PRIVATE_KEY_PKC8 = GdchCredentialsTest.PRIVATE_KEY_PKCS8;
@@ -376,7 +375,7 @@ void getDefaultCredentials_GdchServiceAccount() throws IOException {
376375
MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
377376
InputStream gdchServiceAccountStream =
378377
GdchCredentialsTest.writeGdchServiceAccountStream(
379-
GDCH_SA_FORMAT_VERSION,
378+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
380379
GDCH_SA_PROJECT_ID,
381380
GDCH_SA_PRIVATE_KEY_ID,
382381
GDCH_SA_PRIVATE_KEY_PKC8,

oauth2_http/javatests/com/google/auth/oauth2/GdchCredentialsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ void transcodeDerToConcat_invalidLength() {
11011101

11021102
@Test
11031103
void transcodeDerToConcat_invalidRInteger() {
1104-
// Missing INTEGER for R
1104+
// Uses BIT STRING (0x03) instead of INTEGER (0x02) for R
11051105
byte[] invalidDer = new byte[] {0x30, 0x06, 0x03, 0x01, 0x01, 0x02, 0x01, 0x02};
11061106
GoogleAuthException e =
11071107
assertThrows(
@@ -1111,7 +1111,7 @@ void transcodeDerToConcat_invalidRInteger() {
11111111

11121112
@Test
11131113
void transcodeDerToConcat_invalidSInteger() {
1114-
// Missing INTEGER for S
1114+
// Uses BIT STRING (0x03) instead of INTEGER (0x02) for S
11151115
byte[] invalidDer = new byte[] {0x30, 0x06, 0x02, 0x01, 0x01, 0x03, 0x01, 0x01};
11161116
GoogleAuthException e =
11171117
assertThrows(

oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class GoogleCredentialsTest extends BaseSerializationTest {
7171
private static final String SA_PRIVATE_KEY_ID = "d84a4fefcf50791d4a90f2d7af17469d6282df9d";
7272
private static final String SA_PRIVATE_KEY_PKCS8 =
7373
ServiceAccountCredentialsTest.PRIVATE_KEY_PKCS8;
74-
private static final String GDCH_SA_FORMAT_VERSION =
75-
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION;
74+
7675
private static final String GDCH_SA_PROJECT_ID = "gdch-service-account-project-id";
7776
private static final String GDCH_SA_PRIVATE_KEY_ID = "d84a4fefcf50791d4a90f2d7af17469d6282df9d";
7877
private static final String GDCH_SA_PRIVATE_KEY_PKC8 = GdchCredentialsTest.PRIVATE_KEY_PKCS8;
@@ -245,7 +244,7 @@ void fromStream_gdchServiceAccount_correct() throws IOException {
245244
MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
246245
InputStream gdchServiceAccountStream =
247246
GdchCredentialsTest.writeGdchServiceAccountStream(
248-
GDCH_SA_FORMAT_VERSION,
247+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
249248
GDCH_SA_PROJECT_ID,
250249
GDCH_SA_PRIVATE_KEY_ID,
251250
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -295,7 +294,7 @@ void fromStream_gdchServiceAccountNoFormatVersion_throws() throws IOException {
295294
void fromStream_gdchServiceAccountNoProjectId_throws() throws IOException {
296295
InputStream gdchServiceAccountStream =
297296
GdchCredentialsTest.writeGdchServiceAccountStream(
298-
GDCH_SA_FORMAT_VERSION,
297+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
299298
null,
300299
GDCH_SA_PRIVATE_KEY_ID,
301300
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -310,7 +309,7 @@ void fromStream_gdchServiceAccountNoProjectId_throws() throws IOException {
310309
void fromStream_gdchServiceAccountNoPrivateKeyId_throws() throws IOException {
311310
InputStream gdchServiceAccountStream =
312311
GdchCredentialsTest.writeGdchServiceAccountStream(
313-
GDCH_SA_FORMAT_VERSION,
312+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
314313
GDCH_SA_PROJECT_ID,
315314
null,
316315
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -325,7 +324,7 @@ void fromStream_gdchServiceAccountNoPrivateKeyId_throws() throws IOException {
325324
void fromStream_gdchServiceAccountNoPrivateKey_throws() throws IOException {
326325
InputStream gdchServiceAccountStream =
327326
GdchCredentialsTest.writeGdchServiceAccountStream(
328-
GDCH_SA_FORMAT_VERSION,
327+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
329328
GDCH_SA_PROJECT_ID,
330329
GDCH_SA_PRIVATE_KEY_ID,
331330
null,
@@ -340,7 +339,7 @@ void fromStream_gdchServiceAccountNoPrivateKey_throws() throws IOException {
340339
void fromStream_gdchServiceAccountNoServiceIdentityName_throws() throws IOException {
341340
InputStream gdchServiceAccountStream =
342341
GdchCredentialsTest.writeGdchServiceAccountStream(
343-
GDCH_SA_FORMAT_VERSION,
342+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
344343
GDCH_SA_PROJECT_ID,
345344
GDCH_SA_PRIVATE_KEY_ID,
346345
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -355,7 +354,7 @@ void fromStream_gdchServiceAccountNoServiceIdentityName_throws() throws IOExcept
355354
void fromStream_gdchServiceAccountNoTokenServerUri_throws() throws IOException {
356355
InputStream gdchServiceAccountStream =
357356
GdchCredentialsTest.writeGdchServiceAccountStream(
358-
GDCH_SA_FORMAT_VERSION,
357+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
359358
GDCH_SA_PROJECT_ID,
360359
GDCH_SA_PRIVATE_KEY_ID,
361360
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -380,14 +379,14 @@ void fromStream_gdchServiceAccountInvalidFormatVersion_throws() throws IOExcepti
380379

381380
testFromStreamException(
382381
gdchServiceAccountStream,
383-
String.format("Only format version %s is supported", GDCH_SA_FORMAT_VERSION));
382+
String.format("Only format version %s is supported", GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION));
384383
}
385384

386385
@Test
387386
void fromStream_gdchServiceAccountInvalidCaCertPath_throws() throws IOException {
388387
InputStream gdchServiceAccountStream =
389388
GdchCredentialsTest.writeGdchServiceAccountStream(
390-
GDCH_SA_FORMAT_VERSION,
389+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
391390
GDCH_SA_PROJECT_ID,
392391
GDCH_SA_PRIVATE_KEY_ID,
393392
GDCH_SA_PRIVATE_KEY_PKC8,
@@ -854,7 +853,7 @@ void getCredentialInfo_userCredentials() throws IOException {
854853
void getCredentialInfo_gdchCredentials() throws IOException {
855854
InputStream gdchServiceAccountStream =
856855
GdchCredentialsTest.writeGdchServiceAccountStream(
857-
GDCH_SA_FORMAT_VERSION,
856+
GdchCredentials.SUPPORTED_JSON_FORMAT_VERSION,
858857
GDCH_SA_PROJECT_ID,
859858
GDCH_SA_PRIVATE_KEY_ID,
860859
GDCH_SA_PRIVATE_KEY_PKC8,

0 commit comments

Comments
 (0)