Skip to content

Commit

Permalink
test: add test for credentrial detection in protocol agnistic url
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Nov 8, 2024
1 parent 2cba1bc commit 069a070
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
15 changes: 1 addition & 14 deletions packages/fetch-mock/src/__tests__/FetchMock/routing.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import fetchMock from '../../FetchMock';

describe('Routing', () => {
Expand Down Expand Up @@ -250,17 +250,4 @@ describe('Routing', () => {
expect(res.status).toEqual(200);
});
});

describe('relative routes', () => {
beforeEach(() => {
fm.config.allowRelativeUrls = true;
});
afterEach(() => {
fm.config.allowRelativeUrls = false;
});
it('allows handling relative routes', async () => {
fm.route('/relative/path', 200);
await fm.fetchHandler('/relative/path');
});
});
});
9 changes: 9 additions & 0 deletions packages/fetch-mock/src/__tests__/spec-compliance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ describe('Spec compliance', () => {
),
);
});
it('rejects on protocol agnostic url containing credentials', async () => {
await expect(
fetchMock.fetchHandler('//user:password@a.com'),
).rejects.toThrow(
new TypeError(
'Request cannot be constructed from a URL that includes credentials: //user:password@a.com/',
),
);
});
it('reject if the request method is GET or HEAD and the body is non-null.', async () => {
await expect(
fetchMock.fetchHandler('http://a.com', { body: 'a' }),
Expand Down

0 comments on commit 069a070

Please sign in to comment.