Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for concatCookieNameValuePath()
- Loading branch information
1 parent
74fe7d1
commit 2e334e4
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { concatCookieNameValuePath } from '../../src/helpers/cookie-utils'; | ||
|
||
describe('concatCookieNameValuePath', () => { | ||
describe('encode cookie value', () => { | ||
test.each([ | ||
{ | ||
actual: ['name', 'value', ''], | ||
expected: 'name=value;', | ||
}, | ||
{ | ||
actual: ['name', 'value', '/'], | ||
expected: 'name=value; path=/', | ||
}, | ||
{ | ||
actual: ['pop::138', '138', ''], | ||
// do not encode cookie name | ||
// https://github.com/AdguardTeam/Scriptlets/issues/408 | ||
expected: 'pop::138=138;', | ||
}, | ||
{ | ||
actual: ['aa::bb::cc', '1', ''], | ||
expected: 'aa::bb::cc=1;', | ||
}, | ||
// invalid path | ||
{ | ||
actual: ['name', 'value', '/docs'], | ||
// no path is set if unsupported path values passed | ||
expected: 'name=value;', | ||
}, | ||
// invalid name because of ';' | ||
{ | ||
actual: ['a;bc', 'def', ''], | ||
expected: null, | ||
}, | ||
// value with ';' but it should be encoded so its ok | ||
{ | ||
actual: ['abc', 'de;f', ''], | ||
expected: 'abc=de%3Bf;', | ||
}, | ||
])('$actual -> $expected', ({ actual, expected }) => { | ||
expect(concatCookieNameValuePath(...actual)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('no cookie value encoding', () => { | ||
test.each([ | ||
{ | ||
actual: ['name', 'value', ''], | ||
expected: 'name=value;', | ||
}, | ||
{ | ||
actual: ['aa::bb::cc', '1', ''], | ||
expected: 'aa::bb::cc=1;', | ||
}, | ||
{ | ||
actual: ['__w_cc11', '{%22cookies_statistical%22:false%2C%22cookies_ad%22:true}', ''], | ||
// do not encode cookie value | ||
// https://github.com/AdguardTeam/Scriptlets/issues/311 | ||
expected: '__w_cc11={%22cookies_statistical%22:false%2C%22cookies_ad%22:true};', | ||
}, | ||
// invalid name because of ';' | ||
{ | ||
actual: ['a;bc', 'def', ''], | ||
expected: null, | ||
}, | ||
// invalid value because of ';' and it is not being encoded | ||
{ | ||
actual: ['abc', 'de;f', ''], | ||
expected: null, | ||
}, | ||
])('$actual -> $expected', ({ actual, expected }) => { | ||
// explicit 'false' to disable encoding | ||
expect(concatCookieNameValuePath(...actual, false)).toBe(expected); | ||
}); | ||
}); | ||
}); |