Skip to content

Commit d7d4bf9

Browse files
committed
Test code cleanup and doc fix
1 parent a267bbb commit d7d4bf9

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

javaagent-extensions/gcp-auth/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def otelAgentPath = <OpenTelemetry Java Agent location>
4848
// Specify the path for Google Cloud Authentication Extension for the Java Agent.
4949
def extensionPath = <Google Cloud Authentication Extension location>
5050
def googleCloudProjectId = <Your Google Cloud Project ID>
51-
def googleCloudRegion = <Your preferred Google Cloud Region>
5251
def googleOtlpEndpoint = <Google Cloud OTLP endpoint>
5352
5453
application {

javaagent-extensions/gcp-auth/src/test/java/com/google/cloud/opentelemetry/extension/auth/GcpAuthExtensionSmokeTest.java renamed to javaagent-extensions/gcp-auth/src/test/java/com/google/cloud/opentelemetry/extension/auth/GcpAuthExtensionEndToEndTest.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,34 @@
6262
@SpringBootTest(
6363
classes = {Application.class},
6464
webEnvironment = WebEnvironment.RANDOM_PORT)
65-
public class GcpAuthExtensionSmokeTest {
65+
public class GcpAuthExtensionEndToEndTest {
6666

6767
@LocalServerPort private int testApplicationPort; // port at which the spring app is running
6868

6969
@Autowired private TestRestTemplate template;
7070

7171
// The port at which the backend server will receive telemetry
7272
private static final int EXPORTER_ENDPOINT_PORT = 4318;
73-
// The port at which the mock GCP metadata server will run
74-
private static final int MOCK_GCP_METADATA_PORT = 8090;
73+
// The port at which the mock GCP OAuth 2.0 server will run
74+
private static final int MOCK_GCP_OAUTH2_PORT = 8090;
7575

7676
// Backend server to which the application under test will export traces
7777
// the export config is specified in the build.gradle file.
7878
private static ClientAndServer backendServer;
7979

80-
// Mock server to intercept calls to the GCP metadata server and provide fake credentials
81-
private static ClientAndServer mockGcpMetadataServer;
80+
// Mock server to intercept calls to the GCP OAuth 2.0 server and provide fake credentials
81+
private static ClientAndServer mockGcpOAuth2Server;
8282

83-
private static final String METADATA_GOOGLE_INTERNAL = "metadata.google.internal";
8483
private static final String DUMMY_GCP_QUOTA_PROJECT = System.getenv("GOOGLE_CLOUD_QUOTA_PROJECT");
8584
private static final String DUMMY_GCP_PROJECT = System.getProperty("google.cloud.project");
8685

8786
@BeforeAll
8887
public static void setup() throws NoSuchAlgorithmException, KeyManagementException {
89-
// Set up the mock server to always respond with 200
90-
// Setup proxy host
88+
// Setup proxy host(s)
9189
System.setProperty("http.proxyHost", "localhost");
92-
System.setProperty("http.proxyPort", MOCK_GCP_METADATA_PORT + "");
90+
System.setProperty("http.proxyPort", MOCK_GCP_OAUTH2_PORT + "");
9391
System.setProperty("https.proxyHost", "localhost");
94-
System.setProperty("https.proxyPort", MOCK_GCP_METADATA_PORT + "");
92+
System.setProperty("https.proxyPort", MOCK_GCP_OAUTH2_PORT + "");
9593
System.setProperty("http.nonProxyHost", "localhost");
9694
System.setProperty("https.nonProxyHost", "localhost");
9795

@@ -106,47 +104,33 @@ public static void setup() throws NoSuchAlgorithmException, KeyManagementExcepti
106104
// Set up the mock gcp metadata server to provide fake credentials
107105
String accessTokenResponse =
108106
"{\"access_token\": \"fake.access_token\",\"expires_in\": 3600, \"token_type\": \"Bearer\"}";
109-
mockGcpMetadataServer = ClientAndServer.startClientAndServer(MOCK_GCP_METADATA_PORT);
107+
mockGcpOAuth2Server = ClientAndServer.startClientAndServer(MOCK_GCP_OAUTH2_PORT);
110108

111109
MockServerClient mockServerClient =
112-
new MockServerClient("localhost", MOCK_GCP_METADATA_PORT).withSecure(true);
110+
new MockServerClient("localhost", MOCK_GCP_OAUTH2_PORT).withSecure(true);
113111

114-
// mock the token refresh
112+
// mock the token refresh - always respond with 200
115113
mockServerClient
116114
.when(request().withMethod("POST").withPath("/token"))
117115
.respond(
118116
response()
119117
.withStatusCode(200)
120118
.withHeader("Content-Type", "application/json")
121119
.withBody(new JsonBody(accessTokenResponse)));
122-
// mock the gcp metadata server
123-
mockServerClient
124-
.when(
125-
request()
126-
.withMethod("GET")
127-
.withPath("/computeMetadata/v1/instance/service-accounts/default/token")
128-
.withHeader("Host", METADATA_GOOGLE_INTERNAL)
129-
.withHeader("Metadata-Flavor", "Google"))
130-
.respond(
131-
response()
132-
.withStatusCode(200)
133-
.withHeader("Content-Type", "application/json")
134-
.withBody(new JsonBody(accessTokenResponse)));
135120
}
136121

137122
@AfterAll
138123
public static void teardown() {
139124
// Stop the backend server
140125
stopQuietly(backendServer);
141-
stopQuietly(mockGcpMetadataServer);
126+
stopQuietly(mockGcpOAuth2Server);
142127
}
143128

144129
@Test
145130
public void authExtensionSmokeTest() {
146131
ResponseEntity<?> a =
147132
template.getForEntity(
148133
URI.create("http://localhost:" + testApplicationPort + "/ping"), String.class);
149-
System.out.println("resp is " + a.toString());
150134

151135
await()
152136
.atMost(10, TimeUnit.SECONDS)

0 commit comments

Comments
 (0)