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