-
Notifications
You must be signed in to change notification settings - Fork 275
fix(gdch): support EC private keys #1896
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
base: main
Are you sure you want to change the base?
Changes from all commits
dc5b79c
0c5e423
5851b3e
258ac9d
e8511bb
a4d0f93
e3d5302
e6635c6
cc49dba
f58f593
42f2662
91a3751
b83a511
625741e
1e0a7c3
24cd25d
027a242
a8b459b
4e8af24
f257a81
c523df2
ed026a4
1528e76
7300e59
382d8ae
c348ee1
6323455
1aa7715
4f69872
f4b53ee
b3085a2
39ef931
3003076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,26 @@ public static Map<String, String> parseQuery(String query) throws IOException { | |
| return map; | ||
| } | ||
|
|
||
| /** | ||
| * Parses the request body as either JSON or a query string. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: query string is part of the URL, right? This seems to be doing two separate things. Can we separate the logic for this into two methods:
|
||
| * | ||
| * @param content The request body content. | ||
| * @return A map of the parsed parameters. | ||
| * @throws IOException If the content cannot be parsed. | ||
| */ | ||
| public static Map<String, String> parseBody(String content) throws IOException { | ||
| if (content != null && content.trim().startsWith("{")) { | ||
| GenericJson json = JSON_FACTORY.fromString(content, GenericJson.class); | ||
| Map<String, String> map = new HashMap<>(); | ||
| for (Map.Entry<String, Object> entry : json.entrySet()) { | ||
| Object value = entry.getValue(); | ||
| map.put(entry.getKey(), value == null ? null : value.toString()); | ||
| } | ||
| return map; | ||
| } | ||
| return parseQuery(content); | ||
| } | ||
|
|
||
| public static String errorJson(String message) throws IOException { | ||
| GenericJson errorResponse = new GenericJson(); | ||
| errorResponse.setFactory(JSON_FACTORY); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
| import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
|
||
| import com.google.api.client.http.HttpTransport; | ||
| import com.google.api.client.http.LowLevelHttpRequest; | ||
|
|
@@ -94,7 +95,7 @@ class DefaultCredentialsProviderTest { | |
| private static final String GDCH_SA_CA_CERT_FILE_NAME = "cert.pem"; | ||
| private static final String GDCH_SA_CA_CERT_PATH = | ||
| GdchCredentialsTest.class.getClassLoader().getResource(GDCH_SA_CA_CERT_FILE_NAME).getPath(); | ||
| private static final URI GDCH_SA_API_AUDIENCE = URI.create("https://gdch-api-audience"); | ||
| private static final String GDCH_SA_API_AUDIENCE = "https://gdch-api-audience"; | ||
| private static final Collection<String> SCOPES = Collections.singletonList("dummy.scope"); | ||
| private static final URI CALL_URI = URI.create("http://googleapis.com/testapi/v1/foo"); | ||
| private static final String QUOTA_PROJECT = "sample-quota-project-id"; | ||
|
|
@@ -180,48 +181,36 @@ void getDefaultCredentials_noCredentials_singleGceTestRequest() { | |
| } | ||
|
|
||
| @Test | ||
| void getDefaultCredentials_noCredentials_linuxNotGce() throws IOException { | ||
| TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); | ||
| testProvider.setProperty("os.name", "Linux"); | ||
| String productFilePath = SMBIOS_PATH_LINUX; | ||
| InputStream productStream = new ByteArrayInputStream("test".getBytes()); | ||
| testProvider.addFile(productFilePath, productStream); | ||
|
|
||
| assertFalse(ComputeEngineCredentials.checkStaticGceDetection(testProvider)); | ||
| void getDefaultCredentials_noCredentials_linuxNotGce() { | ||
| checkStaticGceDetection("Linux", "test", false); | ||
| } | ||
|
|
||
| @Test | ||
| void getDefaultCredentials_static_linux() throws IOException { | ||
| TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); | ||
| testProvider.setProperty("os.name", "Linux"); | ||
| String productFilePath = SMBIOS_PATH_LINUX; | ||
| File productFile = new File(productFilePath); | ||
| InputStream productStream = new ByteArrayInputStream("Googlekdjsfhg".getBytes()); | ||
| testProvider.addFile(productFile.getAbsolutePath(), productStream); | ||
|
|
||
| assertTrue(ComputeEngineCredentials.checkStaticGceDetection(testProvider)); | ||
| void getDefaultCredentials_static_linux() { | ||
| checkStaticGceDetection("Linux", "Googlekdjsfhg", true); | ||
| } | ||
|
|
||
| @Test | ||
| void getDefaultCredentials_static_windows_configuredAsLinux_notGce() throws IOException { | ||
| TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); | ||
| testProvider.setProperty("os.name", "windows"); | ||
| String productFilePath = SMBIOS_PATH_LINUX; | ||
| InputStream productStream = new ByteArrayInputStream("Googlekdjsfhg".getBytes()); | ||
| testProvider.addFile(productFilePath, productStream); | ||
|
|
||
| assertFalse(ComputeEngineCredentials.checkStaticGceDetection(testProvider)); | ||
| void getDefaultCredentials_static_windows_configuredAsLinux_notGce() { | ||
| checkStaticGceDetection("windows", "Googlekdjsfhg", false); | ||
| } | ||
|
|
||
| @Test | ||
| void getDefaultCredentials_static_unsupportedPlatform_notGce() throws IOException { | ||
| void getDefaultCredentials_static_unsupportedPlatform_notGce() { | ||
| checkStaticGceDetection("macos", "Googlekdjsfhg", false); | ||
| } | ||
|
|
||
| private void checkStaticGceDetection(String osName, String productContent, boolean expected) { | ||
| assumeTrue( | ||
| System.getProperty("os.name").toLowerCase().startsWith("linux"), | ||
| "This test only runs on Linux."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if I'm wrong, but I don't think this is the behavior we want. IIUC, this looks like it will only run the test on Linux environments (e.g. our if our CI or local was linux). The original tests was mocking the environment and testing it so that it would mock the os.name value regardless of the CI or local OS. |
||
| TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider(); | ||
| testProvider.setProperty("os.name", "macos"); | ||
| testProvider.setProperty("os.name", osName); | ||
| String productFilePath = SMBIOS_PATH_LINUX; | ||
| InputStream productStream = new ByteArrayInputStream("Googlekdjsfhg".getBytes()); | ||
| InputStream productStream = new ByteArrayInputStream(productContent.getBytes()); | ||
| testProvider.addFile(productFilePath, productStream); | ||
|
|
||
| assertFalse(ComputeEngineCredentials.checkStaticGceDetection(testProvider)); | ||
| assertEquals(expected, ComputeEngineCredentials.checkStaticGceDetection(testProvider)); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that OAuth2Utils and GdchCredentials classes are in the same package, can we make these enums and methods package-private?