1212from decimal import Decimal
1313import random
1414import nacl
15+ import base64
1516
1617from pusher .pusher_client import PusherClient
1718from pusher .http import GET
@@ -36,11 +37,6 @@ def test_cluster_should_be_text(self):
3637
3738 self .assertRaises (TypeError , lambda : PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = 4 ))
3839
39- def test_encryption_master_key_should_be_text (self ):
40- PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = u'eu' , encryption_master_key = "8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY" )
41-
42- self .assertRaises (TypeError , lambda : PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True , cluster = 4 , encryption_master_key = 48762478647865374856347856888764 ))
43-
4440 def test_host_behaviour (self ):
4541 conf = PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , ssl = True )
4642 self .assertEqual (conf .host , u'api.pusherapp.com' , u'default host should be correct' )
@@ -143,12 +139,18 @@ def test_trigger_batch_success_case_2(self):
143139 def test_trigger_batch_with_mixed_channels_success_case (self ):
144140 json_dumped = u'{"message": "something"}'
145141
146- encryp_master_key = u'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY'
142+ master_key = b'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY'
143+ master_key_base64 = base64 .b64encode (master_key )
147144 event_name_2 = "my-event-2"
148145 chan_2 = "private-encrypted-2"
149146 payload = {"message" : "hello worlds" }
150147
151- pc = PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , encryption_master_key = encryp_master_key , ssl = True )
148+ pc = PusherClient (
149+ app_id = u'4' ,
150+ key = u'key' ,
151+ secret = u'secret' ,
152+ encryption_master_key_base64 = master_key_base64 ,
153+ ssl = True )
152154 request = pc .trigger_batch .make_request (
153155 [{
154156 u'channel' : u'my-chan' ,
@@ -162,9 +164,8 @@ def test_trigger_batch_with_mixed_channels_success_case(self):
162164 )
163165
164166 # simulate the same encryption process and check equality
165- encryp_master_key = ensure_binary (encryp_master_key , "encryp_master_key" )
166- chan_2 = ensure_binary (chan_2 ,"chan_2" )
167- shared_secret = generate_shared_secret (chan_2 , encryp_master_key )
167+ chan_2 = ensure_binary (chan_2 , "chan_2" )
168+ shared_secret = generate_shared_secret (chan_2 , master_key )
168169
169170 box = nacl .secret .SecretBox (shared_secret )
170171
@@ -207,7 +208,12 @@ def test_trigger_with_private_encrypted_channel_string_fail_case_no_encryption_m
207208 def test_trigger_with_public_channel_with_encryption_master_key_specified_success (self ):
208209 json_dumped = u'{"message": "something"}'
209210
210- pc = PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , encryption_master_key = u'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY' , ssl = True )
211+ pc = PusherClient (
212+ app_id = u'4' ,
213+ key = u'key' ,
214+ secret = u'secret' ,
215+ encryption_master_key_base64 = u'OHRXNUZRTG5pUTFzQlFGd3J3N3Q2VFZFc0paZDEweVk=' ,
216+ ssl = True )
211217
212218 with mock .patch ('json.dumps' , return_value = json_dumped ) as json_dumps_mock :
213219
@@ -222,8 +228,14 @@ def test_trigger_with_public_channel_with_encryption_master_key_specified_succes
222228
223229 def test_trigger_with_private_encrypted_channel_success (self ):
224230 # instantiate a new client configured with the master encryption key
225- encryp_master_key = u'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY'
226- pc = PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , encryption_master_key = encryp_master_key , ssl = True )
231+ master_key = b'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY'
232+ master_key_base64 = base64 .b64encode (master_key )
233+ pc = PusherClient (
234+ app_id = u'4' ,
235+ key = u'key' ,
236+ secret = u'secret' ,
237+ encryption_master_key_base64 = master_key_base64 ,
238+ ssl = True )
227239
228240 # trigger a request to a private-encrypted channel and capture the request to assert equality
229241 chan = "private-encrypted-tst"
@@ -232,10 +244,8 @@ def test_trigger_with_private_encrypted_channel_success(self):
232244 request = pc .trigger .make_request (chan , event_name , payload )
233245
234246 # simulate the same encryption process and check equality
235-
236- encryp_master_key = ensure_binary (encryp_master_key ,"encryp_master_key" )
237- chan = ensure_binary (chan ,"chan" )
238- shared_secret = generate_shared_secret (chan , encryp_master_key )
247+ chan = ensure_binary (chan , "chan" )
248+ shared_secret = generate_shared_secret (chan , master_key )
239249
240250 box = nacl .secret .SecretBox (shared_secret )
241251
@@ -284,9 +294,12 @@ def test_trigger_disallow_invalid_channels(self):
284294 self .pusher_client .trigger .make_request ([u'so/me_channel!' ], u'some_event' , {u'message' : u'hello world' }))
285295
286296 def test_trigger_disallow_private_encrypted_channel_with_multiple_channels (self ):
287- # instantiate a new client configured with the master encryption key
288- encryp_master_key = u'8tW5FQLniQ1sBQFwrw7t6TVEsJZd10yY'
289- pc = PusherClient (app_id = u'4' , key = u'key' , secret = u'secret' , encryption_master_key = encryp_master_key , ssl = True )
297+ pc = PusherClient (
298+ app_id = u'4' ,
299+ key = u'key' ,
300+ secret = u'secret' ,
301+ encryption_master_key_base64 = u'OHRXNUZRTG5pUTFzQlFGd3J3N3Q2VFZFc0paZDEweVk=' ,
302+ ssl = True )
290303
291304 self .assertRaises (ValueError , lambda :
292305 self .pusher_client .trigger .make_request ([u'my-chan' , u'private-encrypted-pippo' ], u'some_event' , {u'message' : u'hello world' }))
0 commit comments