|
19 | 19 | from saml2.client import Saml2Client
|
20 | 20 | from saml2.config import SPConfig
|
21 | 21 | from saml2.response import LogoutResponse
|
22 |
| -from saml2.saml import NAMEID_FORMAT_PERSISTENT |
| 22 | +from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion |
23 | 23 | from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
24 | 24 | from saml2.saml import NameID
|
25 | 25 | from saml2.server import Server
|
26 |
| -from saml2.sigver import pre_encryption_part |
| 26 | +from saml2.sigver import pre_encryption_part, rm_xmltag |
27 | 27 | from saml2.s_utils import do_attribute_statement
|
28 | 28 | from saml2.s_utils import factory
|
29 | 29 | from saml2.time_util import in_a_while
|
|
38 | 38 | }
|
39 | 39 |
|
40 | 40 |
|
| 41 | +def add_subelement(xmldoc, node_name, subelem): |
| 42 | + s = xmldoc.find(node_name) |
| 43 | + if s > 0: |
| 44 | + x = xmldoc.rindex("<", 0, s) |
| 45 | + tag = xmldoc[x+1:s-1] |
| 46 | + c = s+len(node_name) |
| 47 | + spaces = "" |
| 48 | + while xmldoc[c] == " ": |
| 49 | + spaces += " " |
| 50 | + c += 1 |
| 51 | + xmldoc = xmldoc.replace( |
| 52 | + "<%s:%s%s/>" % (tag, node_name, spaces), |
| 53 | + "<%s:%s%s>%s</%s:%s>" % (tag, node_name, spaces, subelem, tag, |
| 54 | + node_name)) |
| 55 | + |
| 56 | + return xmldoc |
| 57 | + |
41 | 58 | def for_me(condition, me):
|
42 | 59 | for restriction in condition.audience_restriction:
|
43 | 60 | audience = restriction.audience
|
@@ -439,21 +456,25 @@ def test_sign_then_encrypt_assertion2(self):
|
439 | 456 | assertion.id, _sec.my_cert, 1)
|
440 | 457 |
|
441 | 458 | sigass = _sec.sign_statement(assertion, class_name(assertion),
|
442 |
| - #key_file="pki/mykey.pem", |
443 |
| - key_file="test.key", |
| 459 | + key_file=self.client.sec.key_file, |
444 | 460 | node_id=assertion.id)
|
445 |
| - # Create an Assertion instance from the signed assertion |
446 |
| - _ass = saml.assertion_from_string(sigass) |
| 461 | + |
| 462 | + sigass = rm_xmltag(sigass) |
447 | 463 |
|
448 | 464 | response = sigver.response_factory(
|
449 | 465 | in_response_to="_012345",
|
450 | 466 | destination="https://www.example.com",
|
451 | 467 | status=s_utils.success_status_factory(),
|
452 | 468 | issuer=self.server._issuer(),
|
453 |
| - assertion=_ass |
| 469 | + encrypted_assertion=EncryptedAssertion() |
454 | 470 | )
|
455 | 471 |
|
456 |
| - enctext = _sec.crypto.encrypt_assertion(response, _sec.cert_file, |
| 472 | + xmldoc = "%s" % response |
| 473 | + # strangely enough I get different tags if I run this test separately |
| 474 | + # or as part of a bunch of tests. |
| 475 | + xmldoc = add_subelement(xmldoc, "EncryptedAssertion", sigass) |
| 476 | + |
| 477 | + enctext = _sec.crypto.encrypt_assertion(xmldoc, _sec.cert_file, |
457 | 478 | pre_encryption_part())
|
458 | 479 |
|
459 | 480 | #seresp = samlp.response_from_string(enctext)
|
|
0 commit comments