(t *testing.T)
| 689 | } |
| 690 | |
| 691 | func Test_CookieJar_MixedHostOnlyAndDomainCookies(t *testing.T) { |
| 692 | t.Parallel() |
| 693 | |
| 694 | testCases := []struct { |
| 695 | name string |
| 696 | order []string |
| 697 | }{ |
| 698 | { |
| 699 | name: "host-only first", |
| 700 | order: []string{"host-only", "domain"}, |
| 701 | }, |
| 702 | { |
| 703 | name: "domain first", |
| 704 | order: []string{"domain", "host-only"}, |
| 705 | }, |
| 706 | } |
| 707 | |
| 708 | for _, testCase := range testCases { |
| 709 | t.Run(testCase.name, func(t *testing.T) { |
| 710 | t.Parallel() |
| 711 | |
| 712 | jar := &CookieJar{} |
| 713 | |
| 714 | hostOnlyOrigin := fasthttp.AcquireURI() |
| 715 | defer fasthttp.ReleaseURI(hostOnlyOrigin) |
| 716 | require.NoError(t, hostOnlyOrigin.Parse(nil, []byte("http://example.com/"))) |
| 717 | |
| 718 | domainOrigin := fasthttp.AcquireURI() |
| 719 | defer fasthttp.ReleaseURI(domainOrigin) |
| 720 | require.NoError(t, domainOrigin.Parse(nil, []byte("http://sub.example.com/"))) |
| 721 | |
| 722 | hostOnlyCookie := &fasthttp.Cookie{} |
| 723 | hostOnlyCookie.SetKey("host-only") |
| 724 | hostOnlyCookie.SetValue("123") |
| 725 | |
| 726 | domainCookie := &fasthttp.Cookie{} |
| 727 | domainCookie.SetKey("domain") |
| 728 | domainCookie.SetValue("456") |
| 729 | domainCookie.SetDomain("example.com") |
| 730 | |
| 731 | for _, cookieType := range testCase.order { |
| 732 | switch cookieType { |
| 733 | case "host-only": |
| 734 | jar.Set(hostOnlyOrigin, hostOnlyCookie) |
| 735 | case "domain": |
| 736 | jar.Set(domainOrigin, domainCookie) |
| 737 | default: |
| 738 | t.Fatalf("unexpected cookie type %q", cookieType) |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | anotherSubdomain := fasthttp.AcquireURI() |
| 743 | defer fasthttp.ReleaseURI(anotherSubdomain) |
| 744 | require.NoError(t, anotherSubdomain.Parse(nil, []byte("http://child.example.com/"))) |
| 745 | require.Equal(t, []string{"domain"}, cookieKeys(jar.Get(anotherSubdomain))) |
| 746 | |
| 747 | require.ElementsMatch(t, []string{"domain", "host-only"}, cookieKeys(jar.Get(hostOnlyOrigin))) |
| 748 | }) |
nothing calls this directly
no test coverage detected