1111 ResponseValidationError ,
1212 ResponseNameIDError ,
1313 ResponseConditionError ,
14- )
14+ )
1515
1616test_response = """<samlp:Response
1717 xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
6767 </samlp:Response>
6868"""
6969
70+
7071class TestResponse (object ):
72+
7173 def setUp (self ):
7274 fudge .clear_expectations ()
7375
@@ -89,12 +91,18 @@ def test__init__(self):
8991 from_string .with_args ('foo decoded response' , parser = fake_xmlparser )
9092 from_string .returns ('foo document' )
9193
94+ request_data = {
95+ 'http_host' : 'example.com' ,
96+ 'script_name' : 'index.html'
97+ }
98+
9299 res = Response (
100+ request_data = request_data ,
93101 response = 'foo response' ,
94102 signature = 'foo signature' ,
95103 _base64 = fake_base64 ,
96104 _etree = fake_etree ,
97- )
105+ )
98106
99107 eq (res ._document , 'foo document' )
100108 eq (res ._signature , 'foo signature' )
@@ -105,7 +113,7 @@ def test_get_name_id_simple(self):
105113 res = Response (
106114 response = encoded_response ,
107115 signature = None ,
108- )
116+ )
109117 name_id = res .name_id
110118
111119 eq ('3f7b3dcf-1674-4ecd-92c8-1544f346baf8' , name_id )
@@ -173,18 +181,16 @@ def test_get_name_id_multiple(self):
173181 res = Response (
174182 response = encoded_response ,
175183 signature = None ,
176- )
184+ )
177185 msg = assert_raises (
178186 ResponseNameIDError ,
179187 res ._get_name_id ,
180- )
188+ )
181189
182190 eq (
183- str (msg ),
184- ('There was a problem getting the name ID: Found more than one '
185- + 'name ID'
186- ),
187- )
191+ str (msg ), ('There was a problem getting the name ID:' +
192+ ' Found more than one name ID' ),
193+ )
188194
189195 @fudge .with_fakes
190196 def test_get_name_id_none (self ):
@@ -241,18 +247,18 @@ def test_get_name_id_none(self):
241247 res = Response (
242248 response = encoded_response ,
243249 signature = None ,
244- )
250+ )
245251 msg = assert_raises (
246252 ResponseNameIDError ,
247253 res ._get_name_id ,
248- )
254+ )
249255
250256 eq (
251257 str (msg ),
252258 ('There was a problem getting the name ID: Did not find a name '
253259 + 'ID'
254260 ),
255- )
261+ )
256262
257263 @fudge .with_fakes
258264 def test_is_valid_not_before_missing (self ):
@@ -312,20 +318,20 @@ def test_is_valid_not_before_missing(self):
312318 res = Response (
313319 response = encoded_response ,
314320 signature = 'foo signature' ,
315- )
321+ )
316322
317323 fake_verifier = fudge .Fake (
318324 'verifier' ,
319325 callable = True ,
320- )
326+ )
321327 fake_verifier .times_called (1 )
322328 fake_verifier .with_args (res ._document , 'foo signature' )
323329
324330 fake_verifier .returns (True )
325331
326332 msg = res .is_valid (
327333 _verifier = fake_verifier ,
328- )
334+ )
329335
330336 eq (msg , True )
331337
@@ -387,77 +393,77 @@ def test_is_valid_not_on_or_after_missing(self):
387393 res = Response (
388394 response = encoded_response ,
389395 signature = None ,
390- )
396+ )
391397 msg = assert_raises (
392398 ResponseConditionError ,
393399 res .is_valid ,
394- )
400+ )
395401
396- eq (str ( msg ),
397- ( 'There was a problem validating a condition: Did not find '
398- + 'NotOnOrAfter condition'
399- ),
400- )
402+ eq (
403+ str ( msg ),
404+ ( 'There was a problem validating a condition:' +
405+ ' Did not find NotOnOrAfter condition' ),
406+ )
401407
402408 @fudge .with_fakes
403409 def test_is_valid_current_time_earlier (self ):
404410 encoded_response = base64 .b64encode (test_response )
405411 res = Response (
406412 response = encoded_response ,
407413 signature = None ,
408- )
414+ )
409415
410416 def fake_clock ():
411417 return datetime (2004 , 12 , 05 , 9 , 16 , 45 , 462796 )
412418 msg = assert_raises (
413419 ResponseValidationError ,
414420 res .is_valid ,
415421 _clock = fake_clock ,
416- )
422+ )
417423
418- eq (str ( msg ),
419- ( 'There was a problem validating the response: Current time is '
420- + 'earlier than NotBefore condition'
421- ),
422- )
424+ eq (
425+ str ( msg ),
426+ ( 'There was a problem validating the response: Current time is ' +
427+ 'earlier than NotBefore condition' ),
428+ )
423429
424430 @fudge .with_fakes
425431 def test_is_valid_current_time_on_or_after (self ):
426432 encoded_response = base64 .b64encode (test_response )
427433 res = Response (
428434 response = encoded_response ,
429435 signature = None ,
430- )
436+ )
431437
432438 def fake_clock ():
433439 return datetime (2004 , 12 , 05 , 9 , 30 , 45 , 462796 )
434440 msg = assert_raises (
435441 ResponseValidationError ,
436442 res .is_valid ,
437443 _clock = fake_clock ,
438- )
444+ )
439445
440- eq (str ( msg ),
441- ( 'There was a problem validating the response: Current time is '
442- + 'on or after NotOnOrAfter condition'
443- ),
444- )
446+ eq (
447+ str ( msg ),
448+ ( 'There was a problem validating the response: Current time is ' +
449+ 'on or after NotOnOrAfter condition' ),
450+ )
445451
446452 @fudge .with_fakes
447453 def test_is_valid_simple (self ):
448454 encoded_response = base64 .b64encode (test_response )
449455 res = Response (
450456 response = encoded_response ,
451457 signature = 'foo signature' ,
452- )
458+ )
453459
454460 def fake_clock ():
455461 return datetime (2004 , 12 , 05 , 9 , 18 , 45 , 462796 )
456462
457463 fake_verifier = fudge .Fake (
458464 'verifier' ,
459465 callable = True ,
460- )
466+ )
461467 fake_verifier .times_called (1 )
462468 fake_verifier .with_args (res ._document , 'foo signature' )
463469
@@ -466,6 +472,6 @@ def fake_clock():
466472 msg = res .is_valid (
467473 _clock = fake_clock ,
468474 _verifier = fake_verifier ,
469- )
475+ )
470476
471477 eq (msg , True )
0 commit comments