8
8
import uuid
9
9
10
10
from saml2 .cert import OpenSSLWrapper
11
- from saml2 .sigver import make_temp , EncryptError , CertificateError
11
+ from saml2 .sigver import make_temp , DecryptError , EncryptError , CertificateError
12
12
from saml2 .assertion import Policy
13
13
from saml2 .authn_context import INTERNETPROTOCOLPASSWORD
14
14
from saml2 .saml import NameID , NAMEID_FORMAT_TRANSIENT
34
34
from pathutils import full_path
35
35
import saml2 .xmldsig as ds
36
36
37
+
37
38
nid = NameID (name_qualifier = "foo" , format = NAMEID_FORMAT_TRANSIENT ,
38
39
text = "123456" )
39
40
@@ -171,7 +172,7 @@ def test_assertion(self):
171
172
assert attr1 .attribute_value [0 ].text == "Derek"
172
173
assert attr0 .friendly_name == "sn"
173
174
assert attr0 .attribute_value [0 ].text == "Jeter"
174
- #
175
+
175
176
subject = assertion .subject
176
177
assert _eq (subject .keyswv (), ["text" , "name_id" ])
177
178
assert subject .text == "_aaa"
@@ -613,9 +614,11 @@ def test_encrypted_signed_response_2(self):
613
614
614
615
decr_text_old = copy .deepcopy ("%s" % signed_resp )
615
616
616
- decr_text = self .server .sec .decrypt (signed_resp , self .client .config .encryption_keypairs [0 ]["key_file" ])
617
-
618
- assert decr_text == decr_text_old
617
+ with raises (DecryptError ):
618
+ decr_text = self .server .sec .decrypt (
619
+ signed_resp ,
620
+ self .client .config .encryption_keypairs [0 ]["key_file" ],
621
+ )
619
622
620
623
decr_text = self .server .sec .decrypt (signed_resp , self .client .config .encryption_keypairs [1 ]["key_file" ])
621
624
@@ -958,7 +961,7 @@ def test_encrypted_response_7(self):
958
961
self .verify_advice_assertion (resp , decr_text_2 )
959
962
960
963
def test_encrypted_response_8 (self ):
961
- try :
964
+ with raises ( EncryptError ) :
962
965
_resp = self .server .create_authn_response (
963
966
self .ava ,
964
967
"id12" , # in_response_to
@@ -973,13 +976,8 @@ def test_encrypted_response_8(self):
973
976
encrypt_cert_advice = "whatever" ,
974
977
encrypt_cert_assertion = "whatever"
975
978
)
976
- assert False , "Must throw an exception"
977
- except EncryptError as ex :
978
- pass
979
- except Exception as ex :
980
- assert False , "Wrong exception!"
981
979
982
- try :
980
+ with raises ( EncryptError ) :
983
981
_resp = self .server .create_authn_response (
984
982
self .ava ,
985
983
"id12" , # in_response_to
@@ -993,13 +991,8 @@ def test_encrypted_response_8(self):
993
991
pefim = True ,
994
992
encrypt_cert_advice = "whatever" ,
995
993
)
996
- assert False , "Must throw an exception"
997
- except EncryptError as ex :
998
- pass
999
- except Exception as ex :
1000
- assert False , "Wrong exception!"
1001
994
1002
- try :
995
+ with raises ( EncryptError ) :
1003
996
_resp = self .server .create_authn_response (
1004
997
self .ava ,
1005
998
"id12" , # in_response_to
@@ -1013,15 +1006,10 @@ def test_encrypted_response_8(self):
1013
1006
encrypted_advice_attributes = False ,
1014
1007
encrypt_cert_assertion = "whatever"
1015
1008
)
1016
- assert False , "Must throw an exception"
1017
- except EncryptError as ex :
1018
- pass
1019
- except Exception as ex :
1020
- assert False , "Wrong exception!"
1021
1009
1022
1010
_server = Server ("idp_conf_verify_cert" )
1023
1011
1024
- try :
1012
+ with raises ( CertificateError ) :
1025
1013
_resp = _server .create_authn_response (
1026
1014
self .ava ,
1027
1015
"id12" , # in_response_to
@@ -1036,13 +1024,8 @@ def test_encrypted_response_8(self):
1036
1024
encrypt_cert_advice = "whatever" ,
1037
1025
encrypt_cert_assertion = "whatever"
1038
1026
)
1039
- assert False , "Must throw an exception"
1040
- except CertificateError as ex :
1041
- pass
1042
- except Exception as ex :
1043
- assert False , "Wrong exception!"
1044
1027
1045
- try :
1028
+ with raises ( CertificateError ) :
1046
1029
_resp = _server .create_authn_response (
1047
1030
self .ava ,
1048
1031
"id12" , # in_response_to
@@ -1056,13 +1039,8 @@ def test_encrypted_response_8(self):
1056
1039
pefim = True ,
1057
1040
encrypt_cert_advice = "whatever" ,
1058
1041
)
1059
- assert False , "Must throw an exception"
1060
- except CertificateError as ex :
1061
- pass
1062
- except Exception as ex :
1063
- assert False , "Wrong exception!"
1064
1042
1065
- try :
1043
+ with raises ( CertificateError ) :
1066
1044
_resp = _server .create_authn_response (
1067
1045
self .ava ,
1068
1046
"id12" , # in_response_to
@@ -1076,11 +1054,6 @@ def test_encrypted_response_8(self):
1076
1054
encrypted_advice_attributes = False ,
1077
1055
encrypt_cert_assertion = "whatever"
1078
1056
)
1079
- assert False , "Must throw an exception"
1080
- except CertificateError as ex :
1081
- pass
1082
- except Exception as ex :
1083
- assert False , "Wrong exception!"
1084
1057
1085
1058
def test_encrypted_response_9 (self ):
1086
1059
_server = Server ("idp_conf_sp_no_encrypt" )
@@ -1715,9 +1688,11 @@ def test_encrypted_signed_response_2(self):
1715
1688
1716
1689
decr_text_old = copy .deepcopy ("%s" % signed_resp )
1717
1690
1718
- decr_text = self .server .sec .decrypt (signed_resp , self .client .config .encryption_keypairs [0 ]["key_file" ])
1719
-
1720
- assert decr_text == decr_text_old
1691
+ with raises (DecryptError ):
1692
+ decr_text = self .server .sec .decrypt (
1693
+ signed_resp ,
1694
+ self .client .config .encryption_keypairs [0 ]["key_file" ],
1695
+ )
1721
1696
1722
1697
decr_text = self .server .sec .decrypt (signed_resp , self .client .config .encryption_keypairs [1 ]["key_file" ])
1723
1698
0 commit comments