|
1 | 1 | /* |
2 | | - * Copyright (c) 2021-2024, FusionAuth, All Rights Reserved |
| 2 | + * Copyright (c) 2021-2025, FusionAuth, All Rights Reserved |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
36 | 36 | import static org.testng.Assert.assertNull; |
37 | 37 | import static org.testng.Assert.assertTrue; |
38 | 38 |
|
| 39 | +/** |
| 40 | + * @author Brian Pontarelli |
| 41 | + */ |
39 | 42 | public class CookieTest extends BaseTest { |
40 | 43 | @Test |
41 | 44 | public void cookieInjection() throws Exception { |
@@ -305,6 +308,41 @@ public void fromResponseHeader() { |
305 | 308 | // Borked cookie |
306 | 309 | cookie = Cookie.fromResponseHeader("=a"); |
307 | 310 | assertNull(cookie); |
| 311 | + |
| 312 | + // additional attributes |
| 313 | + // - name and value |
| 314 | + cookie = Cookie.fromResponseHeader("foo=;utm=123"); |
| 315 | + assertEquals(cookie.name, "foo"); |
| 316 | + assertEquals(cookie.getAttribute("utm"), "123"); |
| 317 | + |
| 318 | + // additional attributes |
| 319 | + // - name, sep but no value |
| 320 | + cookie = Cookie.fromResponseHeader("foo=;utm="); |
| 321 | + assertEquals(cookie.name, "foo"); |
| 322 | + assertEquals(cookie.getAttribute("utm"), ""); |
| 323 | + |
| 324 | + // additional attributes |
| 325 | + // - name only |
| 326 | + cookie = Cookie.fromResponseHeader("foo=;utm"); |
| 327 | + assertEquals(cookie.name, "foo"); |
| 328 | + assertEquals(cookie.getAttribute("utm"), ""); |
| 329 | + |
| 330 | + // additional attributes |
| 331 | + // - multiple |
| 332 | + cookie = Cookie.fromResponseHeader("foo=;foo=bar;bar=baz;bing=boom"); |
| 333 | + assertEquals(cookie.name, "foo"); |
| 334 | + assertEquals(cookie.getAttribute("foo"), "bar"); |
| 335 | + assertEquals(cookie.getAttribute("bar"), "baz"); |
| 336 | + assertEquals(cookie.getAttribute("bing"), "boom"); |
| 337 | + |
| 338 | + // has attribute |
| 339 | + cookie = Cookie.fromResponseHeader("foo=;foo=bar;bar=baz;bing=boom"); |
| 340 | + assertTrue(cookie.hasAttribute("foo")); |
| 341 | + assertTrue(cookie.hasAttribute("bar")); |
| 342 | + assertTrue(cookie.hasAttribute("bing")); |
| 343 | + assertFalse(cookie.hasAttribute("booya")); |
| 344 | + assertFalse(cookie.hasAttribute("baz")); |
| 345 | + assertFalse(cookie.hasAttribute("boom")); |
308 | 346 | } |
309 | 347 |
|
310 | 348 | @Test(dataProvider = "schemes") |
|
0 commit comments