Skip to content

Commit

Permalink
test: add test for invalid cookie url (#18751)
Browse files Browse the repository at this point in the history
Co-Authored-By: Erick Zhao <erick@hotmail.ca>
  • Loading branch information
2 people authored and codebytere committed Jun 13, 2019
1 parent ba96cdb commit ddec3c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/api/cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ the response.
#### `cookies.set(details)`

* `details` Object
* `url` String - The url to associate the cookie with.
* `url` String - The url to associate the cookie with. An error is thrown if the url is invalid.
* `name` String (optional) - The name of the cookie. Empty by default if omitted.
* `value` String (optional) - The value of the cookie. Empty by default if omitted.
* `domain` String (optional) - The domain of the cookie; this will be normalized with a preceding dot so that it's also valid for subdomains. Empty by default if omitted.
Expand Down
23 changes: 17 additions & 6 deletions spec-main/api-session-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,23 @@ describe('session module', () => {
})

it('yields an error when setting a cookie with missing required fields', async () => {
await expect((async () => {
const { cookies } = session.defaultSession
const name = '1'
const value = '1'
await cookies.set({ url: '', name, value })
})()).to.eventually.be.rejectedWith('Failed to get cookie domain')
const { cookies } = session.defaultSession
const name = '1'
const value = '1'

await expect(
cookies.set({ url: '', name, value })
).to.eventually.be.rejectedWith('Failed to get cookie domain')
})

it('yields an error when setting a cookie with an invalid URL', async () => {
const { cookies } = session.defaultSession
const name = '1'
const value = '1'

await expect(
cookies.set({ url: 'asdf', name, value })
).to.eventually.be.rejectedWith('Failed to get cookie domain')
})

it('should overwrite previous cookies', async () => {
Expand Down

0 comments on commit ddec3c0

Please sign in to comment.