|
21 | 21 |
|
22 | 22 | import com.google.api.client.auth.openidconnect.IdToken; |
23 | 23 | import com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager; |
| 24 | +import com.google.api.client.http.LowLevelHttpRequest; |
24 | 25 | import com.google.api.client.json.JsonFactory; |
25 | 26 | import com.google.api.client.json.gson.GsonFactory; |
26 | 27 | import com.google.api.client.json.webtoken.JsonWebSignature; |
|
31 | 32 | import com.google.api.client.testing.http.MockHttpTransport; |
32 | 33 | import com.google.api.client.testing.http.MockLowLevelHttpResponse; |
33 | 34 | import com.google.common.io.BaseEncoding; |
| 35 | +import com.google.firebase.auth.FirebaseAuthException; |
34 | 36 | import com.google.firebase.auth.FirebaseToken; |
35 | 37 | import com.google.firebase.auth.TestOnlyImplFirebaseAuthTrampolines; |
36 | 38 | import com.google.firebase.testing.ServiceAccount; |
|
42 | 44 | import java.security.spec.InvalidKeySpecException; |
43 | 45 | import java.security.spec.KeySpec; |
44 | 46 | import java.security.spec.PKCS8EncodedKeySpec; |
| 47 | +import org.junit.Assert; |
45 | 48 | import org.junit.Before; |
46 | 49 | import org.junit.Rule; |
47 | 50 | import org.junit.Test; |
@@ -265,6 +268,36 @@ public void verifyTokenFailure_WrongCert() throws Exception { |
265 | 268 | verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token)); |
266 | 269 | } |
267 | 270 |
|
| 271 | + @Test |
| 272 | + public void verifyTokenCertificateError() throws Exception { |
| 273 | + FirebaseToken token = |
| 274 | + TestOnlyImplFirebaseAuthTrampolines.parseToken( |
| 275 | + FACTORY, createToken(createHeader(), createPayload())); |
| 276 | + |
| 277 | + MockHttpTransport mockTransport = new MockHttpTransport() { |
| 278 | + @Override |
| 279 | + public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { |
| 280 | + throw new IOException("Expected error"); |
| 281 | + } |
| 282 | + }; |
| 283 | + FirebaseTokenVerifier verifier = new FirebaseTokenVerifier.Builder() |
| 284 | + .setClock(CLOCK) |
| 285 | + .setPublicKeysManager( |
| 286 | + new GooglePublicKeysManager.Builder(mockTransport, FACTORY) |
| 287 | + .setClock(CLOCK) |
| 288 | + .setPublicCertsEncodedUrl(FirebaseTokenVerifier.CLIENT_CERT_URL) |
| 289 | + .build()) |
| 290 | + .setProjectId(PROJECT_ID) |
| 291 | + .build(); |
| 292 | + try { |
| 293 | + verifier.verifyTokenAndSignature(TestOnlyImplFirebaseAuthTrampolines.getToken(token)); |
| 294 | + Assert.fail("No exception thrown"); |
| 295 | + } catch (FirebaseAuthException expected) { |
| 296 | + assertTrue(expected.getCause() instanceof IOException); |
| 297 | + assertEquals("Expected error", expected.getCause().getMessage()); |
| 298 | + } |
| 299 | + } |
| 300 | + |
268 | 301 | @Test |
269 | 302 | public void legacyCustomToken() throws Exception { |
270 | 303 | initCrypto(ServiceAccount.OWNER.getPrivateKey(), ServiceAccount.NONE.getCert()); |
|
0 commit comments