Browse Source

test: add test for invalid cookie url (#18751)

Co-Authored-By: Erick Zhao <[email protected]>
Micha Hanselmann 5 years ago
parent
commit
ddec3c0e78
2 changed files with 18 additions and 7 deletions
  1. 1 1
      docs/api/cookies.md
  2. 17 6
      spec-main/api-session-spec.js

+ 1 - 1
docs/api/cookies.md

@@ -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.

+ 17 - 6
spec-main/api-session-spec.js

@@ -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 () => {