Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: add code sample and test for getting an access token from an im…" #1299

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

42 changes: 12 additions & 30 deletions samples/snippets/src/test/java/SnippetsIT.java
Original file line number Diff line number Diff line change
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