-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
590fe7b
commit 9df2a4a
Showing
1 changed file
with
41 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -135,7 +135,8 @@ test('isURLPotentiallyTrustworthy', (t) => { | |
}) | ||
|
||
test('determineRequestsReferrer', (t) => { | ||
t.plan(4) | ||
t.plan(7) | ||
|
||
t.test('Should handle empty referrerPolicy', (tt) => { | ||
tt.plan(2) | ||
tt.equal(util.determineRequestsReferrer({}), 'no-referrer') | ||
|
@@ -169,4 +170,43 @@ test('determineRequestsReferrer', (t) => { | |
}), 'no-referrer') | ||
} | ||
}) | ||
|
||
t.test('Should return "no-referrer" if the request referrer is neither client nor instance of URL', (tt) => { | ||
tt.plan(4) | ||
const requests = [ | ||
{ referrerPolicy: 'origin', referrer: 'string' }, | ||
{ referrerPolicy: 'origin', referrer: null }, | ||
{ referrerPolicy: 'origin', referrer: undefined }, | ||
{ referrerPolicy: 'origin', referrer: '' } | ||
] | ||
|
||
for (const request of requests) { | ||
tt.equal(util.determineRequestsReferrer(request), 'no-referrer') | ||
} | ||
}) | ||
|
||
t.test('Should return referrer origin on referrerPolicy origin', (tt) => { | ||
tt.plan(1) | ||
const expectedRequest = { | ||
referrerPolicy: 'origin', | ||
referrer: new URL('http://example:[email protected]') | ||
} | ||
|
||
tt.equal(util.determineRequestsReferrer(expectedRequest), expectedRequest.referrer.origin) | ||
}) | ||
|
||
t.test('Should return referrer url on referrerPolicy unsafe-url', (tt) => { | ||
tt.plan(1) | ||
const expectedRequest = { | ||
referrerPolicy: 'unsafe-url', | ||
referrer: new URL('http://example:[email protected]/hello/world') | ||
} | ||
|
||
const expectedReffererUrl = new URL(expectedRequest.referrer.href) | ||
|
||
expectedReffererUrl.username = '' | ||
expectedReffererUrl.password = '' | ||
|
||
tt.equal(util.determineRequestsReferrer(expectedRequest), expectedReffererUrl.href) | ||
}) | ||
}) |