mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-06-13 15:47:37 +08:00
- Add regression coverage for jow-/ucode whitelist entries - Verify whitelist parsing and matching preserve hyphenated owner names
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"ghproxy/config"
|
|
)
|
|
|
|
func TestSplitUserRepoWhitelist_PreservesHyphenatedOwner(t *testing.T) {
|
|
user, repo := splitUserRepoWhitelist("jow-/ucode")
|
|
|
|
if user != "jow-" {
|
|
t.Fatalf("user = %q, want %q", user, "jow-")
|
|
}
|
|
if repo != "ucode" {
|
|
t.Fatalf("repo = %q, want %q", repo, "ucode")
|
|
}
|
|
}
|
|
|
|
func TestInitWhitelist_AllowsHyphenatedOwnerRepo(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
whitelistPath := filepath.Join(tmpDir, "whitelist.json")
|
|
|
|
content := []byte(`{"whitelist":["jow-/ucode"]}`)
|
|
if err := os.WriteFile(whitelistPath, content, 0o600); err != nil {
|
|
t.Fatalf("write whitelist file: %v", err)
|
|
}
|
|
|
|
whitelistInstance = nil
|
|
whitelistInitErr = nil
|
|
|
|
cfg := &config.Config{}
|
|
cfg.Whitelist.WhitelistFile = whitelistPath
|
|
|
|
if err := InitWhitelist(cfg); err != nil {
|
|
t.Fatalf("InitWhitelist() error = %v", err)
|
|
}
|
|
|
|
if !CheckWhitelist("jow-", "ucode") {
|
|
t.Fatal("CheckWhitelist() = false, want true for jow-/ucode")
|
|
}
|
|
|
|
if CheckWhitelist("jow", "ucode") {
|
|
t.Fatal("CheckWhitelist() = true, want false for non-hyphenated owner")
|
|
}
|
|
|
|
if CheckWhitelist("jow-", "other") {
|
|
t.Fatal("CheckWhitelist() = true, want false for unmatched repo")
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
whitelistInstance = nil
|
|
whitelistInitErr = nil
|
|
})
|
|
}
|