Milan Pavlik f09c35a02d
[installer] Change cookie name (#18958)
* [installer] Change cookie name

* fix test

* fix
2023-10-19 17:35:28 +03:00

66 lines
1.7 KiB
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package auth
import "testing"
func TestCookieNameFromDomain(t *testing.T) {
tests := []struct {
name string
domain string
expectedOutcome string
}{
{
name: "Simple Domain",
domain: "example.com",
expectedOutcome: "_example_com_jwt2_",
},
{
name: "Domain with Underscore",
domain: "example_test.com",
expectedOutcome: "_example_test_com_jwt2_",
},
{
name: "Domain with Hyphen",
domain: "example-test.com",
expectedOutcome: "_example_test_com_jwt2_",
},
{
name: "Domain with Special Characters",
domain: "example&test.com",
expectedOutcome: "_example_test_com_jwt2_",
},
{
name: "Subdomain",
domain: "subdomain.example.com",
expectedOutcome: "_subdomain_example_com_jwt2_",
},
{
name: "Subdomain with Hyphen",
domain: "sub-domain.example.com",
expectedOutcome: "_sub_domain_example_com_jwt2_",
},
{
name: "Subdomain with Underscore",
domain: "sub_domain.example.com",
expectedOutcome: "_sub_domain_example_com_jwt2_",
},
{
name: "Subdomain with Special Characters",
domain: "sub&domain.example.com",
expectedOutcome: "_sub_domain_example_com_jwt2_",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := cookieNameFromDomain(tt.domain)
if actual != tt.expectedOutcome {
t.Errorf("expected %q, got %q", tt.expectedOutcome, actual)
}
})
}
}