7
7
import json
8
8
import datetime
9
9
import pytz
10
+ from jose import jwt
11
+ import time
10
12
11
13
from opentok import OpenTok , Archive , ArchiveList , OutputModes , __version__
12
14
@@ -41,7 +43,12 @@ def test_start_archive(self):
41
43
42
44
archive = self .opentok .start_archive (self .session_id )
43
45
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 ))
45
52
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
46
53
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
47
54
# non-deterministic json encoding. have to decode to test it properly
@@ -92,7 +99,8 @@ def test_start_archive_with_name(self):
92
99
93
100
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ))
94
101
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
+
96
104
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
97
105
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
98
106
# non-deterministic json encoding. have to decode to test it properly
@@ -141,7 +149,12 @@ def test_start_voice_archive(self):
141
149
142
150
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), has_video = False )
143
151
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 ))
145
158
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
146
159
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
147
160
# non-deterministic json encoding. have to decode to test it properly
@@ -192,7 +205,12 @@ def test_start_individual_archive(self):
192
205
193
206
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .individual )
194
207
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 ))
196
214
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
197
215
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
198
216
# non-deterministic json encoding. have to decode to test it properly
@@ -244,7 +262,12 @@ def test_start_composed_archive(self):
244
262
245
263
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .composed )
246
264
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 ))
248
271
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
249
272
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
250
273
# non-deterministic json encoding. have to decode to test it properly
@@ -297,7 +320,12 @@ def test_stop_archive(self):
297
320
298
321
archive = self .opentok .stop_archive (archive_id )
299
322
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 ))
301
329
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
302
330
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
303
331
expect (archive ).to .be .an (Archive )
@@ -324,7 +352,12 @@ def test_delete_archive(self):
324
352
325
353
self .opentok .delete_archive (archive_id )
326
354
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 ))
328
361
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
329
362
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
330
363
@@ -353,7 +386,12 @@ def test_find_archive(self):
353
386
354
387
archive = self .opentok .get_archive (archive_id )
355
388
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 ))
357
395
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
358
396
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
359
397
expect (archive ).to .be .an (Archive )
@@ -468,7 +506,12 @@ def test_find_archives(self):
468
506
469
507
archive_list = self .opentok .get_archives ()
470
508
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 ))
472
515
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
473
516
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
474
517
expect (archive_list ).to .be .an (ArchiveList )
@@ -528,7 +571,12 @@ def test_find_archives_with_offset(self):
528
571
529
572
archive_list = self .opentok .get_archives (offset = 3 )
530
573
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 ))
532
580
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
533
581
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
534
582
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -578,7 +626,12 @@ def test_find_archives_with_count(self):
578
626
579
627
archive_list = self .opentok .get_archives (count = 2 )
580
628
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 ))
582
635
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
583
636
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
584
637
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -654,7 +707,12 @@ def test_find_archives_with_offset_and_count(self):
654
707
655
708
archive_list = self .opentok .get_archives (count = 4 , offset = 2 )
656
709
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 ))
658
716
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
659
717
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
660
718
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
0 commit comments