Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 276bf54

Browse filesBrowse files
author
Devendra
committed
history fix
1 parent d6455ba commit 276bf54
Copy full SHA for 276bf54

File tree

Expand file treeCollapse file tree

2 files changed

+19
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-7
lines changed
Open diff view settings
Collapse file

‎pubnub.py‎

Copy file name to clipboardExpand all lines: pubnub.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,14 @@ def history(self, channel, count=100, reverse=False,
919919
"""
920920

921921
def _get_decrypted_history(resp):
922-
if resp and resp[1] is not None and self.cipher_key:
923-
msgs = resp[0]
924-
for i in range(0,len(msgs)):
925-
msgs[i] = self.decrypt(msgs[i])
926-
return resp
922+
try:
923+
if resp and resp[1] is not None and self.cipher_key:
924+
msgs = resp[0]
925+
for i in range(0,len(msgs)):
926+
msgs[i] = self.decrypt(msgs[i])
927+
except KeyError:
928+
pass
929+
return resp
927930

928931
def _history_callback(resp):
929932
if callback is not None:
@@ -940,7 +943,7 @@ def _history_callback(resp):
940943
params['reverse'] = reverse
941944
params['start'] = start
942945
params['end'] = end
943-
params['auth_key'] = self.auth_key
946+
params['auth'] = self.auth_key
944947
params['pnsdk'] = self.pnsdk
945948
params['include_token'] = 'true' if include_token else 'false'
946949

@@ -2187,7 +2190,7 @@ def _request(self, request, callback=None, error=None, single=False, timeout=5):
21872190
if callback is None:
21882191
return get_data_for_user(self._request_sync(request, timeout=timeout))
21892192
else:
2190-
self._request_async(request, callback, error, single=single, timeout=timeout)
2193+
return self._request_async(request, callback, error, single=single, timeout=timeout)
21912194

21922195
# Pubnub Twisted
21932196

Collapse file

‎python/tests/test_history.py‎

Copy file name to clipboardExpand all lines: python/tests/test_history.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
pubnub = Pubnub("ds","ds")
88
pubnub_enc = Pubnub(publish_key="ds",subscribe_key="ds",cipher_key="enigma")
9+
pubnub_pam = Pubnub(publish_key="pam", subscribe_key="pam", secret_key="pam")
910

1011

1112
def rand(msg):
1213
return "rand-" + str(random.random()) + "-" + msg
1314

1415
channel = rand("channel")
1516
channel_enc = rand("channel_enc")
17+
channel_pam = rand("channel_pam")
1618

1719
messages = []
1820

@@ -21,17 +23,24 @@ def setup_func():
2123
for i in range(0,20):
2224
msg = rand("message-" + str(i))
2325
messages.append(msg)
26+
pubnub_pam.grant(channel=channel_pam, read=True, write=True, ttl=144000)
2427
pubnub.publish(channel=channel, message=msg)
2528
pubnub_enc.publish(channel=channel_enc, message=msg)
29+
pubnub_pam.publish(channel=channel_pam, message=msg)
2630

2731

2832
@with_setup(setup_func)
2933
def test_1():
3034
time.sleep(3)
3135
hresp = pubnub.history(channel=channel, count=20)
3236
hresp2 = pubnub_enc.history(channel=channel_enc, count=20)
37+
hresp3 = pubnub_pam.history(channel=channel_pam, count=20)
38+
hresp4 = pubnub_pam.history(channel=channel_pam + "no_rw", count=20)
3339
assert hresp[0] == messages
3440
assert hresp2[0] == messages
41+
assert hresp3[0] == messages
42+
assert hresp4['message'] == 'Forbidden'
43+
assert channel_pam + "no_rw" in hresp4['payload']['channels']
3544

3645

3746

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.