Skip to content

Commit

Permalink
fix: Issue #1347: ExternalAccountCredentials serialization is broken (#…
Browse files Browse the repository at this point in the history
…1358)

* fix: Issue #1347: ExternalAccountCredentials serialization is broken

* fix test

* fix lint

* Update oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java

Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com>

* address the removal of redaundant public

* move the getter to test class

---------

Co-authored-by: Leo <39062083+lsirac@users.noreply.github.com>
  • Loading branch information
BigTailWolf and lsirac committed Jan 24, 2024
1 parent 6ec1116 commit e3a2e9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Expand Up @@ -42,6 +42,7 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -555,6 +556,13 @@ public CredentialSource getCredentialSource() {
return credentialSource;
}

@SuppressWarnings("unused")
private void readObject(ObjectInputStream input) throws IOException, ClassNotFoundException {
// Properly deserialize the transient transportFactory.
input.defaultReadObject();
transportFactory = newInstance(transportFactoryClassName);
}

@Nullable
public String getServiceAccountImpersonationUrl() {
return serviceAccountImpersonationUrl;
Expand Down
Expand Up @@ -1109,6 +1109,9 @@ public void serialize() throws IOException, ClassNotFoundException {
testCredentials.getServiceAccountImpersonationOptions().getLifetime(),
deserializedCredentials.getServiceAccountImpersonationOptions().getLifetime());
assertSame(deserializedCredentials.clock, Clock.SYSTEM);
assertEquals(
MockExternalAccountCredentialsTransportFactory.class,
deserializedCredentials.toBuilder().getHttpTransportFactory().getClass());
}

@Test
Expand Down Expand Up @@ -1299,17 +1302,30 @@ protected TestCredentialSource(Map<String, Object> credentialSourceMap) {
}
}

@Override
public Builder toBuilder() {
return new Builder(this);
}

public static Builder newBuilder() {
return new Builder();
}

static class Builder extends ExternalAccountCredentials.Builder {
Builder() {}

Builder(TestExternalAccountCredentials credentials) {
super(credentials);
}

@Override
public TestExternalAccountCredentials build() {
return new TestExternalAccountCredentials(this);
}

public HttpTransportFactory getHttpTransportFactory() {
return transportFactory;
}
}

protected TestExternalAccountCredentials(ExternalAccountCredentials.Builder builder) {
Expand Down

0 comments on commit e3a2e9c

Please sign in to comment.