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