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

Function TestIDPCanHandlePostRequestWithExistingSession

identity_provider_test.go:265–292  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func TestIDPCanHandlePostRequestWithExistingSession(t *testing.T) {
266 test := NewIdentifyProviderTest(t)
267 test.IDP.SessionProvider = &mockSessionProvider{
268 GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
269 return &Session{
270 ID: "f00df00df00d",
271 UserName: "alice",
272 }
273 },
274 }
275
276 w := httptest.NewRecorder()
277
278 authRequest, err := test.SP.MakeAuthenticationRequest(test.SP.GetSSOBindingLocation(HTTPRedirectBinding), HTTPRedirectBinding, HTTPPostBinding)
279 assert.Check(t, err)
280 authRequestBuf, err := xml.Marshal(authRequest)
281 assert.Check(t, err)
282 q := url.Values{}
283 q.Set("SAMLRequest", base64.StdEncoding.EncodeToString(authRequestBuf))
284 q.Set("RelayState", "ThisIsTheRelayState")
285
286 r, _ := http.NewRequest("POST", "https://idp.example.com/saml/sso", strings.NewReader(q.Encode()))
287 r.Header.Set("Content-type", "application/x-www-form-urlencoded")
288
289 test.IDP.ServeSSO(w, r)
290 assert.Check(t, is.Equal(200, w.Code))
291 golden.Assert(t, w.Body.String(), t.Name()+"_http_response_body")
292}
293
294func TestIDPRejectsInvalidRequest(t *testing.T) {
295 test := NewIdentifyProviderTest(t)

Callers

nothing calls this directly

Calls 6

NewIdentifyProviderTestFunction · 0.85
GetSSOBindingLocationMethod · 0.80
ServeSSOMethod · 0.80
StringMethod · 0.80
EncodeMethod · 0.65

Tested by

no test coverage detected