@@ -491,6 +491,56 @@ def test_handlers(self):
491
491
body = context .get (path ).body .read ()
492
492
self .assertTrue (isatom (body ))
493
493
494
+ def urllib2_insert_cookie_handler (url , message , ** kwargs ):
495
+ method = message ['method' ].lower ()
496
+ data = message .get ('body' , b"" ) if method == 'post' else None
497
+ headers = dict (message .get ('headers' , []))
498
+ req = Request (url , data , headers )
499
+ try :
500
+ # If running Python 2.7.9+, disable SSL certificate validation
501
+ if sys .version_info >= (2 , 7 , 9 ):
502
+ response = urlopen (req , context = ssl ._create_unverified_context ())
503
+ else :
504
+ response = urlopen (req )
505
+ except HTTPError as response :
506
+ pass # Propagate HTTP errors via the returned response message
507
+
508
+ # Mimic the insertion of 3rd party cookies into the response.
509
+ # An example is "sticky session"/"insert cookie" persistence
510
+ # of a load balancer for a SHC.
511
+ header_list = [(k , v ) for k , v in response .info ().items ()]
512
+ header_list .append (("Set-Cookie" , "BIGipServer_splunk-shc-8089=1234567890.12345.0000; path=/; Httponly; Secure" ))
513
+ header_list .append (("Set-Cookie" , "home_made=yummy" ))
514
+
515
+ return {
516
+ 'status' : response .code ,
517
+ 'reason' : response .msg ,
518
+ 'headers' : header_list ,
519
+ 'body' : BytesIO (response .read ())
520
+ }
521
+
522
+ class TestCookiePersistence (testlib .SDKTestCase ):
523
+ # Verify persistence of 3rd party inserted cookies.
524
+ def test_3rdPartyInsertedCookiePersistence (self ):
525
+ paths = ["/services" , "authentication/users" ,
526
+ "search/jobs" ]
527
+ logging .debug ("Connecting with urllib2_insert_cookie_handler %s" , urllib2_insert_cookie_handler )
528
+ context = binding .connect (
529
+ handler = urllib2_insert_cookie_handler ,
530
+ ** self .opts .kwargs )
531
+
532
+ persisted_cookies = context .get_cookies ()
533
+
534
+ splunk_token_found = False
535
+ for k , v in persisted_cookies .items ():
536
+ if k [:8 ] == "splunkd_" :
537
+ splunk_token_found = True
538
+ break
539
+
540
+ self .assertEqual (splunk_token_found , True )
541
+ self .assertEqual (persisted_cookies ['BIGipServer_splunk-shc-8089' ], "1234567890.12345.0000" )
542
+ self .assertEqual (persisted_cookies ['home_made' ], "yummy" )
543
+
494
544
@pytest .mark .smoke
495
545
class TestLogout (BindingTestCase ):
496
546
def test_logout (self ):
0 commit comments