77import json
88import datetime
99import pytz
10- from jose import jwt
11- import time
10+ from .validate_jwt import validate_jwt_header
1211
1312from opentok import OpenTok , Archive , ArchiveList , OutputModes , __version__
1413
@@ -43,12 +42,7 @@ def test_start_archive(self):
4342
4443 archive = self .opentok .start_archive (self .session_id )
4544
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' )])
5246 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
5347 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
5448 # non-deterministic json encoding. have to decode to test it properly
@@ -99,12 +93,7 @@ def test_start_archive_with_name(self):
9993
10094 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ))
10195
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' )])
10897 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
10998 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
11099 # non-deterministic json encoding. have to decode to test it properly
@@ -153,12 +142,7 @@ def test_start_voice_archive(self):
153142
154143 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), has_video = False )
155144
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' )])
162146 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
163147 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
164148 # non-deterministic json encoding. have to decode to test it properly
@@ -209,12 +193,7 @@ def test_start_individual_archive(self):
209193
210194 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .individual )
211195
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' )])
218197 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
219198 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
220199 # non-deterministic json encoding. have to decode to test it properly
@@ -266,12 +245,7 @@ def test_start_composed_archive(self):
266245
267246 archive = self .opentok .start_archive (self .session_id , name = u ('ARCHIVE NAME' ), output_mode = OutputModes .composed )
268247
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' )])
275249 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
276250 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
277251 # non-deterministic json encoding. have to decode to test it properly
@@ -324,12 +298,7 @@ def test_stop_archive(self):
324298
325299 archive = self .opentok .stop_archive (archive_id )
326300
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' )])
333302 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
334303 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
335304 expect (archive ).to .be .an (Archive )
@@ -356,12 +325,7 @@ def test_delete_archive(self):
356325
357326 self .opentok .delete_archive (archive_id )
358327
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' )])
365329 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
366330 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
367331
@@ -390,12 +354,7 @@ def test_find_archive(self):
390354
391355 archive = self .opentok .get_archive (archive_id )
392356
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' )])
399358 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
400359 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
401360 expect (archive ).to .be .an (Archive )
@@ -510,12 +469,7 @@ def test_find_archives(self):
510469
511470 archive_list = self .opentok .get_archives ()
512471
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' )])
519473 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
520474 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
521475 expect (archive_list ).to .be .an (ArchiveList )
@@ -575,12 +529,7 @@ def test_find_archives_with_offset(self):
575529
576530 archive_list = self .opentok .get_archives (offset = 3 )
577531
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' )])
584533 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
585534 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
586535 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -630,12 +579,7 @@ def test_find_archives_with_count(self):
630579
631580 archive_list = self .opentok .get_archives (count = 2 )
632581
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' )])
639583 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
640584 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
641585 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
@@ -711,12 +655,7 @@ def test_find_archives_with_offset_and_count(self):
711655
712656 archive_list = self .opentok .get_archives (count = 4 , offset = 2 )
713657
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' )])
720659 expect (httpretty .last_request ().headers [u ('user-agent' )]).to .contain (u ('OpenTok-Python-SDK/' )+ __version__ )
721660 expect (httpretty .last_request ().headers [u ('content-type' )]).to .equal (u ('application/json' ))
722661 expect (httpretty .last_request ()).to .have .property ("querystring" ).being .equal ({
0 commit comments