Skip to content

Commit e426816

Browse files
author
Roland Hedberg
committed
When not a SAML class instance adding an element is slightly more complex.
1 parent ab5c008 commit e426816

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

tests/test_51_client.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from saml2.client import Saml2Client
2020
from saml2.config import SPConfig
2121
from saml2.response import LogoutResponse
22-
from saml2.saml import NAMEID_FORMAT_PERSISTENT
22+
from saml2.saml import NAMEID_FORMAT_PERSISTENT, EncryptedAssertion
2323
from saml2.saml import NAMEID_FORMAT_TRANSIENT
2424
from saml2.saml import NameID
2525
from saml2.server import Server
26-
from saml2.sigver import pre_encryption_part
26+
from saml2.sigver import pre_encryption_part, rm_xmltag
2727
from saml2.s_utils import do_attribute_statement
2828
from saml2.s_utils import factory
2929
from saml2.time_util import in_a_while
@@ -38,6 +38,23 @@
3838
}
3939

4040

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+
4158
def for_me(condition, me):
4259
for restriction in condition.audience_restriction:
4360
audience = restriction.audience
@@ -439,21 +456,25 @@ def test_sign_then_encrypt_assertion2(self):
439456
assertion.id, _sec.my_cert, 1)
440457

441458
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,
444460
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)
447463

448464
response = sigver.response_factory(
449465
in_response_to="_012345",
450466
destination="https://www.example.com",
451467
status=s_utils.success_status_factory(),
452468
issuer=self.server._issuer(),
453-
assertion=_ass
469+
encrypted_assertion=EncryptedAssertion()
454470
)
455471

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,
457478
pre_encryption_part())
458479

459480
#seresp = samlp.response_from_string(enctext)

0 commit comments

Comments
 (0)