(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestIDPSignedAuthnRequestRequiresDestination(t *testing.T) { |
| 200 | t.Run("signed redirect without destination is rejected", func(t *testing.T) { |
| 201 | test := newExistingSessionIDPTest(t) |
| 202 | w := httptest.NewRecorder() |
| 203 | test.IDP.ServeSSO(w, signedRedirectSSORequest(t, test, "")) |
| 204 | assert.Check(t, is.Equal(http.StatusBadRequest, w.Code)) |
| 205 | }) |
| 206 | |
| 207 | t.Run("signed redirect with only a SigAlg is rejected", func(t *testing.T) { |
| 208 | test := newExistingSessionIDPTest(t) |
| 209 | r := signedRedirectSSORequest(t, test, "") |
| 210 | query := r.URL.Query() |
| 211 | query.Del("Signature") |
| 212 | r.URL.RawQuery = query.Encode() |
| 213 | w := httptest.NewRecorder() |
| 214 | test.IDP.ServeSSO(w, r) |
| 215 | assert.Check(t, is.Equal(http.StatusBadRequest, w.Code)) |
| 216 | }) |
| 217 | |
| 218 | t.Run("signed redirect with the SSO URL as destination is accepted", func(t *testing.T) { |
| 219 | test := newExistingSessionIDPTest(t) |
| 220 | w := httptest.NewRecorder() |
| 221 | test.IDP.ServeSSO(w, signedRedirectSSORequest(t, test, test.IDP.SSOURL.String())) |
| 222 | assert.Check(t, is.Equal(http.StatusOK, w.Code)) |
| 223 | }) |
| 224 | |
| 225 | t.Run("signed redirect with another destination is rejected", func(t *testing.T) { |
| 226 | test := newExistingSessionIDPTest(t) |
| 227 | w := httptest.NewRecorder() |
| 228 | test.IDP.ServeSSO(w, signedRedirectSSORequest(t, test, "https://other.example.com/saml/sso")) |
| 229 | assert.Check(t, is.Equal(http.StatusBadRequest, w.Code)) |
| 230 | }) |
| 231 | |
| 232 | t.Run("unsigned redirect without destination is accepted", func(t *testing.T) { |
| 233 | test := newExistingSessionIDPTest(t) |
| 234 | authnRequest, err := test.SP.MakeAuthenticationRequest("", HTTPRedirectBinding, HTTPPostBinding) |
| 235 | assert.NilError(t, err) |
| 236 | redirectURL, err := authnRequest.Redirect("ThisIsTheRelayState", &test.SP) |
| 237 | assert.NilError(t, err) |
| 238 | assert.Check(t, !redirectURL.Query().Has("Signature")) |
| 239 | u := test.IDP.SSOURL |
| 240 | u.RawQuery = redirectURL.RawQuery |
| 241 | r, _ := http.NewRequest("GET", u.String(), nil) |
| 242 | w := httptest.NewRecorder() |
| 243 | test.IDP.ServeSSO(w, r) |
| 244 | assert.Check(t, is.Equal(http.StatusOK, w.Code)) |
| 245 | }) |
| 246 | |
| 247 | postRequest := func(t *testing.T, test *IdentityProviderTest, destination string) *http.Request { |
| 248 | t.Helper() |
| 249 | test.SP.SignatureMethod = dsig.RSASHA256SignatureMethod |
| 250 | authnRequest, err := test.SP.MakeAuthenticationRequest(destination, HTTPPostBinding, HTTPPostBinding) |
| 251 | assert.NilError(t, err) |
| 252 | assert.Check(t, authnRequest.Signature != nil) |
| 253 | doc := etree.NewDocument() |
| 254 | doc.SetRoot(authnRequest.Element()) |
| 255 | buf, err := doc.WriteToBytes() |
| 256 | assert.NilError(t, err) |
nothing calls this directly
no test coverage detected