Skip to content

Commit

Permalink
Add a test for case with specified "domain"
Browse files Browse the repository at this point in the history
Log a message if "domainValue" is specified and cookie name has "__Host-" prefix
  • Loading branch information
AdamWr committed Sep 5, 2024
1 parent 563a36f commit 9953375
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/helpers/cookie-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export const serializeCookie = (
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#attributes
// https://github.com/AdguardTeam/Scriptlets/issues/448
resultCookie += '; path=/; secure';
if (domainValue) {
// eslint-disable-next-line no-console
console.debug(
`Domain value: "${domainValue}" has been ignored, because is not allowed for __Host- prefixed cookies`,
);
}
return resultCookie;
}
const path = getCookiePath(rawPath);
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/cookie-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('serializeCookie', () => {
actual: ['__Host-prefix', 'host_prefix', ''],
expected: '__Host-prefix=host_prefix; path=/; secure',
},
{
actual: ['__Host-prefix_domain', 'host_prefix_domain', '', 'example.com'],
expected: '__Host-prefix_domain=host_prefix_domain; path=/; secure',
},
{
actual: ['__Secure-prefix', 'secure_prefix', ''],
expected: '__Secure-prefix=secure_prefix; secure',
Expand Down

0 comments on commit 9953375

Please sign in to comment.