camo: support URL encoding option
This commit is contained in:
parent
54045766f2
commit
486ce04a3e
6 changed files with 56 additions and 4 deletions
17
test/camo.js
17
test/camo.js
|
|
@ -7,7 +7,8 @@ describe('Camo', () => {
|
|||
camo: {
|
||||
server: 'http://localhost:8081',
|
||||
key: '9LKC7708ZHOVRCTLOLE3G2YJ0U1T8F96',
|
||||
'whitelisted-domains': ['def.xyz']
|
||||
'whitelisted-domains': ['def.xyz'],
|
||||
encoding: 'hex'
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -17,6 +18,20 @@ describe('Camo', () => {
|
|||
assert.strictEqual(result, 'http://localhost:8081/a9c295dd7d8dcbc8247dec97ac5d9b4ee8baeb31/687474703a2f2f6162632e78797a2f696d6167652e6a706567');
|
||||
});
|
||||
|
||||
it('constructs a camo url using url encoding', () => {
|
||||
const config = new CamoConfig({
|
||||
camo: {
|
||||
server: 'http://localhost:8081',
|
||||
key: '9LKC7708ZHOVRCTLOLE3G2YJ0U1T8F96',
|
||||
'whitelisted-domains': ['def.xyz'],
|
||||
encoding: 'url'
|
||||
}
|
||||
});
|
||||
|
||||
const result = Camo.camoify(config, 'http://abc.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'http://localhost:8081/a9c295dd7d8dcbc8247dec97ac5d9b4ee8baeb31?url=http%3A%2F%2Fabc.xyz%2Fimage.jpeg');
|
||||
});
|
||||
|
||||
it('bypasses camo for whitelisted domains', () => {
|
||||
const result = Camo.camoify(config, 'http://def.xyz/image.jpeg');
|
||||
assert.strictEqual(result, 'https://def.xyz/image.jpeg');
|
||||
|
|
|
|||
|
|
@ -15,6 +15,17 @@ describe('CamoConfig', () => {
|
|||
it('defaults to enabled=false', () => {
|
||||
assert.strictEqual(new CamoConfig().isEnabled(), false);
|
||||
});
|
||||
|
||||
it('validates that encoding must be either url or hex', () => {
|
||||
|
||||
assert.throws(() => {
|
||||
new CamoConfig({
|
||||
camo: {
|
||||
encoding: 'asdjfnasdf'
|
||||
}
|
||||
});
|
||||
}, /must be either 'url' or 'hex'/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getWhitelistedDomains', () => {
|
||||
|
|
@ -22,4 +33,10 @@ describe('CamoConfig', () => {
|
|||
assert.deepStrictEqual(new CamoConfig().getWhitelistedDomains(), []);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getEncoding', () => {
|
||||
it('defaults to url', () => {
|
||||
assert.deepStrictEqual(new CamoConfig().getEncoding(), 'url');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue