77import json
88import datetime
99import pytz
10+ from jose import jwt
11+ import time
1012
1113from opentok import OpenTok , Archive , ArchiveList , OutputModes , __version__
1214
@@ -41,7 +43,12 @@ def test_start_archive(self):
4143
4244 archive = self .opentok .start_archive (self .session_id )
4345
44- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
46+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
47+ expect (claims [u ('iss' )]).to .equal (self .api_key )
48+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
49+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
50+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
51+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
4552 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
4653 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
4754 # non-deterministic json encoding. have to decode to test it properly
@@ -92,7 +99,8 @@ def test_start_archive_with_name(self):
9299
93100 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ))
94101
95- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
102+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
103+
96104 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
97105 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
98106 # non-deterministic json encoding. have to decode to test it properly
@@ -141,7 +149,12 @@ def test_start_voice_archive(self):
141149
142150 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), has_video = False )
143151
144- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
152+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
153+ expect (claims [u ('iss' )]).to .equal (self .api_key )
154+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
155+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
156+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
157+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
145158 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
146159 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
147160 # non-deterministic json encoding. have to decode to test it properly
@@ -192,7 +205,12 @@ def test_start_individual_archive(self):
192205
193206 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .individual )
194207
195- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
208+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
209+ expect (claims [u ('iss' )]).to .equal (self .api_key )
210+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
211+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
212+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
213+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
196214 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
197215 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
198216 # non-deterministic json encoding. have to decode to test it properly
@@ -244,7 +262,12 @@ def test_start_composed_archive(self):
244262
245263 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .composed )
246264
247- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
265+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
266+ expect (claims [u ('iss' )]).to .equal (self .api_key )
267+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
268+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
269+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
270+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
248271 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
249272 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
250273 # non-deterministic json encoding. have to decode to test it properly
@@ -297,7 +320,12 @@ def test_stop_archive(self):
297320
298321 archive = self .opentok .stop_archive (archive_id )
299322
300- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
323+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
324+ expect (claims [u ('iss' )]).to .equal (self .api_key )
325+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
326+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
327+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
328+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
301329 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
302330 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
303331 expect (archive ).to .be .an (Archive )
@@ -324,7 +352,12 @@ def test_delete_archive(self):
324352
325353 self .opentok .delete_archive (archive_id )
326354
327- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
355+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
356+ expect (claims [u ('iss' )]).to .equal (self .api_key )
357+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
358+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
359+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
360+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
328361 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
329362 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
330363
@@ -353,7 +386,12 @@ def test_find_archive(self):
353386
354387 archive = self .opentok .get_archive (archive_id )
355388
356- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
389+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
390+ expect (claims [u ('iss' )]).to .equal (self .api_key )
391+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
392+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
393+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
394+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
357395 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
358396 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
359397 expect (archive ).to .be .an (Archive )
@@ -468,7 +506,12 @@ def test_find_archives(self):
468506
469507 archive_list = self .opentok .get_archives ()
470508
471- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
509+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
510+ expect (claims [u ('iss' )]).to .equal (self .api_key )
511+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
512+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
513+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
514+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
472515 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
473516 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
474517 expect (archive_list ).to .be .an (ArchiveList )
@@ -528,7 +571,12 @@ def test_find_archives_with_offset(self):
528571
529572 archive_list = self .opentok .get_archives (offset = 3 )
530573
531- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
574+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
575+ expect (claims [u ('iss' )]).to .equal (self .api_key )
576+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
577+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
578+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
579+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
532580 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
533581 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
534582 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -578,7 +626,12 @@ def test_find_archives_with_count(self):
578626
579627 archive_list = self .opentok .get_archives (count = 2 )
580628
581- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
629+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
630+ expect (claims [u ('iss' )]).to .equal (self .api_key )
631+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
632+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
633+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
634+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
582635 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
583636 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
584637 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -654,7 +707,12 @@ def test_find_archives_with_offset_and_count(self):
654707
655708 archive_list = self .opentok .get_archives (count = 4 , offset = 2 )
656709
657- expect (httpretty .last_request ().headers [u ('x-tb-partner-auth' )]).to .equal (self .api_key + u (':' )+ self .api_secret )
710+ claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
711+ expect (claims [u ('iss' )]).to .equal (self .api_key )
712+ expect (claims [u ('ist' )]).to .equal (u ('project' ))
713+ expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
714+ expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
715+ expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
658716 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
659717 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
660718 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
0 commit comments