(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestBasePrefixInLinks(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | basePrefix string |
| 19 | wantInLink string |
| 20 | }{ |
| 21 | { |
| 22 | name: "no prefix", |
| 23 | basePrefix: "", |
| 24 | wantInLink: "/.within.website/x/cmd/anubis/api/", |
| 25 | }, |
| 26 | { |
| 27 | name: "with rififi prefix", |
| 28 | basePrefix: "/rififi", |
| 29 | wantInLink: "/rififi/.within.website/x/cmd/anubis/api/", |
| 30 | }, |
| 31 | { |
| 32 | name: "with myapp prefix", |
| 33 | basePrefix: "/myapp", |
| 34 | wantInLink: "/myapp/.within.website/x/cmd/anubis/api/", |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | for _, tt := range tests { |
| 39 | t.Run(tt.name, func(t *testing.T) { |
| 40 | // Save original BasePrefix and restore after test |
| 41 | origPrefix := anubis.BasePrefix |
| 42 | defer func() { anubis.BasePrefix = origPrefix }() |
| 43 | |
| 44 | anubis.BasePrefix = tt.basePrefix |
| 45 | |
| 46 | // Create test impressum |
| 47 | impressum := &config.Impressum{ |
| 48 | Footer: "<p>Test footer</p>", |
| 49 | Page: config.ImpressumPage{ |
| 50 | Title: "Test Imprint", |
| 51 | Body: "<p>Test imprint body</p>", |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | // Create localizer using a dummy request |
| 56 | req := httptest.NewRequest("GET", "/", nil) |
| 57 | localizer := &localization.SimpleLocalizer{} |
| 58 | localizer.Localizer = localization.NewLocalizationService().GetLocalizerFromRequest(req) |
| 59 | |
| 60 | // Render the base template to a buffer |
| 61 | var buf strings.Builder |
| 62 | component := base(tt.name, templ.NopComponent, impressum, nil, nil, localizer) |
| 63 | err := component.Render(context.Background(), &buf) |
| 64 | if err != nil { |
| 65 | t.Fatalf("failed to render template: %v", err) |
| 66 | } |
| 67 | |
| 68 | output := buf.String() |
| 69 | |
| 70 | // Check that honeypot link includes the base prefix |
| 71 | if !strings.Contains(output, `href="`+tt.wantInLink+`honeypot/`) { |
| 72 | t.Errorf("honeypot link does not contain base prefix %q\noutput: %s", tt.wantInLink, output) |
nothing calls this directly
no test coverage detected