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

Function TestArtifactDecodingReplay

artifact_decoding_test.go:201–250  ·  view source on GitHub ↗

saml-bindings-2.0-os §3.6.5.2: an artifact is resolved only once. With a ReplayCache, the SP refuses a second resolution of the same artifact before contacting the IdP.

(t *testing.T)

Source from the content-addressed store, hash-verified

199// ReplayCache, the SP refuses a second resolution of the same artifact
200// before contacting the IdP.
201func TestArtifactDecodingReplay(t *testing.T) {
202 e, s := artifactdecSetup(t)
203 cache := memoryReplayCache{}
204 e.sp.ReplayCache = cache
205
206 artifact := artifactdecMake(7, artifactdecIDPSourceID(), 0x08)
207 _, err := e.sp.ParseResponse(spcovArtifactRequest(artifact), []string{spcovRequestID})
208 assert.NilError(t, err)
209 assert.Check(t, is.Len(s.paths, 1))
210 _, recorded := cache["Artifact:"+bytesHex(artifactdecIDPSourceID())+":"+bytesHex(fill20(0x08))]
211 assert.Check(t, recorded, "cache keys: %v", cache)
212 _, recorded = cache["id-assertion"]
213 assert.Check(t, recorded)
214
215 t.Run("same artifact again", func(t *testing.T) {
216 _, err := e.sp.ParseResponse(spcovArtifactRequest(artifact), []string{spcovRequestID})
217 privateErr := spcovPrivateErr(t, err)
218 assert.Check(t, is.ErrorIs(privateErr, ErrArtifactResolution))
219 assert.Check(t, is.ErrorIs(privateErr, ErrAssertionReplayed))
220 assert.Check(t, is.Len(s.paths, 1), "the IdP must not be contacted again")
221 })
222
223 t.Run("same MessageHandle through another EndpointIndex", func(t *testing.T) {
224 _, err := e.sp.ParseResponse(spcovArtifactRequest(artifactdecMake(0, artifactdecIDPSourceID(), 0x08)), []string{spcovRequestID})
225 assert.Check(t, is.ErrorIs(spcovPrivateErr(t, err), ErrAssertionReplayed))
226 assert.Check(t, is.Len(s.paths, 1))
227 })
228
229 t.Run("non-standard artifact is recorded by value", func(t *testing.T) {
230 delete(cache, "id-assertion")
231 _, err := e.sp.ParseResponse(spcovArtifactRequest("the-artifact"), []string{spcovRequestID})
232 assert.NilError(t, err)
233 _, recorded := cache["Artifact:raw:the-artifact"]
234 assert.Check(t, recorded)
235 _, err = e.sp.ParseResponse(spcovArtifactRequest("the-artifact"), []string{spcovRequestID})
236 assert.Check(t, is.ErrorIs(spcovPrivateErr(t, err), ErrAssertionReplayed))
237 assert.Check(t, is.Len(s.paths, 2))
238 })
239
240 t.Run("cache error refuses the artifact", func(t *testing.T) {
241 sp := *e.sp
242 sp.ReplayCache = failingReplayCache{}
243 _, err := sp.ParseResponse(spcovArtifactRequest(artifactdecMake(7, artifactdecIDPSourceID(), 0x09)), []string{spcovRequestID})
244 privateErr := spcovPrivateErr(t, err)
245 assert.Check(t, is.ErrorIs(privateErr, ErrArtifactResolution))
246 assert.Check(t, is.Error(privateErr, "artifact: store unavailable"))
247 assert.Check(t, !errors.Is(privateErr, ErrAssertionReplayed))
248 assert.Check(t, is.Len(s.paths, 2))
249 })
250}
251
252func fill20(b byte) [20]byte {
253 var a [20]byte

Callers

nothing calls this directly

Calls 10

artifactdecSetupFunction · 0.85
artifactdecMakeFunction · 0.85
artifactdecIDPSourceIDFunction · 0.85
spcovArtifactRequestFunction · 0.85
bytesHexFunction · 0.85
fill20Function · 0.85
spcovPrivateErrFunction · 0.85
ParseResponseMethod · 0.80
LenMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected