@@ -736,6 +736,63 @@ def test_response_8(self):
736
736
737
737
self .verify_authn_response (idp , authn_response , _client , ava_verify )
738
738
739
+ def test_response_no_name_id (self ):
740
+ """ Test that the SP client can parse an authentication response
741
+ from an IdP that does not contain a <NameID> element."""
742
+
743
+ conf = config .SPConfig ()
744
+ conf .load_file ("server_conf" )
745
+ client = Saml2Client (conf )
746
+
747
+ # Use the same approach as the other tests for mocking up
748
+ # an authentication response to parse.
749
+ idp , ava , ava_verify , nameid_policy = (
750
+ self .setup_verify_authn_response ()
751
+ )
752
+
753
+ # Mock up an authentication response but do not encrypt it
754
+ # nor sign it since below we will modify it directly. Note that
755
+ # setting name_id to None still results in a response that includes
756
+ # a <NameID> element.
757
+ resp = self .server .create_authn_response (
758
+ identity = ava ,
759
+ in_response_to = "id1" ,
760
+ destination = "http://lingon.catalogix.se:8087/" ,
761
+ sp_entity_id = "urn:mace:example.com:saml:roland:sp" ,
762
+ name_id = None ,
763
+
764
+ authn = AUTHN ,
765
+ sign_response = False ,
766
+ sign_assertion = False ,
767
+ encrypt_assertion = False ,
768
+ encrypt_assertion_self_contained = False
769
+ )
770
+
771
+ # The create_authn_response method above will return an instance
772
+ # of saml2.samlp.Response when neither encrypting nor signing and
773
+ # so we can remove the <NameID> element directly.
774
+ resp .assertion .subject .name_id = None
775
+
776
+ # Assert that the response does not contain a NameID element so that
777
+ # the parsing below is a fair test.
778
+ assert str (resp ).find ("NameID" ) == - 1
779
+
780
+ # Cast the response to a string and encode it to mock up the payload
781
+ # the SP client is expected to receive via HTTP POST binding.
782
+ resp_str = encode_fn (str (resp ).encode ())
783
+
784
+ # We do not need the client to verify a signature for this test.
785
+ client .want_assertions_signed = False
786
+ client .want_response_signed = False
787
+
788
+ # Parse the authentication response that does not include a <NameID>.
789
+ authn_response = client .parse_authn_request_response (
790
+ resp_str , BINDING_HTTP_POST ,
791
+ {"id1" : "http://foo.example.com/service" })
792
+
793
+ # A successful test is parsing the response.
794
+ assert authn_response is not None
795
+
739
796
def setup_verify_authn_response (self ):
740
797
idp = "urn:mace:example.com:saml:roland:idp"
741
798
ava = {"givenName" : ["Derek" ], "sn" : ["Jeter" ],
0 commit comments