Skip to content
Permalink
Browse files

Fix: Check target is `file://` in connector-local

Fix #3363
Close #3370
  • Loading branch information
sarvaje authored and molant committed Nov 21, 2019
1 parent 910c381 commit 56542567a943e5a14cec070e1fe765f77433bcf2
Showing with 19 additions and 1 deletion.
  1. +4 −0 packages/connector-local/src/connector.ts
  2. +15 −1 packages/connector-local/tests/tests.ts
@@ -385,6 +385,10 @@ export default class LocalConnector implements IConnector {
}

public async collect(target: URL, options?: IFetchOptions) {
if (target.protocol !== 'file:') {
throw new Error('Connector local only works with local files or directories');
}

/** The target in string format */
const href: string = this._href = target.href;
const initialEvent: Event = { resource: href };
@@ -53,7 +53,7 @@ const mockContext = (context: SandboxContext) => {
const cwdStub = context.sandbox.stub(fsMocks, 'cwd');
const isFileStub = context.sandbox.stub(fsMocks, 'isFile');

const script = proxyquire('../src/connector', {
const script: typeof import('../src/connector') = proxyquire('../src/connector', {
'@hint/utils': { logger },
'@hint/utils-fs': {
cwd: cwdStub,
@@ -553,3 +553,17 @@ test(`When the watcher get an error, it should throw an error`, async (t) => {
t.is(err, 'Error!');
}
});

test('If target is a not a file, it should throw and exception', async (t) => {
const { engine, LocalConnector } = mockContext(t.context);

const connector = new LocalConnector(engine as any, {});

t.plan(1);

try {
await connector.collect(new URL('https://example.com'));
} catch (err) {
t.is(err.message, 'Connector local only works with local files or directories');
}
});

0 comments on commit 5654256

Please sign in to comment.
You can’t perform that action at this time.