| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestDevModeRefusedOnProductionHost(t *testing.T) { |
| 11 | dir := t.TempDir() |
| 12 | path := filepath.Join(dir, "config.yml") |
| 13 | body := []byte("base_url: https://git.timfalken.com\nstorage_path: /mnt/storage/bluegit\nauth:\n mode: dev\n") |
| 14 | if err := os.WriteFile(path, body, 0o600); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | _, err := Load(path) |
| 18 | if err == nil || !strings.Contains(err.Error(), "dev") { |
| 19 | t.Fatalf("verwacht weigering, kreeg %v", err) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func TestSecretFromEnv(t *testing.T) { |
| 24 | dir := t.TempDir() |
| 25 | path := filepath.Join(dir, "config.yml") |
| 26 | body := []byte("base_url: https://git.example.test\nstorage_path: " + dir + "\nauth:\n mode: oauth\n client_id: git.example.test\n") |
| 27 | if err := os.WriteFile(path, body, 0o600); err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | t.Setenv("BLUEGIT_AUTH_CLIENT_SECRET", "uit-de-omgeving") |
| 31 | cfg, err := Load(path) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | if cfg.Auth.ClientSecret != "uit-de-omgeving" || cfg.Git.DefaultBranch != "main" { |
| 36 | t.Fatalf("%+v", cfg.Auth) |
| 37 | } |
| 38 | if cfg.RedirectURI() != "https://git.example.test/auth/callback" { |
| 39 | t.Fatal(cfg.RedirectURI()) |
| 40 | } |
| 41 | } |