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

Function TestSpecBinding_SimpleSign_2_5_SignedOctetString

spec_bindings_test.go:475–528  ·  view source on GitHub ↗

sstc-saml-binding-simplesign-cs-01 §2.5 and §2.6: the SimpleSign signature is over "SAMLResponse= &RelayState= &SigAlg= ", with none of the values URL- or base64-encoded, and RSAwithSHA1 MUST be supported. The receiver reconstructs the string from the form control values. Here th

(t *testing.T)

Source from the content-addressed store, hash-verified

473// certificate, and the service provider accepts an rsa-sha1 SimpleSign
474// response.
475func TestSpecBinding_SimpleSign_2_5_SignedOctetString(t *testing.T) {
476 t.Run("IdP output", func(t *testing.T) {
477 oldTimeNow, oldRandReader := TimeNow, RandReader
478 t.Cleanup(func() { TimeNow, RandReader = oldTimeNow, oldRandReader })
479 test := newSimpleSignIDPTest(t)
480 test.IDP.SessionProvider = &mockSessionProvider{
481 GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
482 return &Session{ID: "f00df00df00d", UserName: "alice"}
483 },
484 }
485 const relayState = "a b&c=d"
486 authnReq, err := test.SP.MakeAuthenticationRequest(test.SP.GetSSOBindingLocation(HTTPRedirectBinding), HTTPRedirectBinding, HTTPPostSimpleSignBinding)
487 assert.NilError(t, err)
488 u, err := authnReq.Redirect(relayState, &test.SP)
489 assert.NilError(t, err)
490 w := httptest.NewRecorder()
491 test.IDP.ServeSSO(w, httptest.NewRequest(http.MethodGet, u.String(), nil))
492 assert.Assert(t, is.Equal(http.StatusOK, w.Code), w.Body.String())
493
494 method, _, fields := specParseForm(t, w.Body.String())
495 assert.Check(t, is.Equal("post", method))
496 assert.Assert(t, fields.Get("SigAlg") != "", w.Body.String())
497 xmlBuf, err := base64.StdEncoding.DecodeString(fields.Get("SAMLResponse"))
498 assert.NilError(t, err)
499 assert.Check(t, is.Equal(relayState, fields.Get("RelayState")))
500
501 signed := "SAMLResponse=" + string(xmlBuf) + "&RelayState=" + relayState + "&SigAlg=" + fields.Get("SigAlg")
502 sig, err := base64.StdEncoding.DecodeString(fields.Get("Signature"))
503 assert.NilError(t, err)
504 alg, ok := redirectSignatureAlgorithms[fields.Get("SigAlg")]
505 assert.Assert(t, ok)
506 assert.NilError(t, test.IDP.Certificate.CheckSignature(alg, []byte(signed), sig))
507 })
508
509 t.Run("SP accepts rsa-sha1", func(t *testing.T) {
510 e := spcovSetup(t)
511 xmlBuf := e.simpleSignResponseXML(t, nil)
512 const relayState = "rs"
513 signed := "SAMLResponse=" + string(xmlBuf) + "&RelayState=" + relayState + "&SigAlg=" + dsig.RSASHA1SignatureMethod
514 sig := redirectSign(t, e.idpKey, dsig.RSASHA1SignatureMethod, signed)
515 form := url.Values{
516 "SAMLResponse": {base64.StdEncoding.EncodeToString(xmlBuf)},
517 "RelayState": {relayState},
518 "SigAlg": {dsig.RSASHA1SignatureMethod},
519 "Signature": {base64.StdEncoding.EncodeToString(sig)},
520 }
521 r := httptest.NewRequest(http.MethodPost, e.sp.AcsURL.String(), strings.NewReader(form.Encode()))
522 r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
523 assert.NilError(t, r.ParseForm())
524 assertion, err := e.sp.ParseResponse(r, []string{spcovRequestID})
525 assert.NilError(t, err)
526 assert.Check(t, is.Equal("alice@example.com", assertion.Subject.NameID.Value))
527 })
528}
529
530// saml-bindings-2.0-os §3.4.5 step 2: when the HTTP-Redirect binding is used,
531// "the HTTP status MUST be either 303 or 302". Checked for the IdP's

Callers

nothing calls this directly

Calls 13

newSimpleSignIDPTestFunction · 0.85
specParseFormFunction · 0.85
spcovSetupFunction · 0.85
redirectSignFunction · 0.85
GetSSOBindingLocationMethod · 0.80
ServeSSOMethod · 0.80
StringMethod · 0.80
simpleSignResponseXMLMethod · 0.80
ParseResponseMethod · 0.80
GetMethod · 0.65
EncodeMethod · 0.65

Tested by

no test coverage detected