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

Function TestSimpleSignResponseAtACS

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

Source from the content-addressed store, hash-verified

172}
173
174func TestSimpleSignResponseAtACS(t *testing.T) {
175 e := spcovSetup(t)
176 acs := e.sp.AcsURL.String()
177 unsigned := e.simpleSignResponseXML(t, nil)
178 valid := simpleSignMsg{param: "SAMLResponse", xml: unsigned, sigAlg: dsig.RSASHA256SignatureMethod, key: e.idpKey}
179 parse := func(t *testing.T, sp *ServiceProvider, v url.Values) (*Assertion, error) {
180 t.Helper()
181 return sp.ParseResponse(simpleSignPost(t, acs, v), []string{spcovRequestID})
182 }
183 accept := func(t *testing.T, sp *ServiceProvider, v url.Values) {
184 t.Helper()
185 assertion, err := parse(t, sp, v)
186 if err != nil {
187 t.Fatalf("unexpected error: %v", spcovPrivateErr(t, err))
188 }
189 assert.Check(t, is.Equal("id-assertion", assertion.ID))
190 }
191 reject := func(t *testing.T, sp *ServiceProvider, v url.Values, wantErr string) {
192 t.Helper()
193 _, err := parse(t, sp, v)
194 assert.Assert(t, err != nil)
195 assert.ErrorContains(t, spcovPrivateErr(t, err), wantErr)
196 }
197
198 t.Run("valid, assertion unsigned", func(t *testing.T) {
199 accept(t, e.sp, valid.values(t))
200 })
201 t.Run("plain HTTP-POST with an unsigned assertion is still rejected", func(t *testing.T) {
202 v := url.Values{"SAMLResponse": {base64.StdEncoding.EncodeToString(unsigned)}}
203 reject(t, e.sp, v, "signature element not present")
204 })
205 for _, alg := range []string{dsig.RSASHA1SignatureMethod, dsig.RSASHA384SignatureMethod, dsig.RSASHA512SignatureMethod} {
206 t.Run("algorithm "+alg, func(t *testing.T) {
207 m := valid
208 m.sigAlg = alg
209 accept(t, e.sp, m.values(t))
210 })
211 }
212 t.Run("with relay state", func(t *testing.T) {
213 m := valid
214 m.relayState = strPtr("a b&c=d/é")
215 accept(t, e.sp, m.values(t))
216 })
217 t.Run("empty relay state field is signed", func(t *testing.T) {
218 m := valid
219 m.relayState = strPtr("")
220 accept(t, e.sp, m.values(t))
221 })
222 t.Run("empty relay state field added after signing", func(t *testing.T) {
223 v := valid.values(t)
224 v.Set("RelayState", "")
225 reject(t, e.sp, v, "verification error")
226 })
227 t.Run("tampered relay state", func(t *testing.T) {
228 m := valid
229 m.relayState = strPtr("token")
230 v := m.values(t)
231 v.Set("RelayState", "other")

Callers

nothing calls this directly

Calls 15

valuesMethod · 0.95
spcovSetupFunction · 0.85
simpleSignPostFunction · 0.85
spcovPrivateErrFunction · 0.85
strPtrFunction · 0.85
otherKeyFunction · 0.85
spcovSerializeFunction · 0.85
fingerprintFunction · 0.85
keyInfoFunction · 0.85
StringMethod · 0.80
simpleSignResponseXMLMethod · 0.80
ParseResponseMethod · 0.80

Tested by

no test coverage detected