|
| 1 | +import * as path from "path" |
| 2 | + |
| 3 | +setupApps({ |
| 4 | + "edge.local": path.resolve(__dirname, "client-certs.edge.js") |
| 5 | +}) |
| 6 | + |
| 7 | +test("client certs pass to server", async () => { |
| 8 | + const response = await fetch("http://edge.local", { |
| 9 | + method: "POST", |
| 10 | + headers: { |
| 11 | + "content-type": "application/json" |
| 12 | + }, |
| 13 | + body: JSON.stringify({ |
| 14 | + cert, |
| 15 | + key, |
| 16 | + ca: [ca] |
| 17 | + }) |
| 18 | + }) |
| 19 | + expect(response.status).toEqual(200) |
| 20 | + expect(await response.text()).toMatch(/SSL Authentication OK!/) |
| 21 | +}) |
| 22 | + |
| 23 | +test("throws on an invalid cert+key", async () => { |
| 24 | + const response = await fetch("http://edge.local", { |
| 25 | + method: "POST", |
| 26 | + headers: { |
| 27 | + "content-type": "application/json" |
| 28 | + }, |
| 29 | + body: JSON.stringify({ |
| 30 | + cert, |
| 31 | + key: "bad-key", |
| 32 | + ca: [ca] |
| 33 | + }) |
| 34 | + }) |
| 35 | + expect(response.status).toEqual(500) |
| 36 | + expect(await response.text()).toMatch(/no start line/) |
| 37 | +}) |
| 38 | + |
| 39 | +const ca = `-----BEGIN CERTIFICATE----- |
| 40 | +MIIFgDCCA2gCCQCLtoAQKfdgizANBgkqhkiG9w0BAQsFADCBgTELMAkGA1UEBhMC |
| 41 | +VVMxCzAJBgNVBAgMAk1BMQ8wDQYDVQQHDAZCb3N0b24xEzARBgNVBAoMCkV4YW1w |
| 42 | +bGUgQ28xEDAOBgNVBAsMB3RlY2hvcHMxCzAJBgNVBAMMAmNhMSAwHgYJKoZIhvcN |
| 43 | +AQkBFhFjZXJ0c0BleGFtcGxlLmNvbTAeFw0xOTAzMTIyMTEzNTVaFw00NjA3Mjcy |
| 44 | +MTEzNTVaMIGBMQswCQYDVQQGEwJVUzELMAkGA1UECAwCTUExDzANBgNVBAcMBkJv |
| 45 | +c3RvbjETMBEGA1UECgwKRXhhbXBsZSBDbzEQMA4GA1U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1Mtxhsgr9dKHW1eWQnFlE7oLnAqictDs |
| 61 | +Pa0tS+H5/YE6g4Ue2ZFr2ksMjjbmhDecrXhoZUWS3b/zl3JNQ/hczw+UNzKuK1AZ |
| 62 | +up+cqe8xKwmTfGxx8iwN2SlCjEAtNu1ioU+PLUi3LRyiAxlbm0ampMGNli0me8BQ |
| 63 | +N3QvFear3gVleTOCXcDOzYlRX76Ied7IXH7xkdEcDUtra5UaLDV/xzOxJOozhlCY |
| 64 | +sKO6fgbVS5gf2gVt3mLVRnVyevsl8P94HhjRsahzmy2tJGD8dCx62EyHyTyscZqX |
| 65 | +p/a+PMoeBb82AHllqcGspqxjv24TIsshA65LZbbDtGxJ1qRqMuKVAkOfTcI+u/1t |
| 66 | +H2OPe8G3F8HX6aCIm4hgKuRXQ5P28PmFNWCQhsyQR/dPQvVMvyNyKJY53yzzByrj |
| 67 | +42IRtl+MYCPQctvsC3Z/2Vfc/xf9Ujpz1OpkMJhmaFw+4PAh1Nbtf9YNdvwopvh7 |
| 68 | ++IG7qjtHvG25zA8ogVoA4gRYk/qdfPQgX8twRBJAiBrlXtRVzlaM7mpWn0+QUzTF |
| 69 | +jNJLqa8fKQgNFs664HWb2od7vZ0= |
| 70 | +-----END CERTIFICATE-----` |
| 71 | + |
| 72 | +const cert = `-----BEGIN CERTIFICATE----- |
| 73 | +MIIFijCCA3KgAwIBAgIJALurjD6W3dJrMA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD |
| 74 | +VQQGEwJVUzELMAkGA1UECAwCTUExDzANBgNVBAcMBkJvc3RvbjETMBEGA1UECgwK |
| 75 | +RXhhbXBsZSBDbzEQMA4GA1UECwwHdGVjaG9wczELMAkGA1UEAwwCY2ExIDAeBgkq |
| 76 | +hkiG9w0BCQEWEWNlcnRzQGV4YW1wbGUuY29tMB4XDTE5MDMxMjIxMTUzM1oXDTIx |
| 77 | +MTIwNTIxMTUzM1owgYYxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNQTEPMA0GA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gOju/ |
| 93 | +tj+jJaVUfsiq7z0hmJFIywRwKEem7mIaCJDykdOttiY8547SRnmR3/44x5PlmgMA |
| 94 | +zQmFYpsZAAShzwE/d9V/tlgG63GqGBXTYlitXcyGLk3ely9skETx1U4A0ZJnXA8d |
| 95 | +CGKsDpp3/T7oPGSna/6T4NW6INm47TuyPeHM859QaDlspsvlP3UlAHbM22p8jLSl |
| 96 | +A1n7TFHtayRU0dBlevrHU+VR6wGpCoSu5CqnkS7uoVgYwemxmOfA4UXnWHFqhD7q |
| 97 | ++nUu6BuHnmJbTJs2vR6VytfcE0IzWE3K5fMhD9zzX8EGuMOu7pQbKbBIwCnin01k |
| 98 | +WRYy3VtyJfGeNwbGRNahyKa5bF1zFPt0jxGeXq+p4MjkkcWS1oRExQjrU3LOzGfT |
| 99 | +JFuvSjAlA3YFhFV9fF1cw5T9uNuOzB7bCYk9uimbRgHEKcyGK02k9zmP14YlxeXN |
| 100 | +B5j7KpYs3shrdQYeF2r0gDLHfDDMXleuvSjS3IIH79v27jJHNVugiob0tI2bMJxi |
| 101 | +Ss1wAbVyLUL8ocgPwHaLNYW6SLI0CrXO0uxP6eDHmaq5msNwtXoJ6dH42BMWSwOp |
| 102 | +T3xf7GOOG9pN3ACBI8FZqfjnxLBcdpVFMGSCoLwP |
| 103 | +-----END CERTIFICATE-----` |
| 104 | + |
| 105 | +const key = `-----BEGIN RSA PRIVATE KEY----- |
| 106 | +MIIJKgIBAAKCAgEA2lSFt720TnMVTX7EXdXh2NcoRN6RhxSYggKwXsZerQ9hEUHS |
| 107 | +qZYO4i6fNXD5zU0R1uOEmzBBkIAx6ALDjXnKAI9lgTiP/xCHhzgGKJUP4/2hwiGU |
| 108 | +sSaLPh6FFV7KxY+QBFis26PiHVM9iyn1LyiVhvN6VFqZwg/LJHHBL6AXmK++Au0k |
| 109 | +QWBRUBPHAfV+6ya3Q14ZhkS9rI3IVJdDKjNDTvmVj0UdOe56M5wuMGlfRH2yGwVh |
| 110 | +C6ANa+zD+G38NODmR5m9+glfALjseAcbFW/9dMEaCMMh9egMmc9VDpydSW1ZCv15 |
| 111 | +XQY29faX7PoYGXjAVtcvw+r32Ra2DveVjYdu93o3U++fqQA44qXazPy7vHeUNule |
| 112 | +ngKbWm3ADku41ayXMzEAod0SdJO2Lv7Fs4l+FeK7jxfcTeM4L1Wxe+qaF0xx1pWb |
| 113 | +ixHrHxjKN5sx3fClBJt5wsda+vHd0qRFjEuLNh0yb2nFiT4avny72+uW4anzEU8H |
| 114 | +PAUgdO6H1Vw1kG3h51U1xICky1Z/bjikUUCMgqf4UQ3CPFcjhhPO/ewAvKV9M8SF |
| 115 | +OiOiBhBK6uwi/TmWDRj3dIuSycPzdA60iC523AqkmsKCc1oxaq6sjNbybvPSvQTL |
| 116 | +HSOa1RL/+HEj4s3iGL3pL/duEhtoWgPZ8ufMIzoq0NXKr+X6T7z4wO2SGdECAwEA |
| 117 | +AQKCAgBYKYlViOUmSJJxmJ7yxUtNpJQ+OyHIyihLV4qgurnAaFVqAopusImSDAF+ |
| 118 | +MwCsRlLN01HY2MOg9iMw7OzKVEOdtknmxFBhTutrTtQtzwN7rQ+EtMq2Pjo7+1cC |
| 119 | +KiT3YeFl3+jtSGAmN1bCu06mnFzFAcyEA5HTK018ifLYqGze2xh/VgMt4xbynwnd |
| 120 | +YKS/kAKw0W69KUTuSNJ8VhhpEgo7+czK7b2/hu0Rqh98rRArOBaTkrh9WUQSMKlx |
| 121 | +x/fv4mEayJpOPTp/sCzMyxHEtlRCsTcyEpnEEtADzBUssVFSNTWfmntHdRr8d3ch |
| 122 | +2lug7YG9j2daVad/ogwiPxfE7st/pIJd59jwKUolmUvmabQez0OqtoN8jyVueuoU |
| 123 | +ayMr5OdHiu5u/QJTE+GEPQ/VjEXy7JB1KYlROyt8R4XWHIVR1PPzyj6GsM8cZNjK |
| 124 | +WPemN4MiCa4ly32GLQjLNzVIQnaqltwSCnC5QRjqsAxuQ4uMocqqguA3TOTFN7sm |
| 125 | +mVhIQI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gt/ |
| 140 | +XnHEPSRonUUKM1i61062ow2POTb2/ZmBnfHrTu33DiCj7VOltzA9BYlpE8urdVfi |
| 141 | +qxmdWQa5dfjhVs5irfmH9zMGxeE5TxtfjWHK+WAyTXOyza318aYH5NZ8RoPQV/71 |
| 142 | +68sVzADwUklVJJ5t+k8Hdli7sSyk6Vvo6j+6DzoaHoXs7+7/nkaqtqr907menRcQ |
| 143 | +oq7c9Qj5Sa5L2TxG+j7qcNUjKOAievRF7uyHc93jhL9TMQmEd4VJ0P/efgiG+s3H |
| 144 | +O12+gQKCAQEA55bChDo2/+OTElm2QKBemLnKeA92W6IdT4iL+41JUT48ki2Iz5wu |
| 145 | +r8ppuSSKoq1pqFFhaOIXzWKE0QjAioRnnAHH5R+av3LWVLrfXFl6PGVsPeTvBetd |
| 146 | +cPtxG48E8cez5ptP52GdFmFCzoemT9Qu59+ihRXpOdXGdvAwDZKBuoyzUDNbUD6W |
| 147 | +OQgTXCMULGeZ/+gNfnnZX1r9ceJYLwB+iRTOTL6VS+6zD1NvFmww9TZMzgdiiIrI |
| 148 | +TpMqKvmeg6QjQmJkfHFdcJ0FYaSMA20jhKp3ra3RsP+rlPp/3KQAETCtV7SffLMS |
| 149 | +m4bgTAadvT1bKSJ+FrOOUXun2+L/skSMgQKCAQEA31Z/I1LzUfFCqEePVHppmQfg |
| 150 | +wLPOxK3oGe6dlQBgi/25eUE9/+Jce4k/K8WnZrktuxV5HwNhnDfFK1Rl5/tQuB8Z |
| 151 | +HrOOeGaA1/o1xNOW/jDWg81SIMaVK31on9Y3SZG0ftn1gqVtyXaLPcA07IjU5Snx |
| 152 | +TuHm3NQAbV0lOBauXrwZOm+EMVzbkqDrBsc1rIWrZamxP0Qt3eZ8C1NLAJNU4HNd |
| 153 | +tfRXvxhIjwe+oZI+1JNJoS/e7XkfXcrC95i60OPIEei99HrxOlQeqFUh2mwUkvy1 |
| 154 | +x6LuLuG1dul6LVbsc50JWaLPK0P9wBQ85enAxJ7joYRmhC0UulvMSomBF/gKtw== |
| 155 | +-----END RSA PRIVATE KEY-----` |
0 commit comments