camo: include subdomains of whitelisted domains in whitelist
This commit is contained in:
parent
07179d6c83
commit
637bcad816
5 changed files with 53 additions and 4 deletions
24
test/camo.js
24
test/camo.js
|
|
@ -7,7 +7,7 @@ describe('Camo', () => {
|
|||
camo: {
|
||||
server: 'http://localhost:8081',
|
||||
key: '9LKC7708ZHOVRCTLOLE3G2YJ0U1T8F96',
|
||||
'whitelisted-domains': ['def.xyz'],
|
||||
'whitelisted-domains': ['def.xyz', 'tii.kzz.qqq'],
|
||||
encoding: 'hex'
|
||||
}
|
||||
});
|
||||
|
|
@ -36,6 +36,28 @@ describe('Camo', () => {
|
|||
const result = Camo.camoify(config, 'http://def.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'https://def.xyz/image.jpeg');
|
||||
});
|
||||
|
||||
it('bypasses camo for whitelisted domains subdomains', () => {
|
||||
const result = Camo.camoify(config, 'http://abc.def.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'https://abc.def.xyz/image.jpeg');
|
||||
});
|
||||
|
||||
it('does not bypass camo for a non-subdomain match', () => {
|
||||
const result = Camo.camoify(config, 'http://abcdef.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'http://localhost:8081/19f53f65e8081a064cff54fbd665e8bb08612aa6/687474703a2f2f6162636465662e78797a2f696d6167652e6a706567');
|
||||
});
|
||||
|
||||
it('does not bypass camo when no whitelist is configured', () => {
|
||||
const config = new CamoConfig({
|
||||
camo: {
|
||||
server: 'http://localhost:8081',
|
||||
key: '9LKC7708ZHOVRCTLOLE3G2YJ0U1T8F96',
|
||||
encoding: 'hex'
|
||||
}
|
||||
});
|
||||
const result = Camo.camoify(config, 'http://abcdef.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'http://localhost:8081/19f53f65e8081a064cff54fbd665e8bb08612aa6/687474703a2f2f6162636465662e78797a2f696d6167652e6a706567');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#transformImgTags', () => {
|
||||
|
|
|
|||
|
|
@ -39,4 +39,18 @@ describe('CamoConfig', () => {
|
|||
assert.deepStrictEqual(new CamoConfig().getEncoding(), 'url');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getWhitelistedDomainsRegexp', () => {
|
||||
it('generates a regex based on the whitelisted domains', () => {
|
||||
const config = new CamoConfig({
|
||||
camo: {
|
||||
server: 'localhost:8081',
|
||||
'whitelisted-domains': ['abc.xyz', 'tii.kzz.qqq']
|
||||
}
|
||||
});
|
||||
|
||||
const re = config.getWhitelistedDomainsRegexp();
|
||||
assert.deepStrictEqual(re, /\.abc\.xyz$|\.tii\.kzz\.qqq$/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue