| ... | ... | @@ -59,6 +59,70 @@ describe("remote", () => { |
| 59 | 59 | }); |
| 60 | 60 | }); |
| 61 | 61 | |
| 62 | it("treats a protocol-relative host as https", () => { |
| 63 | expect( |
| 64 | resolveRemotePairingTarget({ |
| 65 | host: "//remote.example.com", |
| 66 | pairingCode: "pairing-token", |
| 67 | }), |
| 68 | ).toEqual({ |
| 69 | credential: "pairing-token", |
| 70 | httpBaseUrl: "https://remote.example.com/", |
| 71 | wsBaseUrl: "wss://remote.example.com/", |
| 72 | }); |
| 73 | }); |
| 74 | |
| 75 | it("preserves the port when normalizing a protocol-relative host", () => { |
| 76 | expect( |
| 77 | resolveRemotePairingTarget({ |
| 78 | host: "//remote.example.com:3000", |
| 79 | pairingCode: "pairing-token", |
| 80 | }), |
| 81 | ).toEqual({ |
| 82 | credential: "pairing-token", |
| 83 | httpBaseUrl: "https://remote.example.com:3000/", |
| 84 | wsBaseUrl: "wss://remote.example.com:3000/", |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | it("normalizes a protocol-relative host from a hosted pairing link", () => { |
| 89 | expect( |
| 90 | resolveRemotePairingTarget({ |
| 91 | pairingUrl: "https://app.t3.codes/pair?host=%2F%2Fremote.example.com#token=pairing-token", |
| 92 | }), |
| 93 | ).toEqual({ |
| 94 | credential: "pairing-token", |
| 95 | httpBaseUrl: "https://remote.example.com/", |
| 96 | wsBaseUrl: "wss://remote.example.com/", |
| 97 | }); |
| 98 | }); |
| 99 | |
| 100 | it("collapses extra leading slashes instead of producing an empty host", () => { |
| 101 | expect( |
| 102 | resolveRemotePairingTarget({ |
| 103 | host: "///example.com", |
| 104 | pairingCode: "pairing-token", |
| 105 | }), |
| 106 | ).toEqual({ |
| 107 | credential: "pairing-token", |
| 108 | httpBaseUrl: "https://example.com/", |
| 109 | wsBaseUrl: "wss://example.com/", |
| 110 | }); |
| 111 | }); |
| 112 | |
| 113 | it("does not double-prepend https when the host already carries a scheme", () => { |
| 114 | expect( |
| 115 | resolveRemotePairingTarget({ |
| 116 | host: "//https://example.com", |
| 117 | pairingCode: "pairing-token", |
| 118 | }), |
| 119 | ).toEqual({ |
| 120 | credential: "pairing-token", |
| 121 | httpBaseUrl: "https://example.com/", |
| 122 | wsBaseUrl: "wss://example.com/", |
| 123 | }); |
| 124 | }); |
| 125 | |
| 62 | 126 | it("preserves host ports when normalizing a bare host input", () => { |
| 63 | 127 | expect( |
| 64 | 128 | resolveRemotePairingTarget({ |