MCPcopy Create free account
hub / github.com/crewjam/saml / assertXHTMLDocument

Function assertXHTMLDocument

samlsp/xhtml_forms_test.go:24–54  ·  view source on GitHub ↗

assertXHTMLDocument checks that page is a well-formed XML document whose root is an XHTML html element holding a head with a title and a body (saml-bindings-2.0-os §3.5.4: "The HTML document MUST adhere to the XHTML specification").

(t *testing.T, page []byte)

Source from the content-addressed store, hash-verified

22// (saml-bindings-2.0-os §3.5.4: "The HTML document MUST adhere to the XHTML
23// specification").
24func assertXHTMLDocument(t *testing.T, page []byte) {
25 t.Helper()
26 d := xml.NewDecoder(bytes.NewReader(page))
27 d.Strict = true
28
29 var path []string
30 roots := 0
31 seen := map[string]bool{}
32 for {
33 tok, err := d.Token()
34 if errors.Is(err, io.EOF) {
35 break
36 }
37 assert.NilError(t, err, "page is not well-formed XML:\n%s", page)
38 switch tok := tok.(type) {
39 case xml.StartElement:
40 if len(path) == 0 {
41 roots++
42 assert.Check(t, is.Equal(xml.Name{Space: xhtmlNamespace, Local: "html"}, tok.Name))
43 }
44 assert.Check(t, is.Equal(xhtmlNamespace, tok.Name.Space), "element %q is not in the XHTML namespace", tok.Name.Local)
45 path = append(path, tok.Name.Local)
46 seen[strings.Join(path, "/")] = true
47 case xml.EndElement:
48 path = path[:len(path)-1]
49 }
50 }
51 assert.Check(t, is.Equal(1, roots))
52 assert.Check(t, seen["html/head/title"], "page has no html/head/title")
53 assert.Check(t, seen["html/body"], "page has no html/body")
54}
55
56func TestXHTMLPostBindingPage(t *testing.T) {
57 test := NewMiddlewareTest(t)

Callers 2

TestXHTMLPostBindingPageFunction · 0.70
TestXHTMLReplayPageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected