Skip to content

Commit

Permalink
Revert "feat: add code sample and test for getting an access token fr…
Browse files Browse the repository at this point in the history
…om an im…" (#1299)

* Revert "feat: add code sample and test for getting an access token from an impersonated SA (#1289)"

This reverts commit 826ee40.

* fix test assertion
  • Loading branch information
Sita04 committed Oct 11, 2023
1 parent 826ee40 commit 2d867b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 107 deletions.

This file was deleted.

42 changes: 12 additions & 30 deletions samples/snippets/src/test/java/SnippetsIT.java
Expand Up @@ -40,8 +40,6 @@ public class SnippetsIT {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String CREDENTIALS = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
private static final String impersonatedServiceAccount = "TODO";
private static final String scope = "https://www.googleapis.com/auth/cloud-platform";
private ByteArrayOutputStream stdOut;

// Check if the required environment variables are set.
Expand All @@ -64,7 +62,18 @@ public static void setup() throws IOException {
}

@AfterClass
public static void cleanup() {
public static void cleanup() {}

@Before
public void beforeEach() {
stdOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(stdOut));
}

@After
public void afterEach() {
stdOut = null;
System.setOut(null);
}

// Get an id token from a Google service account.
Expand All @@ -84,18 +93,6 @@ private static String getIdTokenFromServiceAccount(
return idToken.getTokenValue();
}

@Before
public void beforeEach() {
stdOut = new ByteArrayOutputStream();
System.setOut(new PrintStream(stdOut));
}

@After
public void afterEach() {
stdOut = null;
System.setOut(null);
}

@Test
public void testIdTokenFromServiceAccount() throws IOException {
IdTokenFromServiceAccount.getIdTokenFromServiceAccount(CREDENTIALS, "https://example.com");
Expand All @@ -110,21 +107,6 @@ public void testVerifyGoogleIdToken() throws IOException {
idToken, "https://example.com", "https://www.googleapis.com/oauth2/v3/certs");
}

@Test
public void testAccessTokenFromImpersonatedCredentials()
throws GeneralSecurityException, IOException {
AccessTokenFromImpersonatedCredentials.getAccessToken(impersonatedServiceAccount, scope);
assertThat(stdOut.toString()).contains("Generated access token.");
}

@Test
public void testIdTokenFromImpersonatedCredentials()
throws GeneralSecurityException, IOException {
IdTokenFromImpersonatedCredentials.getIdTokenUsingOAuth2(impersonatedServiceAccount, scope,
"https://example.com");
assertThat(stdOut.toString()).contains("Generated ID token.");
}

@Test
public void testIdTokenFromMetadataServer() throws GeneralSecurityException, IOException {
IdTokenFromMetadataServer.getIdTokenFromMetadataServer("https://www.google.com");
Expand Down

0 comments on commit 2d867b0

Please sign in to comment.