Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/auth/config_test.go
2501 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package auth
6
7
import (
8
"testing"
9
10
server_lib "github.com/gitpod-io/gitpod/server/go/pkg/lib"
11
)
12
13
func TestCookieNameFromDomain(t *testing.T) {
14
tests := []struct {
15
name string
16
domain string
17
expectedOutcome string
18
}{
19
{
20
name: "Simple Domain",
21
domain: "example.com",
22
expectedOutcome: "__Host-_example_com_jwt2_",
23
},
24
{
25
name: "Domain with Underscore",
26
domain: "example_test.com",
27
expectedOutcome: "__Host-_example_test_com_jwt2_",
28
},
29
{
30
name: "Domain with Hyphen",
31
domain: "example-test.com",
32
expectedOutcome: "__Host-_example_test_com_jwt2_",
33
},
34
{
35
name: "Domain with Special Characters",
36
domain: "example&test.com",
37
expectedOutcome: "__Host-_example_test_com_jwt2_",
38
},
39
{
40
name: "Subdomain",
41
domain: "subdomain.example.com",
42
expectedOutcome: "__Host-_subdomain_example_com_jwt2_",
43
},
44
{
45
name: "Subdomain with Hyphen",
46
domain: "sub-domain.example.com",
47
expectedOutcome: "__Host-_sub_domain_example_com_jwt2_",
48
},
49
{
50
name: "Subdomain with Underscore",
51
domain: "sub_domain.example.com",
52
expectedOutcome: "__Host-_sub_domain_example_com_jwt2_",
53
},
54
{
55
name: "Subdomain with Special Characters",
56
domain: "sub&domain.example.com",
57
expectedOutcome: "__Host-_sub_domain_example_com_jwt2_",
58
},
59
}
60
61
for _, tt := range tests {
62
t.Run(tt.name, func(t *testing.T) {
63
actual := server_lib.CookieNameFromDomain(tt.domain)
64
if actual != tt.expectedOutcome {
65
t.Errorf("expected %q, got %q", tt.expectedOutcome, actual)
66
}
67
})
68
}
69
}
70
71