From 309312daea64c6928e59826bc37dcfae361d5fab Mon Sep 17 00:00:00 2001 From: Timur Sadykov Date: Sun, 19 Nov 2023 23:03:00 -0800 Subject: [PATCH] fix: test fixes --- ...lAccountAuthorizedUserCredentialsTest.java | 6 ++-- .../auth/oauth2/GoogleCredentialsTest.java | 8 ++---- .../auth/oauth2/UserCredentialsTest.java | 28 ------------------- 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentialsTest.java index 2fb89dfdc..bc74a0cef 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentialsTest.java @@ -985,9 +985,9 @@ public void equals_differentAccessToken() { ExternalAccountAuthorizedUserCredentials secondCredentials = credentials.toBuilder().setAccessToken(new AccessToken("different", new Date())).build(); - assertNotEquals(secondCredentials, credentials); - assertNotEquals(credentials, secondCredentials); - assertNotEquals(credentials.hashCode(), secondCredentials.hashCode()); + // credentials objects are still interchangeable even if access_tokens instances are different + assertEquals(secondCredentials, credentials); + assertEquals(credentials.hashCode(), secondCredentials.hashCode()); } @Test diff --git a/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java index 0b740034c..71382a3b7 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java @@ -148,7 +148,7 @@ public void fromStream_serviceAccount_noUniverse_providesToken() throws IOExcept } @Test - public void fromStream_serviceAccount_Universe_providesToken() throws IOException { + public void fromStream_serviceAccount_Universe_noToken() throws IOException { MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); transportFactory.transport.addServiceAccount(SA_CLIENT_EMAIL, ACCESS_TOKEN); InputStream serviceAccountStream = @@ -162,11 +162,7 @@ public void fromStream_serviceAccount_Universe_providesToken() throws IOExceptio assertEquals(TPC_UNIVERSE, credentials.getUniverseDomain()); credentials = credentials.createScoped(SCOPES); Map> metadata = credentials.getRequestMetadata(CALL_URI); - TestUtils.assertContainsBearerToken(metadata, ACCESS_TOKEN); - - credentials = credentials.createScoped(SCOPES, DEFAULT_SCOPES); - metadata = credentials.getRequestMetadata(CALL_URI); - TestUtils.assertContainsBearerToken(metadata, ACCESS_TOKEN); + assertNotNull(((ServiceAccountCredentials) credentials).getSelfSignedJwtCredentialsWithScope()); } @Test diff --git a/oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java index a5c666936..6f793204c 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/UserCredentialsTest.java @@ -342,34 +342,6 @@ public void equals_false_refreshToken() throws IOException { assertFalse(otherCredentials.equals(credentials)); } - @Test - public void equals_false_accessToken() throws IOException { - final URI tokenServer1 = URI.create("https://foo1.com/bar"); - AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null); - AccessToken otherAccessToken = new AccessToken("otherAccessToken", null); - MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory(); - UserCredentials credentials = - UserCredentials.newBuilder() - .setClientId(CLIENT_ID) - .setClientSecret(CLIENT_SECRET) - .setRefreshToken(REFRESH_TOKEN) - .setAccessToken(accessToken) - .setHttpTransportFactory(httpTransportFactory) - .setTokenServerUri(tokenServer1) - .build(); - UserCredentials otherCredentials = - UserCredentials.newBuilder() - .setClientId(CLIENT_ID) - .setClientSecret(CLIENT_SECRET) - .setRefreshToken(REFRESH_TOKEN) - .setAccessToken(otherAccessToken) - .setHttpTransportFactory(httpTransportFactory) - .setTokenServerUri(tokenServer1) - .build(); - assertFalse(credentials.equals(otherCredentials)); - assertFalse(otherCredentials.equals(credentials)); - } - @Test public void equals_false_transportFactory() throws IOException { final URI tokenServer1 = URI.create("https://foo1.com/bar");