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

Function TestSimpleSignOutgoing

simplesign_binding_test.go:548–654  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func TestSimpleSignOutgoing(t *testing.T) {
549 e := spcovSetup(t)
550 e.sp.SignatureMethod = dsig.RSASHA256SignatureMethod
551 e.sp.IDPMetadata.IDPSSODescriptors[0].SingleSignOnServices = append(e.sp.IDPMetadata.IDPSSODescriptors[0].SingleSignOnServices,
552 Endpoint{Binding: HTTPPostSimpleSignBinding, Location: "https://idp.example.com/sso/simplesign"})
553 e.sp.IDPMetadata.IDPSSODescriptors[0].SingleLogoutServices = append(e.sp.IDPMetadata.IDPSSODescriptors[0].SingleLogoutServices,
554 Endpoint{Binding: HTTPPostSimpleSignBinding, Location: "https://idp.example.com/slo/simplesign"})
555 verifier := verifierFor(e.sp)
556 const relayState = "a b&c=d\"<>"
557
558 check := func(t *testing.T, form []byte, wantAction, param string, wantRelayState bool) *etree.Element {
559 t.Helper()
560 action, v := formFields(t, form)
561 assert.Check(t, is.Equal(wantAction, action))
562 _, hasRelayState := v["RelayState"]
563 assert.Check(t, is.Equal(wantRelayState, hasRelayState))
564 assert.Check(t, is.Equal(dsig.RSASHA256SignatureMethod, v.Get("SigAlg")))
565
566 req := simpleSignPost(t, action, v)
567 m, err := parseSimpleSignRequest(req, param)
568 assert.NilError(t, err)
569 assert.NilError(t, verifier.verifySimpleSignSignature(m))
570
571 // The XML is sent unsigned and not deflated.
572 doc := etree.NewDocument()
573 assert.NilError(t, doc.ReadFromBytes(m.XML))
574 assert.Check(t, is.Nil(doc.Root().FindElement("./Signature")))
575 assert.Check(t, is.Equal(wantAction, doc.Root().SelectAttrValue("Destination", "")))
576 return doc.Root()
577 }
578
579 t.Run("AuthnRequest", func(t *testing.T) {
580 form, err := e.sp.MakeSimpleSignAuthenticationRequest(relayState)
581 assert.NilError(t, err)
582 root := check(t, form, "https://idp.example.com/sso/simplesign", "SAMLRequest", true)
583 assert.Check(t, is.Equal("AuthnRequest", root.Tag))
584 _, v := formFields(t, form)
585 assert.Check(t, is.Equal(relayState, v.Get("RelayState")))
586 })
587 t.Run("AuthnRequest without relay state", func(t *testing.T) {
588 form, err := e.sp.MakeSimpleSignAuthenticationRequest("")
589 assert.NilError(t, err)
590 check(t, form, "https://idp.example.com/sso/simplesign", "SAMLRequest", false)
591 })
592 t.Run("AuthnRequest form script matches the HTTP-POST form", func(t *testing.T) {
593 req, err := e.sp.MakeAuthenticationRequest("https://idp.example.com/sso/simplesign", HTTPPostSimpleSignBinding, HTTPPostBinding)
594 assert.NilError(t, err)
595 form, err := req.SimpleSignWithNonce(relayState, "n0nce", e.sp)
596 assert.NilError(t, err)
597 post := req.PostWithNonce(relayState, "n0nce")
598 script := func(b []byte) string { return string(b[strings.Index(string(b), "<script"):]) }
599 assert.Equal(t, script(form), script(post))
600 assert.Check(t, strings.Contains(string(form), `<script nonce="n0nce">`))
601 })
602 t.Run("LogoutRequest", func(t *testing.T) {
603 form, err := e.sp.MakeSimpleSignLogoutRequest("alice", relayState, WithSessionIndex("s1"))
604 assert.NilError(t, err)
605 root := check(t, form, "https://idp.example.com/slo/simplesign", "SAMLRequest", true)

Callers

nothing calls this directly

Calls 15

spcovSetupFunction · 0.85
verifierForFunction · 0.85
formFieldsFunction · 0.85
simpleSignPostFunction · 0.85
parseSimpleSignRequestFunction · 0.85
WithSessionIndexFunction · 0.85
redirectECDSAKeyPairFunction · 0.85
GetSSOBindingLocationMethod · 0.80

Tested by

no test coverage detected