|
5 | 5 | RemoteBackendUrlMissingError, |
6 | 6 | RemotePairingTokenMissingError, |
7 | 7 | RemotePairingUrlInvalidError, |
| 8 | + normalizePairingCode, |
8 | 9 | resolveRemotePairingTarget, |
9 | 10 | } from "./remote.ts"; |
10 | 11 |
|
@@ -200,6 +201,29 @@ describe("remote", () => { |
200 | 201 | ); |
201 | 202 | }); |
202 | 203 |
|
| 204 | + it("repairs a hand-typed pairing code whatever spacing or case it arrived in", () => { |
| 205 | + for (const typed of ["abcd2345efgh", "ABCD-2345-EFGH", "abcd 2345 efgh", " AbCd-2345 EfGh "]) { |
| 206 | + expect(normalizePairingCode(typed.trim())).toBe("ABCD2345EFGH"); |
| 207 | + } |
| 208 | + }); |
| 209 | + |
| 210 | + it("does not normalize a token that came out of a pairing URL", () => { |
| 211 | + // Hosted tokens are issued elsewhere, are not drawn from the uppercase |
| 212 | + // pairing alphabet, and reach resolveRemotePairingTarget through the same |
| 213 | + // pairingCode field - so the normalizer must stay out of this path. |
| 214 | + expect( |
| 215 | + resolveRemotePairingTarget({ |
| 216 | + pairingUrl: "https://remote.example.com/pair#token=MiXeD-case_token", |
| 217 | + }).credential, |
| 218 | + ).toBe("MiXeD-case_token"); |
| 219 | + expect( |
| 220 | + resolveRemotePairingTarget({ |
| 221 | + host: "https://remote.example.com", |
| 222 | + pairingCode: "MiXeD-case_token", |
| 223 | + }).credential, |
| 224 | + ).toBe("MiXeD-case_token"); |
| 225 | + }); |
| 226 | + |
203 | 227 | it("preserves URL parsing causes with their input source", () => { |
204 | 228 | let pairingUrlError: unknown; |
205 | 229 | try { |
|
0 commit comments