|
10 | 10 |
|
11 | 11 | from saml2.argtree import add_path |
12 | 12 | from saml2.cert import OpenSSLWrapper |
| 13 | +from saml2.xmldsig import sig_default |
13 | 14 | from saml2.xmldsig import SIG_RSA_SHA256 |
14 | 15 | from saml2 import BINDING_HTTP_POST |
15 | 16 | from saml2 import BINDING_HTTP_REDIRECT |
@@ -1445,28 +1446,70 @@ def test_sign_then_encrypt_assertion_advice_2(self): |
1445 | 1446 | 'givenName': ['Derek'], 'email': |
1446 | 1447 | ['test.testsson@test.se'], 'sn': ['Jeter']} |
1447 | 1448 |
|
1448 | | - def test_signed_redirect(self): |
1449 | | - |
| 1449 | + def test_signed_with_default_algo_redirect(self): |
1450 | 1450 | # Revert configuration change to disallow unsinged responses |
1451 | 1451 | self.client.want_response_signed = True |
1452 | 1452 |
|
1453 | | - msg_str = "%s" % self.client.create_authn_request( |
1454 | | - "http://localhost:8088/sso", message_id="id1")[1] |
| 1453 | + reqid, req = self.client.create_authn_request( |
| 1454 | + "http://localhost:8088/sso", message_id="id1" |
| 1455 | + ) |
| 1456 | + msg_str = str(req) |
1455 | 1457 |
|
1456 | 1458 | info = self.client.apply_binding( |
1457 | | - BINDING_HTTP_REDIRECT, msg_str, destination="", |
1458 | | - relay_state="relay2", sign=True, sigalg=SIG_RSA_SHA256) |
| 1459 | + BINDING_HTTP_REDIRECT, |
| 1460 | + msg_str, |
| 1461 | + destination="", |
| 1462 | + relay_state="relay2", |
| 1463 | + sign=True, |
| 1464 | + ) |
| 1465 | + loc = info["headers"][0][1] |
| 1466 | + qs = parse.parse_qs(loc[1:]) |
| 1467 | + |
| 1468 | + expected_query_params = ['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'] |
| 1469 | + |
| 1470 | + assert _leq(qs.keys(), expected_query_params) |
| 1471 | + assert all(len(qs[k]) == 1 for k in expected_query_params) |
| 1472 | + assert qs["SigAlg"] == [sig_default] |
| 1473 | + assert verify_redirect_signature( |
| 1474 | + list_values2simpletons(qs), self.client.sec.sec_backend |
| 1475 | + ) |
| 1476 | + |
| 1477 | + res = self.server.parse_authn_request( |
| 1478 | + qs["SAMLRequest"][0], BINDING_HTTP_REDIRECT |
| 1479 | + ) |
| 1480 | + |
| 1481 | + def test_signed_redirect(self): |
| 1482 | + # Revert configuration change to disallow unsinged responses |
| 1483 | + self.client.want_response_signed = True |
| 1484 | + |
| 1485 | + reqid, req = self.client.create_authn_request( |
| 1486 | + "http://localhost:8088/sso", message_id="id1" |
| 1487 | + ) |
| 1488 | + msg_str = str(req) |
1459 | 1489 |
|
| 1490 | + info = self.client.apply_binding( |
| 1491 | + BINDING_HTTP_REDIRECT, |
| 1492 | + msg_str, |
| 1493 | + destination="", |
| 1494 | + relay_state="relay2", |
| 1495 | + sign=True, |
| 1496 | + sigalg=SIG_RSA_SHA256, |
| 1497 | + ) |
1460 | 1498 | loc = info["headers"][0][1] |
1461 | 1499 | qs = parse.parse_qs(loc[1:]) |
1462 | | - assert _leq(qs.keys(), |
1463 | | - ['SigAlg', 'SAMLRequest', 'RelayState', 'Signature']) |
1464 | 1500 |
|
1465 | | - assert verify_redirect_signature(list_values2simpletons(qs), |
1466 | | - self.client.sec.sec_backend) |
| 1501 | + expected_query_params = ['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'] |
1467 | 1502 |
|
1468 | | - res = self.server.parse_authn_request(qs["SAMLRequest"][0], |
1469 | | - BINDING_HTTP_REDIRECT) |
| 1503 | + assert _leq(qs.keys(), expected_query_params) |
| 1504 | + assert all(len(qs[k]) == 1 for k in expected_query_params) |
| 1505 | + assert qs["SigAlg"] == [SIG_RSA_SHA256] |
| 1506 | + assert verify_redirect_signature( |
| 1507 | + list_values2simpletons(qs), self.client.sec.sec_backend |
| 1508 | + ) |
| 1509 | + |
| 1510 | + res = self.server.parse_authn_request( |
| 1511 | + qs["SAMLRequest"][0], BINDING_HTTP_REDIRECT |
| 1512 | + ) |
1470 | 1513 |
|
1471 | 1514 | def test_do_logout_signed_redirect(self): |
1472 | 1515 | conf = config.SPConfig() |
|
0 commit comments