File size: 2,940 Bytes
bf48b89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | import { describe, expect, it } from 'vitest';
import pacProxy from '@/utils/proxy/pac-proxy';
const emptyProxyObj = {
protocol: undefined,
host: undefined,
port: undefined,
auth: undefined,
url_regex: '.*',
};
const effectiveExpect = ({ proxyUri, proxyObj }, expectUri, expectObj) => {
expect(proxyUri).toBe(expectUri);
expect(proxyObj).toEqual(expectObj);
};
describe('pac-proxy', () => {
const nullExpect = (pac) => effectiveExpect(pac, undefined, emptyProxyObj);
it('pac empty', () => {
nullExpect(pacProxy('', '', emptyProxyObj));
});
it('pac-uri invalid', () => {
nullExpect(pacProxy('http://inv ild.test', '', emptyProxyObj));
});
it('pac-uri invalid protocol', () => {
nullExpect(pacProxy('socks://rsshub.proxy', '', emptyProxyObj));
});
const httpUri = 'http://rsshub.proxy/pac.pac';
it('pac-uri http', () => {
effectiveExpect(pacProxy(httpUri, '', emptyProxyObj), httpUri, emptyProxyObj);
});
const httpsUri = 'https://rsshub.proxy/pac.pac';
it('pac-uri https', () => {
effectiveExpect(pacProxy(httpsUri, '', emptyProxyObj), httpsUri, emptyProxyObj);
});
const ftpUri = 'ftp://rsshub.proxy:2333';
it('pac-uri ftp', () => {
effectiveExpect(pacProxy(ftpUri, '', emptyProxyObj), ftpUri, emptyProxyObj);
});
const fileUri = 'file:///path/to/pac.pac';
it('pac-uri file', () => {
effectiveExpect(pacProxy(fileUri, '', emptyProxyObj), fileUri, emptyProxyObj);
});
const dataPacScript = "function FindProxyForURL(url, host){return 'DIRECT';}";
const dataUri = 'data:text/javascript;charset=utf-8,' + encodeURIComponent(dataPacScript);
it('pac-script data', () => {
effectiveExpect(pacProxy('', dataPacScript, emptyProxyObj), dataUri, emptyProxyObj);
});
const httpsObj = { ...emptyProxyObj, protocol: 'https', host: 'rsshub.proxy', port: '2333' };
const httpsAuthUri = 'https://user:pass@rsshub.proxy:2333';
it('pac-uri https auth', () => {
effectiveExpect(pacProxy(httpsAuthUri, '', emptyProxyObj), httpsAuthUri, httpsObj);
});
const httpsAuthObj = { ...httpsObj, auth: 'testtest' };
it('pac proxy-obj https auth', () => {
effectiveExpect(pacProxy(httpsUri, '', httpsAuthObj), httpsUri, httpsAuthObj);
});
const ftpObj = { ...httpsObj, protocol: 'ftp' };
const ftpAuthUri = 'ftp://user:pass@rsshub.proxy:2333';
it('pac-uri ftp auth', () => {
effectiveExpect(pacProxy(ftpAuthUri, '', emptyProxyObj), ftpAuthUri, ftpObj);
});
const ftpAuthObj = { ...ftpObj, auth: 'testtest' };
it('pac-uri ftp auth (invalid)', () => {
effectiveExpect(pacProxy(ftpUri, '', ftpAuthObj), ftpUri, ftpObj);
});
it('pac-uri user@pass override proxy-obj auth', () => {
effectiveExpect(pacProxy(httpsAuthUri, '', httpsAuthObj), httpsAuthUri, httpsObj);
});
});
|