def test_crypto_publish_key_mismatch(self): channel_name = self.protocol_channel_name('persisted:crypto_publish_key_mismatch') publish0 = self.ably.channels.get(channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) rx_channel = self.ably2.channels.get(channel_name, cipher={'key': generate_random_key()}) try: with self.assertRaises(AblyException) as cm: messages = rx_channel.history() except Exception as e: log.debug('test_crypto_publish_key_mismatch_fail: rx_channel.history not creating exception') log.debug(messages.items[0].data) raise(e) the_exception = cm.exception self.assertTrue( 'invalid-padding' == the_exception.message or the_exception.message.startswith("UnicodeDecodeError: 'utf8'") or the_exception.message.startswith("UnicodeDecodeError: 'utf-8'"))
def test_crypto_publish(self): channel_name = self.protocol_channel_name('persisted:crypto_publish_text') publish0 = self.ably.channels.get(channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) history = publish0.history() messages = history.items self.assertIsNotNone(messages, msg="Expected non-None messages") self.assertEqual(4, len(messages), msg="Expected 4 messages") message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) self.assertEqual(six.u("This is a string message payload"), message_contents["publish3"], msg="Expect publish3 to be expected String)") self.assertEqual(b"This is a byte[] message payload", message_contents["publish4"], msg="Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4'])) self.assertEqual({"test": "This is a JSONObject message payload"}, message_contents["publish5"], msg="Expect publish5 to be expected JSONObject") self.assertEqual(["This is a JSONArray message payload"], message_contents["publish6"], msg="Expect publish6 to be expected JSONObject")
def test_crypto_publish(self): channel_name = self.get_channel_name('persisted:crypto_publish_text') publish0 = self.ably.channels.get( channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) history = publish0.history() messages = history.items assert messages is not None, "Expected non-None messages" assert 4 == len(messages), "Expected 4 messages" message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) assert six.u("This is a string message payload") == message_contents[ "publish3"], "Expect publish3 to be expected String)" assert b"This is a byte[] message payload" == message_contents[ "publish4"], "Expect publish4 to be expected byte[]. Actual: %s" % str( message_contents['publish4']) assert { "test": "This is a JSONObject message payload" } == message_contents[ "publish5"], "Expect publish5 to be expected JSONObject" assert ["This is a JSONArray message payload"] == message_contents[ "publish6"], "Expect publish6 to be expected JSONObject"
def test_channels_get_doesnt_updates_existing_with_none_options(self): key = generate_random_key() channel = self.ably.channels.get('new_channel', cipher={'key': key}) self.assertIsNot(channel.cipher, None) channel_same = self.ably.channels.get('new_channel') self.assertIs(channel, channel_same) self.assertIsNot(channel.cipher, None)
def test_channels_get_doesnt_updates_existing_with_none_options(self): key = generate_random_key() channel = self.ably.channels.get('new_channel', cipher={'key': key}) assert channel.cipher is not None channel_same = self.ably.channels.get('new_channel') assert channel is channel_same assert channel.cipher is not None
async def test_crypto_publish_key_mismatch(self): channel_name = self.get_channel_name('persisted:crypto_publish_key_mismatch') publish0 = self.ably.channels.get(channel_name, cipher={'key': generate_random_key()}) await publish0.publish("publish3", "This is a string message payload") await publish0.publish("publish4", b"This is a byte[] message payload") await publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) await publish0.publish("publish6", ["This is a JSONArray message payload"]) rx_channel = self.ably2.channels.get(channel_name, cipher={'key': generate_random_key()}) with pytest.raises(AblyException) as excinfo: await rx_channel.history() message = excinfo.value.message assert 'invalid-padding' == message or "codec can't decode" in message
def test_crypto_publish_key_mismatch(self): channel_name = self.get_channel_name('persisted:crypto_publish_key_mismatch') publish0 = self.ably.channels.get(channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) rx_channel = self.ably2.channels.get(channel_name, cipher={'key': generate_random_key()}) with pytest.raises(AblyException) as excinfo: rx_channel.history() message = excinfo.value.message assert ( 'invalid-padding' == message or message.startswith("UnicodeDecodeError: 'utf8'") or message.startswith("UnicodeDecodeError: 'utf-8'") )
def test_crypto_publish_key_mismatch(self): channel_name = self.get_channel_name( 'persisted:crypto_publish_key_mismatch') publish0 = self.ably.channels.get( channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) rx_channel = self.ably2.channels.get( channel_name, cipher={'key': generate_random_key()}) with pytest.raises(AblyException) as excinfo: rx_channel.history() message = excinfo.value.message assert ('invalid-padding' == message or message.startswith("UnicodeDecodeError: 'utf8'") or message.startswith("UnicodeDecodeError: 'utf-8'"))
def test_crypto_publish(self): channel_name = self.get_channel_name('persisted:crypto_publish_text') publish0 = self.ably.channels.get(channel_name, cipher={'key': generate_random_key()}) publish0.publish("publish3", six.u("This is a string message payload")) publish0.publish("publish4", six.b("This is a byte[] message payload")) publish0.publish("publish5", {"test": "This is a JSONObject message payload"}) publish0.publish("publish6", ["This is a JSONArray message payload"]) history = publish0.history() messages = history.items assert messages is not None, "Expected non-None messages" assert 4 == len(messages), "Expected 4 messages" message_contents = dict((m.name, m.data) for m in messages) log.debug("message_contents: %s" % str(message_contents)) assert six.u("This is a string message payload") == message_contents["publish3"], "Expect publish3 to be expected String)" assert b"This is a byte[] message payload" == message_contents["publish4"], "Expect publish4 to be expected byte[]. Actual: %s" % str(message_contents['publish4']) assert {"test": "This is a JSONObject message payload"} == message_contents["publish5"], "Expect publish5 to be expected JSONObject" assert ["This is a JSONArray message payload"] == message_contents["publish6"], "Expect publish6 to be expected JSONObject"
def test_channels_get_returns_new_with_options(self): key = generate_random_key() channel = self.ably.channels.get('new_channel', cipher={'key': key}) self.assertIsInstance(channel, Channel) self.assertIs(channel.cipher.secret_key, key)
def test_channels_get_returns_new_with_options(self): key = generate_random_key() channel = self.ably.channels.get('new_channel', cipher={'key': key}) assert isinstance(channel, Channel) assert channel.cipher.secret_key is key