Skip to content

Commit

Permalink
deps: Update com.google.auth dependencies to v1.21.0 (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttosta-google committed Jan 8, 2024
1 parent 1ffdd02 commit a8f1c00
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
<version>1.20.0</version>
<version>1.21.0</version>
</dependency>

<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.20.0</version>
<version>1.21.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ default GoogleCredentials getCredentials() {
? Date.from(Instant.ofEpochMilli(credential.getExpirationTimeMilliseconds()))
: null);

return new GoogleCredentials(accessToken) {
return new GoogleCredentials(GoogleCredentials.newBuilder().setAccessToken(accessToken)) {
@Override
public AccessToken refreshAccessToken() throws IOException {
credential.refreshToken();
Expand Down
12 changes: 10 additions & 2 deletions core/src/test/java/com/google/cloud/sql/ConnectorConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,16 @@ public void testEqual_withDelegatesEqual() {

@Test
public void testNotEqual_withGoogleCredentialsNotEqual() {
GoogleCredentials c1 = GoogleCredentials.create(new AccessToken("c1", null));
GoogleCredentials c2 = GoogleCredentials.create(new AccessToken("c2", null));
GoogleCredentials c1 =
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("c1", null))
.setQuotaProjectId("project1")
.build();
GoogleCredentials c2 =
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("c2", null))
.setQuotaProjectId("project2")
.build();
ConnectorConfig k1 = new ConnectorConfig.Builder().withGoogleCredentials(c1).build();
ConnectorConfig k2 = new ConnectorConfig.Builder().withGoogleCredentials(c2).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class CredentialFactoryTest {

@Test
public void testDefaultGetCredentialsWorksForGoogleCredentials() {
GoogleCredentials googleCredentials = new GoogleCredentials(new AccessToken("my-token", null));
GoogleCredentials googleCredentials =
GoogleCredentials.create(new AccessToken("my-token", null));
CredentialFactory factory = new GoogleCredentialsFactory(googleCredentials);

// Expected behavior from old implementation before getCredential()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void getInstanceCredentialFactory_returnsSupplierCredentialFactory() {

@Test
public void getInstanceCredentialFactory_returnsImpersonatingCredentialFactory() {
GoogleCredentials c = new GoogleCredentials(null);
GoogleCredentials c = GoogleCredentials.create(null);
ConnectorConfig config =
new ConnectorConfig.Builder()
.withGoogleCredentials(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void setup() throws IOException {

// Scoped credentials can't be refreshed.
scopedCredentials =
new GoogleCredentials(new AccessToken("my-scoped-token", null)) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-scoped-token", null))) {
@Override
public AccessToken refreshAccessToken() throws IOException {
refreshCounter.incrementAndGet();
Expand All @@ -82,7 +84,9 @@ public void testEmptyTokenOnEmptyCredentials() throws IOException {
public void testWithValidToken() throws Exception {
// Google credentials can be refreshed
GoogleCredentials googleCredentials =
new GoogleCredentials(new AccessToken("my-token", Date.from(future))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-token", Date.from(future)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand Down Expand Up @@ -133,7 +137,9 @@ public HttpRequestInitializer create() {
public void testThrowsOnExpiredTokenRefreshNotSupported() throws Exception {

GoogleCredentials expiredGoogleCredentials =
new GoogleCredentials(new AccessToken("my-expired-token", Date.from(past))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-expired-token", Date.from(past)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand All @@ -158,7 +164,9 @@ public AccessToken refreshAccessToken() throws IOException {
public void testThrowsOnExpiredTokenRefreshStillExpired() throws Exception {

GoogleCredentials refreshGetsExpiredToken =
new GoogleCredentials(new AccessToken("my-expired-token", Date.from(past))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-expired-token", Date.from(past)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand All @@ -182,7 +190,9 @@ public AccessToken refreshAccessToken() throws IOException {
@Test
public void testValidOnRefreshSucceeded() throws Exception {
GoogleCredentials refreshableCredentials =
new GoogleCredentials(new AccessToken("my-expired-token", Date.from(past))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-expired-token", Date.from(past)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand All @@ -209,7 +219,9 @@ public AccessToken refreshAccessToken() throws IOException {
@Test
public void testValidOnRefreshFailsSometimes() throws Exception {
GoogleCredentials refreshableCredentials =
new GoogleCredentials(new AccessToken("my-expired-token", Date.from(past))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-expired-token", Date.from(past)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand Down Expand Up @@ -241,7 +253,9 @@ public AccessToken refreshAccessToken() throws IOException {
public void downscopesGoogleCredentials() {
// Google credentials can be refreshed
GoogleCredentials googleCredentials =
new GoogleCredentials(new AccessToken("my-token", Date.from(future))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-token", Date.from(future)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand Down Expand Up @@ -269,7 +283,8 @@ public void throwsErrorForWrongCredentialType() {
@Test
public void throwsErrorForEmptyAccessToken() {
GoogleCredentials creds =
new GoogleCredentials(new AccessToken("", Date.from(future))) {
new GoogleCredentials(
GoogleCredentials.newBuilder().setAccessToken(new AccessToken("", Date.from(future)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand All @@ -286,7 +301,9 @@ public GoogleCredentials createScoped(String... scopes) {
@Test
public void throwsErrorForExpiredAccessToken() {
GoogleCredentials refreshableCredentials =
new GoogleCredentials(new AccessToken("my-expired-token", Date.from(past))) {
new GoogleCredentials(
GoogleCredentials.newBuilder()
.setAccessToken(new AccessToken("my-expired-token", Date.from(past)))) {
@Override
public GoogleCredentials createScoped(String... scopes) {
return scopedCredentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static class RefreshGoogleCredentials extends GoogleCredentials {
private final OAuth2Credentials oauth2;

RefreshGoogleCredentials(OAuth2Credentials oauth2) {
super(oauth2.getAccessToken());
super(GoogleCredentials.newBuilder().setAccessToken(oauth2.getAccessToken()));
this.oauth2 = oauth2;
}

Expand Down

0 comments on commit a8f1c00

Please sign in to comment.