|
38 | 38 |
|
39 | 39 | import com.google.auth.oauth2.SystemPropertyProvider; |
40 | 40 | import com.google.auth.oauth2.TestEnvironmentProvider; |
| 41 | +import com.google.auth.oauth2.TestPropertyProvider; |
41 | 42 | import java.io.File; |
42 | 43 | import java.io.FileInputStream; |
43 | 44 | import java.io.IOException; |
@@ -136,4 +137,36 @@ void x509Provider_succeeds_withWellKnownPath() |
136 | 137 | assertEquals(1, store.size()); |
137 | 138 | assertNotNull(store.getCertificateAlias(expectedCert)); |
138 | 139 | } |
| 140 | + |
| 141 | + @Test |
| 142 | + void x509Provider_succeeds_withWindowsPath() |
| 143 | + throws IOException, KeyStoreException, CertificateException { |
| 144 | + Path windowsTempDir = Files.createTempDirectory("windowsTempDir"); |
| 145 | + windowsTempDir.toFile().deleteOnExit(); |
| 146 | + Path gcloudDir = windowsTempDir.resolve("gcloud"); |
| 147 | + Files.createDirectory(gcloudDir); |
| 148 | + Path configPath = gcloudDir.resolve("certificate_config.json"); |
| 149 | + |
| 150 | + // Copy the valid config to this new temp location |
| 151 | + Files.copy(new File(TEST_CONFIG_PATH).toPath(), configPath); |
| 152 | + |
| 153 | + TestEnvironmentProvider envProvider = new TestEnvironmentProvider(); |
| 154 | + envProvider.setEnv("APPDATA", windowsTempDir.toString()); |
| 155 | + |
| 156 | + TestPropertyProvider propProvider = new TestPropertyProvider(); |
| 157 | + propProvider.setProperty("os.name", "Windows 10"); |
| 158 | + |
| 159 | + X509Provider testProvider = new X509Provider(envProvider, propProvider, null); |
| 160 | + |
| 161 | + CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
| 162 | + Certificate expectedCert; |
| 163 | + try (FileInputStream fis = new FileInputStream(new File(TEST_CERT_PATH))) { |
| 164 | + expectedCert = cf.generateCertificate(fis); |
| 165 | + } |
| 166 | + |
| 167 | + KeyStore store = testProvider.getKeyStore(); |
| 168 | + assertEquals(1, store.size()); |
| 169 | + assertNotNull(store.getCertificateAlias(expectedCert)); |
| 170 | + } |
139 | 171 | } |
| 172 | + |
0 commit comments