7
7
import json
8
8
import datetime
9
9
import pytz
10
- from jose import jwt
11
- import time
10
+ from .validate_jwt import validate_jwt_header
12
11
13
12
from opentok import OpenTok , Archive , ArchiveList , OutputModes , __version__
14
13
@@ -43,12 +42,7 @@ def test_start_archive(self):
43
42
44
43
archive = self .opentok .start_archive (self .session_id )
45
44
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
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
52
46
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
53
47
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
54
48
# non-deterministic json encoding. have to decode to test it properly
@@ -99,12 +93,7 @@ def test_start_archive_with_name(self):
99
93
100
94
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ))
101
95
102
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
103
- expect (claims [u ('iss' )]).to .equal (self .api_key )
104
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
105
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
106
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
107
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
96
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
108
97
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
109
98
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
110
99
# non-deterministic json encoding. have to decode to test it properly
@@ -153,12 +142,7 @@ def test_start_voice_archive(self):
153
142
154
143
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), has_video = False )
155
144
156
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
157
- expect (claims [u ('iss' )]).to .equal (self .api_key )
158
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
159
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
160
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
161
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
145
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
162
146
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
163
147
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
164
148
# non-deterministic json encoding. have to decode to test it properly
@@ -209,12 +193,7 @@ def test_start_individual_archive(self):
209
193
210
194
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .individual )
211
195
212
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
213
- expect (claims [u ('iss' )]).to .equal (self .api_key )
214
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
215
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
216
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
217
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
196
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
218
197
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
219
198
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
220
199
# non-deterministic json encoding. have to decode to test it properly
@@ -266,12 +245,7 @@ def test_start_composed_archive(self):
266
245
267
246
archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .composed )
268
247
269
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
270
- expect (claims [u ('iss' )]).to .equal (self .api_key )
271
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
272
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
273
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
274
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
248
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
275
249
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
276
250
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
277
251
# non-deterministic json encoding. have to decode to test it properly
@@ -324,12 +298,7 @@ def test_stop_archive(self):
324
298
325
299
archive = self .opentok .stop_archive (archive_id )
326
300
327
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
328
- expect (claims [u ('iss' )]).to .equal (self .api_key )
329
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
330
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
331
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
332
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
301
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
333
302
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
334
303
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
335
304
expect (archive ).to .be .an (Archive )
@@ -356,12 +325,7 @@ def test_delete_archive(self):
356
325
357
326
self .opentok .delete_archive (archive_id )
358
327
359
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
360
- expect (claims [u ('iss' )]).to .equal (self .api_key )
361
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
362
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
363
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
364
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
328
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
365
329
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
366
330
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
367
331
@@ -390,12 +354,7 @@ def test_find_archive(self):
390
354
391
355
archive = self .opentok .get_archive (archive_id )
392
356
393
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
394
- expect (claims [u ('iss' )]).to .equal (self .api_key )
395
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
396
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
397
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
398
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
357
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
399
358
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
400
359
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
401
360
expect (archive ).to .be .an (Archive )
@@ -510,12 +469,7 @@ def test_find_archives(self):
510
469
511
470
archive_list = self .opentok .get_archives ()
512
471
513
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
514
- expect (claims [u ('iss' )]).to .equal (self .api_key )
515
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
516
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
517
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
518
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
472
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
519
473
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
520
474
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
521
475
expect (archive_list ).to .be .an (ArchiveList )
@@ -575,12 +529,7 @@ def test_find_archives_with_offset(self):
575
529
576
530
archive_list = self .opentok .get_archives (offset = 3 )
577
531
578
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
579
- expect (claims [u ('iss' )]).to .equal (self .api_key )
580
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
581
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
582
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
583
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
532
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
584
533
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
585
534
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
586
535
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -630,12 +579,7 @@ def test_find_archives_with_count(self):
630
579
631
580
archive_list = self .opentok .get_archives (count = 2 )
632
581
633
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
634
- expect (claims [u ('iss' )]).to .equal (self .api_key )
635
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
636
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
637
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
638
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
582
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
639
583
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
640
584
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
641
585
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -711,12 +655,7 @@ def test_find_archives_with_offset_and_count(self):
711
655
712
656
archive_list = self .opentok .get_archives (count = 4 , offset = 2 )
713
657
714
- claims = jwt .decode (httpretty .last_request ().headers [u ('x-tb-opentok-auth' )], self .api_secret , algorithms = [u ('HS256' )])
715
- expect (claims [u ('iss' )]).to .equal (self .api_key )
716
- expect (claims [u ('ist' )]).to .equal (u ('project' ))
717
- expect (float (claims [u ('exp' )])).to .be .greater_than (float (time .time ()))
718
- expect (float (claims [u ('jti' )])).to .be .greater_than_or_equal_to (float (0 ))
719
- expect (float (claims [u ('jti' )])).to .be .lower_than (float (1 ))
658
+ validate_jwt_header (self , httpretty .last_request ().headers [u ('x-tb-opentok-auth' )])
720
659
expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
721
660
expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
722
661
expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
0 commit comments