Skip to content

Commit 9f5bfdc

Browse files
committed
Add tests for hash, query, and auth exceptions
1 parent 724b258 commit 9f5bfdc

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/core/server/http/http_config.test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,40 @@ describe('basePath', () => {
156156
describe('publicBaseUrl', () => {
157157
test('throws if invalid HTTP(S) URL', () => {
158158
const httpSchema = config.schema;
159-
expect(() => httpSchema.validate({ publicBaseUrl: 'myhost.com' })).toThrow();
160-
expect(() => httpSchema.validate({ publicBaseUrl: '//myhost.com' })).toThrow();
161-
expect(() => httpSchema.validate({ publicBaseUrl: 'ftp://myhost.com' })).toThrow();
159+
expect(() =>
160+
httpSchema.validate({ publicBaseUrl: 'myhost.com' })
161+
).toThrowErrorMatchingInlineSnapshot(
162+
`"[publicBaseUrl]: expected URI with scheme [http|https]."`
163+
);
164+
expect(() =>
165+
httpSchema.validate({ publicBaseUrl: '//myhost.com' })
166+
).toThrowErrorMatchingInlineSnapshot(
167+
`"[publicBaseUrl]: expected URI with scheme [http|https]."`
168+
);
169+
expect(() =>
170+
httpSchema.validate({ publicBaseUrl: 'ftp://myhost.com' })
171+
).toThrowErrorMatchingInlineSnapshot(
172+
`"[publicBaseUrl]: expected URI with scheme [http|https]."`
173+
);
174+
});
175+
176+
test('throws if includes hash, query, or auth', () => {
177+
const httpSchema = config.schema;
178+
expect(() =>
179+
httpSchema.validate({ publicBaseUrl: 'http://myhost.com/?a=b' })
180+
).toThrowErrorMatchingInlineSnapshot(
181+
`"[publicBaseUrl] may only contain a protocol, host, port, and pathname"`
182+
);
183+
expect(() =>
184+
httpSchema.validate({ publicBaseUrl: 'http://myhost.com/#a' })
185+
).toThrowErrorMatchingInlineSnapshot(
186+
`"[publicBaseUrl] may only contain a protocol, host, port, and pathname"`
187+
);
188+
expect(() =>
189+
httpSchema.validate({ publicBaseUrl: 'http://user:pass@myhost.com' })
190+
).toThrowErrorMatchingInlineSnapshot(
191+
`"[publicBaseUrl] may only contain a protocol, host, port, and pathname"`
192+
);
162193
});
163194

164195
test('throws if basePath and publicBaseUrl are specified, but do not match', () => {

0 commit comments

Comments
 (0)