mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-25 01:59:07 +02:00
templates: generalise auth templates for web and OIDC
Extract shared HTML/CSS design into a common template and create generalised auth success and web auth templates that work for both node registration and SSH check authentication flows. Updates #1850
This commit is contained in:
@@ -7,35 +7,54 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestOIDCCallbackTemplate(t *testing.T) {
|
||||
func TestAuthSuccessTemplate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
userName string
|
||||
verb string
|
||||
name string
|
||||
result templates.AuthSuccessResult
|
||||
}{
|
||||
{
|
||||
name: "logged_in_user",
|
||||
userName: "test@example.com",
|
||||
verb: "Logged in",
|
||||
name: "node_registered",
|
||||
result: templates.AuthSuccessResult{
|
||||
Title: "Headscale - Node Registered",
|
||||
Heading: "Node registered",
|
||||
Verb: "Registered",
|
||||
User: "newuser@example.com",
|
||||
Message: "You can now close this window.",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "registered_user",
|
||||
userName: "newuser@example.com",
|
||||
verb: "Registered",
|
||||
name: "node_reauthenticated",
|
||||
result: templates.AuthSuccessResult{
|
||||
Title: "Headscale - Node Reauthenticated",
|
||||
Heading: "Node reauthenticated",
|
||||
Verb: "Reauthenticated",
|
||||
User: "test@example.com",
|
||||
Message: "You can now close this window.",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ssh_session_authorized",
|
||||
result: templates.AuthSuccessResult{
|
||||
Title: "Headscale - SSH Session Authorized",
|
||||
Heading: "SSH session authorized",
|
||||
Verb: "Authorized",
|
||||
User: "test@example.com",
|
||||
Message: "You may return to your terminal.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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()
|
||||
html := templates.AuthSuccess(tt.result).Render()
|
||||
|
||||
// Verify the HTML contains expected elements
|
||||
// Verify the HTML contains expected structural 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")
|
||||
assert.Contains(t, html, "<title>"+tt.result.Title+"</title>")
|
||||
assert.Contains(t, html, tt.result.Heading)
|
||||
assert.Contains(t, html, tt.result.Verb+" as ")
|
||||
assert.Contains(t, html, tt.result.User)
|
||||
assert.Contains(t, html, tt.result.Message)
|
||||
|
||||
// Verify Material for MkDocs design system CSS is present
|
||||
assert.Contains(t, html, "Material for MkDocs")
|
||||
|
||||
Reference in New Issue
Block a user