mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-20 09:46:01 -05:00
templates: migrate OIDC callback to elem-go
Replace html/template with type-safe elem-go templating for OIDC callback page. Improves consistency with other templates and provides compile-time safety. All UI elements and styling preserved.
This commit is contained in:
committed by
Kristoffer Dalby
parent
d14be8d43b
commit
89285c317b
63
hscontrol/oidc_template_test.go
Normal file
63
hscontrol/oidc_template_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package hscontrol
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/templates"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOIDCCallbackTemplate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
userName string
|
||||
verb string
|
||||
}{
|
||||
{
|
||||
name: "logged_in_user",
|
||||
userName: "test@example.com",
|
||||
verb: "Logged in",
|
||||
},
|
||||
{
|
||||
name: "registered_user",
|
||||
userName: "newuser@example.com",
|
||||
verb: "Registered",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Render using the elem-go template
|
||||
html := templates.OIDCCallback(tt.userName, tt.verb).Render()
|
||||
|
||||
// Verify the HTML contains expected elements
|
||||
assert.Contains(t, html, "<!DOCTYPE html>")
|
||||
assert.Contains(t, html, "<title>Headscale Authentication Succeeded</title>")
|
||||
assert.Contains(t, html, tt.verb)
|
||||
assert.Contains(t, html, tt.userName)
|
||||
assert.Contains(t, html, "You can now close this window")
|
||||
|
||||
// Verify Material for MkDocs design system CSS is present
|
||||
assert.Contains(t, html, "Material for MkDocs")
|
||||
assert.Contains(t, html, "Roboto")
|
||||
assert.Contains(t, html, ".md-typeset")
|
||||
|
||||
// Verify SVG elements are present
|
||||
assert.Contains(t, html, "<svg")
|
||||
assert.Contains(t, html, "class=\"headscale-logo\"")
|
||||
assert.Contains(t, html, "id=\"checkbox\"")
|
||||
|
||||
// Save the output for manual inspection
|
||||
testDataDir := filepath.Join("testdata", "oidc_templates")
|
||||
err := os.MkdirAll(testDataDir, 0755)
|
||||
require.NoError(t, err)
|
||||
|
||||
outputFile := filepath.Join(testDataDir, tt.name+".html")
|
||||
err = os.WriteFile(outputFile, []byte(html), 0644)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user