|
5 | 5 | CLIENT_CERT_ALERT, |
6 | 6 | CLIENT_CERT_MESSAGES, |
7 | 7 | } from "@/error/clientCertificateError"; |
| 8 | +import { CrossOriginRedirectError } from "@/error/crossOriginRedirectError"; |
8 | 9 |
|
9 | 10 | type AlertName = keyof typeof CLIENT_CERT_ALERT; |
10 | 11 | type AlertTestCase = [AlertName, string]; |
@@ -40,18 +41,42 @@ describe("ClientCertificateError.fromError", () => { |
40 | 41 | }); |
41 | 42 | }); |
42 | 43 |
|
43 | | - describe("lowercase patterns", () => { |
| 44 | + describe("OpenSSL text patterns", () => { |
44 | 45 | it.each<LowercaseTestCase>([ |
45 | | - ["certificate_expired", CLIENT_CERT_ALERT.CERTIFICATE_EXPIRED], |
46 | | - ["bad_certificate", CLIENT_CERT_ALERT.BAD_CERTIFICATE], |
47 | | - ["unknown_ca", CLIENT_CERT_ALERT.UNKNOWN_CA], |
| 46 | + [ |
| 47 | + "sslv3 alert certificate expired", |
| 48 | + CLIENT_CERT_ALERT.CERTIFICATE_EXPIRED, |
| 49 | + ], |
| 50 | + ["sslv3 alert bad certificate", CLIENT_CERT_ALERT.BAD_CERTIFICATE], |
| 51 | + ["tlsv1 alert unknown ca", CLIENT_CERT_ALERT.UNKNOWN_CA], |
48 | 52 | ])("should detect %s", (pattern, expectedCode) => { |
49 | 53 | const certError = ClientCertificateError.fromError( |
50 | | - new Error(`SSL error: ${pattern}`), |
| 54 | + new Error(`SSL routines:ssl3_read_bytes:${pattern}`), |
51 | 55 | ); |
52 | 56 | expect(certError).toBeDefined(); |
53 | 57 | expect(certError!.alertCode).toBe(expectedCode); |
54 | 58 | }); |
| 59 | + |
| 60 | + it("should ignore an alert name outside an alert", () => { |
| 61 | + expect( |
| 62 | + ClientCertificateError.fromError( |
| 63 | + new Error("getaddrinfo ENOTFOUND certificate_expired.example.com"), |
| 64 | + ), |
| 65 | + ).toBeUndefined(); |
| 66 | + }); |
| 67 | + |
| 68 | + it("should ignore a refused redirect, whose hostname the deployment picks", () => { |
| 69 | + const redirect = new CrossOriginRedirectError( |
| 70 | + "https://sslv3_alert_certificate_expired.example.com/", |
| 71 | + ); |
| 72 | + expect( |
| 73 | + ClientCertificateError.fromError( |
| 74 | + new Error(`Redirected request failed: ${redirect.message}`, { |
| 75 | + cause: redirect, |
| 76 | + }), |
| 77 | + ), |
| 78 | + ).toBeUndefined(); |
| 79 | + }); |
55 | 80 | }); |
56 | 81 |
|
57 | 82 | describe("SSL alert number fallback", () => { |
|
0 commit comments