@@ -619,7 +619,26 @@ def setup_class(self):
619
619
def test_do_authn (self ):
620
620
binding = BINDING_HTTP_REDIRECT
621
621
response_binding = BINDING_HTTP_POST
622
- sid , auth_binding , http_args = self .client .prepare_for_authenticate (
622
+ sid , http_args = self .client .prepare_for_authenticate (
623
+ IDP , "http://www.example.com/relay_state" ,
624
+ binding = binding , response_binding = response_binding )
625
+
626
+ assert isinstance (sid , basestring )
627
+ assert len (http_args ) == 4
628
+ assert http_args ["headers" ][0 ][0 ] == "Location"
629
+ assert http_args ["data" ] == []
630
+ redirect_url = http_args ["headers" ][0 ][1 ]
631
+ _ , _ , _ , _ , qs , _ = urlparse .urlparse (redirect_url )
632
+ qs_dict = urlparse .parse_qs (qs )
633
+ req = self .server .parse_authn_request (qs_dict ["SAMLRequest" ][0 ],
634
+ binding )
635
+ resp_args = self .server .response_args (req .message , [response_binding ])
636
+ assert resp_args ["binding" ] == response_binding
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 (
623
642
IDP , "http://www.example.com/relay_state" ,
624
643
binding = binding , response_binding = response_binding )
625
644
@@ -670,7 +689,40 @@ def test_logout_1(self):
670
689
def test_post_sso (self ):
671
690
binding = BINDING_HTTP_POST
672
691
response_binding = BINDING_HTTP_POST
673
- sid , auth_binding , http_args = self .client .prepare_for_authenticate (
692
+ sid , http_args = self .client .prepare_for_authenticate (
693
+ "urn:mace:example.com:saml:roland:idp" , relay_state = "really" ,
694
+ binding = binding , response_binding = response_binding )
695
+ _dic = unpack_form (http_args ["data" ][3 ])
696
+
697
+ req = self .server .parse_authn_request (_dic ["SAMLRequest" ], binding )
698
+ resp_args = self .server .response_args (req .message , [response_binding ])
699
+ assert resp_args ["binding" ] == response_binding
700
+
701
+ # Normally a response would now be sent back to the users web client
702
+ # Here I fake what the client will do
703
+ # create the form post
704
+
705
+ http_args ["data" ] = urllib .urlencode (_dic )
706
+ http_args ["method" ] = "POST"
707
+ http_args ["dummy" ] = _dic ["SAMLRequest" ]
708
+ http_args ["headers" ] = [('Content-type' ,
709
+ 'application/x-www-form-urlencoded' )]
710
+
711
+ response = self .client .send (** http_args )
712
+ print response .text
713
+ _dic = unpack_form (response .text [3 ], "SAMLResponse" )
714
+ resp = self .client .parse_authn_request_response (_dic ["SAMLResponse" ],
715
+ BINDING_HTTP_POST ,
716
+ {sid : "/" })
717
+ ac = resp .assertion .authn_statement [0 ].authn_context
718
+ assert ac .authenticating_authority [0 ].text == \
719
+ 'http://www.example.com/login'
720
+ assert ac .authn_context_class_ref .text == INTERNETPROTOCOLPASSWORD
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 (
674
726
"urn:mace:example.com:saml:roland:idp" , relay_state = "really" ,
675
727
binding = binding , response_binding = response_binding )
676
728
_dic = unpack_form (http_args ["data" ][3 ])
@@ -711,4 +763,4 @@ def test_post_sso(self):
711
763
if __name__ == "__main__" :
712
764
tc = TestClient ()
713
765
tc .setup_class ()
714
- tc .test_sign_then_encrypt_assertion_advice ()
766
+ tc .test_sign_then_encrypt_assertion_advice ()
0 commit comments