@@ -635,6 +635,26 @@ def test_do_authn(self):
635
635
resp_args = self .server .response_args (req .message , [response_binding ])
636
636
assert resp_args ["binding" ] == response_binding
637
637
638
+ def test_do_negotiated_authn (self ):
639
+ binding = BINDING_HTTP_REDIRECT
640
+ response_binding = BINDING_HTTP_POST
641
+ sid , auth_binding , http_args = self .client .prepare_for_negotiated_authenticate (
642
+ IDP , "http://www.example.com/relay_state" ,
643
+ binding = binding , response_binding = response_binding )
644
+
645
+ assert binding == auth_binding
646
+ assert isinstance (sid , basestring )
647
+ assert len (http_args ) == 4
648
+ assert http_args ["headers" ][0 ][0 ] == "Location"
649
+ assert http_args ["data" ] == []
650
+ redirect_url = http_args ["headers" ][0 ][1 ]
651
+ _ , _ , _ , _ , qs , _ = urlparse .urlparse (redirect_url )
652
+ qs_dict = urlparse .parse_qs (qs )
653
+ req = self .server .parse_authn_request (qs_dict ["SAMLRequest" ][0 ],
654
+ binding )
655
+ resp_args = self .server .response_args (req .message , [response_binding ])
656
+ assert resp_args ["binding" ] == response_binding
657
+
638
658
def test_do_attribute_query (self ):
639
659
response = self .client .do_attribute_query (
640
660
IDP , "_e7b68a04488f715cda642fbdd90099f5" ,
@@ -699,6 +719,41 @@ def test_post_sso(self):
699
719
'http://www.example.com/login'
700
720
assert ac .authn_context_class_ref .text == INTERNETPROTOCOLPASSWORD
701
721
722
+ def test_negotiated_post_sso (self ):
723
+ binding = BINDING_HTTP_POST
724
+ response_binding = BINDING_HTTP_POST
725
+ sid , auth_binding , http_args = self .client .prepare_for_negotiated_authenticate (
726
+ "urn:mace:example.com:saml:roland:idp" , relay_state = "really" ,
727
+ binding = binding , response_binding = response_binding )
728
+ _dic = unpack_form (http_args ["data" ][3 ])
729
+
730
+ assert binding == auth_binding
731
+
732
+ req = self .server .parse_authn_request (_dic ["SAMLRequest" ], binding )
733
+ resp_args = self .server .response_args (req .message , [response_binding ])
734
+ assert resp_args ["binding" ] == response_binding
735
+
736
+ # Normally a response would now be sent back to the users web client
737
+ # Here I fake what the client will do
738
+ # create the form post
739
+
740
+ http_args ["data" ] = urllib .urlencode (_dic )
741
+ http_args ["method" ] = "POST"
742
+ http_args ["dummy" ] = _dic ["SAMLRequest" ]
743
+ http_args ["headers" ] = [('Content-type' ,
744
+ 'application/x-www-form-urlencoded' )]
745
+
746
+ response = self .client .send (** http_args )
747
+ print response .text
748
+ _dic = unpack_form (response .text [3 ], "SAMLResponse" )
749
+ resp = self .client .parse_authn_request_response (_dic ["SAMLResponse" ],
750
+ BINDING_HTTP_POST ,
751
+ {sid : "/" })
752
+ ac = resp .assertion .authn_statement [0 ].authn_context
753
+ assert ac .authenticating_authority [0 ].text == \
754
+ 'http://www.example.com/login'
755
+ assert ac .authn_context_class_ref .text == INTERNETPROTOCOLPASSWORD
756
+
702
757
703
758
# if __name__ == "__main__":
704
759
# tc = TestClient()
@@ -708,4 +763,4 @@ def test_post_sso(self):
708
763
if __name__ == "__main__" :
709
764
tc = TestClient ()
710
765
tc .setup_class ()
711
- tc .test_sign_then_encrypt_assertion_advice ()
766
+ tc .test_sign_then_encrypt_assertion_advice ()
0 commit comments