Introduce a commercial license option alongside AGPL-3.0-only, require a CLA for contributors, and document the terms in COMMERCIAL.md and NOTICE. Add a script to stamp SPDX headers on Go files and apply it across the tree.
53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package dnsname
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateExternalFQDN(t *testing.T) {
|
|
// Four maximal labels + three dots = 255 chars, over the 253 limit.
|
|
overlongName := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." +
|
|
strings.Repeat("c", 63) + "." + strings.Repeat("d", 63)
|
|
|
|
tests := []struct {
|
|
name string
|
|
domain string
|
|
operatorRoots []string
|
|
wantErr bool
|
|
}{
|
|
{"valid external domain", "wiki.example.org", []string{"example.test"}, false},
|
|
{"valid deep external domain", "a.b.wiki.example.org", []string{"example.test"}, false},
|
|
{"shape check only with no operator roots", "wiki.example.org", nil, false},
|
|
{"empty root entry ignored", "wiki.example.org", []string{""}, false},
|
|
{"punycode label accepted", "xn--53h.example.org", nil, false},
|
|
{"similar suffix is not under an operator root", "notexample.test", []string{"example.test"}, false},
|
|
{"clear of every operator root", "wiki.example.org", []string{"example.test", "other.test"}, false},
|
|
{"single label rejected", "intranet", nil, true},
|
|
{"empty rejected", "", nil, true},
|
|
{"operator root itself rejected", "example.test", []string{"example.test"}, true},
|
|
{"name under an operator root rejected", "foo.example.test", []string{"example.test"}, true},
|
|
{"deep name under an operator root rejected", "a.b.example.test", []string{"example.test"}, true},
|
|
{"name under a later operator root rejected", "a.other.test", []string{"example.test", "other.test"}, true},
|
|
{"uppercase rejected — caller must normalize", "Wiki.Example.org", nil, true},
|
|
{"label over 63 chars rejected", strings.Repeat("a", 64) + ".example.org", nil, true},
|
|
{"total over 253 chars rejected", overlongName, nil, true},
|
|
{"leading hyphen rejected", "-wiki.example.org", nil, true},
|
|
{"empty label rejected", "wiki..example.org", nil, true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ValidateExternalFQDN(tt.domain, tt.operatorRoots)
|
|
if tt.wantErr && got == "" {
|
|
t.Errorf("ValidateExternalFQDN(%q, %v) = no error, want error", tt.domain, tt.operatorRoots)
|
|
}
|
|
if !tt.wantErr && got != "" {
|
|
t.Errorf("ValidateExternalFQDN(%q, %v) = %q, want no error", tt.domain, tt.operatorRoots, got)
|
|
}
|
|
})
|
|
}
|
|
}
|