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

Function TestAttributeQueryElement

schema_attribute_query_test.go:31–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestAttributeQueryElement(t *testing.T) {
32 el := testAttributeQuery().SoapRequest()
33 doc := etree.NewDocument()
34 doc.SetRoot(el)
35 buf, err := doc.WriteToString()
36 assert.NilError(t, err)
37
38 // Re-parse, so that every element is checked by the namespace its
39 // prefix resolves to rather than by the prefix itself.
40 doc = etree.NewDocument()
41 assert.NilError(t, doc.ReadFromString(buf))
42 root := doc.Root()
43 assert.Equal(t, root.NamespaceURI(), soapEnvelopeNamespace)
44 assert.Equal(t, root.Tag, "Envelope")
45 body, err := findOneChild(root, soapEnvelopeNamespace, "Body")
46 assert.NilError(t, err)
47 queryEl, err := findOneChild(body, "urn:oasis:names:tc:SAML:2.0:protocol", "AttributeQuery")
48 assert.NilError(t, err)
49 assert.Equal(t, queryEl.SelectAttrValue("ID", ""), "id-query")
50 assert.Equal(t, queryEl.SelectAttrValue("Destination", ""), "https://idp.example.com/saml/aa")
51 assert.Equal(t, queryEl.SelectAttrValue("IssueInstant", ""), "2014-01-01T00:00:00Z")
52
53 children := queryEl.ChildElements()
54 assert.Equal(t, len(children), 4)
55 for i, tag := range []string{"Issuer", "Subject", "Attribute", "Attribute"} {
56 assert.Equal(t, children[i].NamespaceURI(), "urn:oasis:names:tc:SAML:2.0:assertion")
57 assert.Equal(t, children[i].Tag, tag)
58 }
59 nameID := children[1].FindElement("NameID")
60 assert.Assert(t, nameID != nil)
61 assert.Equal(t, nameID.NamespaceURI(), "urn:oasis:names:tc:SAML:2.0:assertion")
62 assert.Equal(t, nameID.Text(), "alice")
63 assert.Equal(t, nameID.SelectAttrValue("Format", ""), string(PersistentNameIDFormat))
64 value := children[3].FindElement("AttributeValue")
65 assert.Assert(t, value != nil)
66 assert.Equal(t, value.Text(), "staff")
67}
68
69func TestAttributeQueryXMLRoundTrip(t *testing.T) {
70 want := testAttributeQuery()

Callers

nothing calls this directly

Calls 3

testAttributeQueryFunction · 0.85
findOneChildFunction · 0.85
SoapRequestMethod · 0.45

Tested by

no test coverage detected