Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ably

Package Overview
Dependencies
Maintainers
1
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ably - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

spec/common/ably-common/.git

2

bower.json
{
"name": "Ably",
"version": "1.0.9",
"version": "1.0.10",
"homepage": "https://www.ably.io/",

@@ -5,0 +5,0 @@ "authors": [

/**
* @license Copyright 2017, Ably
*
* Ably JavaScript Library v1.0.9
* Ably JavaScript Library v1.0.10
* https://github.com/ably/ably-js

@@ -6,0 +6,0 @@ *

@@ -218,4 +218,14 @@ var Message = (function() {

function normalizeCipherOptions(options) {
if(options && options.cipher && !options.cipher.channelCipher) {
if(!Crypto) throw new Error('Encryption not enabled; use ably.encryption.js instead');
var cipher = Crypto.getCipher(options.cipher);
options.cipher = cipher.cipherParams;
options.channelCipher = cipher.cipher;
}
}
Message.fromEncoded = function(encoded, options) {
var msg = Message.fromValues(encoded);
normalizeCipherOptions(options);
/* if decoding fails at any point, catch and return the message decoded to

@@ -232,2 +242,3 @@ * the fullest extent possible */

Message.fromEncodedArray = function(encodedArray, options) {
normalizeCipherOptions(options);
return Utils.arrMap(encodedArray, function(encoded) {

@@ -234,0 +245,0 @@ return Message.fromEncoded(encoded, options);

@@ -23,3 +23,3 @@ Defaults.protocolVersion = 1;

Defaults.version = '1.0.9';
Defaults.version = '1.0.10';
Defaults.libstring = Platform.libver + Defaults.version;

@@ -26,0 +26,0 @@ Defaults.apiVersion = '1.0';

{
"name": "ably",
"description": "Realtime client library for Ably.io, the realtime messaging service",
"version": "1.0.9",
"version": "1.0.10",
"main": "./nodejs/index.js",

@@ -6,0 +6,0 @@ "typings": "./browser/static/ably.d.ts",

@@ -5,3 +5,3 @@ # [Ably](https://www.ably.io)

## Version: 1.0.9
## Version: 1.0.10

@@ -8,0 +8,0 @@ This repo contains the Ably Javascript client library, for the browser (including IE8+), Nodejs, React Native, NativeScript and Cordova.

@@ -187,2 +187,28 @@ "use strict";

exports.fromEncoded_cipher_options = function(test) {
if(!Crypto) {
test.ok(false, 'Encryption not supported');
test.done();
return;
}
loadTestData(testResourcesPath + 'crypto-data-256.json', function(err, testData) {
if(err) {
test.ok(false, 'Unable to get test assets; err = ' + displayError(err));
return;
}
var key = BufferUtils.base64Decode(testData.key);
var iv = BufferUtils.base64Decode(testData.iv);
test.expect(testData.items.length);
for(var i = 0; i < testData.items.length; i++) {
var item = testData.items[i];
var testMessage = Message.fromEncoded(item.encoded);
var decryptedMessage = Message.fromEncoded(item.encrypted, {cipher: {key: key, iv: iv}});
test.ok(compareMessage(testMessage, decryptedMessage));
}
test.done();
});
};
exports.msgpack_128 = function(test) {

@@ -189,0 +215,0 @@ if(typeof ArrayBuffer === 'undefined') {

"use strict";
define(['ably', 'shared_helper', 'async'], function(Ably, helper, async) {
var exports = {},
var currentTime, rest, exports = {},
_exports = {},
loadTestData = helper.loadTestData,
testClientId = 'clientId',
utils = helper.Utils,
i = utils.inspect,
displayError = helper.displayError,
utils = helper.Utils,
mixin = utils.mixin,
closeAndFinish = helper.closeAndFinish,
monitorConnection = helper.monitorConnection,
testOnAllTransports = helper.testOnAllTransports;
testOnAllTransports = helper.testOnAllTransports,
BufferUtils = Ably.Realtime.BufferUtils,
Crypto = Ably.Realtime.Crypto,
Message = Ably.Realtime.Message,
displayError = helper.displayError,
testResourcesPath = helper.testResourcesPath,
msgpack = (typeof(window) == 'object') ? Ably.msgpack : require('msgpack-js'),
mixin = helper.Utils.mixin,
utils = helper.Utils,
noop = function() {},
createPM = Ably.Realtime.ProtocolMessage.fromDeserialized,
simulateDroppedConnection = helper.simulateDroppedConnection,
availableTransports = helper.availableTransports;
exports.setupMessage = function(test) {
exports.setuptmp = function(test) {
test.expect(1);
helper.setupApp(function(err) {
if(err) {
test.ok(false, displayError(err));
} else {
test.ok(true, 'setup app');
test.ok(false, helper.displayError(err));
test.done();
return;
}
test.done();
rest = helper.AblyRest();
rest.time(function(err, time) {
if(err) {
test.ok(false, helper.displayError(err));
} else {
currentTime = time;
test.ok(true, 'Obtained time via REST');
}
test.done();
});
});
};
//testOnAllTransports(exports, 'reauth_authCallback', function(realtimeOpts) { return function(test) {
//test.expect(5);
//var realtime, rest = helper.AblyRest();
//var firstTime = true;
//var authCallback = function(tokenParams, callback) {
//tokenParams.clientId = '*';
//tokenParams.capability = firstTime ? {'wrong': ['*']} : {'right': ['*']};
//firstTime = false;
//rest.auth.requestToken(tokenParams, null, function(err, tokenDetails) {
//if(err) {
//test.ok(false, displayError(err));
//closeAndFinish(test, realtime);
//return;
//}
//callback(null, tokenDetails);
//});
//};
function requestSync(realtime, channelName) {
realtime.connection.connectionManager.activeProtocol.transport.send({
action: 16,
channel: channelName
});
}
//realtime = helper.AblyRealtime(mixin(realtimeOpts, {log: {level: 4}, authCallback: authCallback }));
//realtime.connection.once('connected', function(){
//test.ok(true, 'Verify connection connected');
//var channel = realtime.channels.get('right');
//channel.attach(function(err) {
//test.ok(err, 'Check using first token, without channel attach capability');
//test.equal(err.code, 40160, 'Check expected error code');
function attachChannels(channels, callback) {
async.map(channels, function(channel, cb) { channel.attach(cb); }, callback);
}
//[> soon after connected, reauth <]
//realtime.auth.authorize(null, null, function(err) {
//test.ok(!err, err && displayError(err));
//channel.attach(function(err) {
//test.ok(!err, 'Check using second token, with channel attach capability');
//closeAndFinish(test, realtime);
//});
//});
//});
//});
//monitorConnection(test, realtime);
//}});
exports.connectionAttributes = function(test) {
test.expect(6);
var realtime;
function compareMessage(one, two) {
if(one.encoding != two.encoding) return false;
if(typeof(one.data) == 'string' && typeof(two.data) == 'string') {
return one.data == two.data;
}
if(BufferUtils.isBuffer(one.data) && BufferUtils.isBuffer(two.data)) {
return (BufferUtils.bufferCompare(one.data, two.data) === 0);
}
return JSON.stringify(one.data) == JSON.stringify(two.data);
}
function testEachFixture(test, filename, channelName, testsPerFixture, fixtureTest) {
if(!Crypto) {
test.ok(false, 'Encryption not supported');
test.done();
return;
}
loadTestData(testResourcesPath + filename, function(err, testData) {
if(err) {
test.ok(false, 'Unable to get test assets; err = ' + displayError(err));
return;
}
var realtime = helper.AblyRealtime();
var key = BufferUtils.base64Decode(testData.key);
var iv = BufferUtils.base64Decode(testData.iv);
var channel = realtime.channels.get(channelName, {cipher: {key: key, iv: iv}});
test.expect(testData.items.length * testsPerFixture);
for(var i = 0; i < testData.items.length; i++) {
var item = testData.items[i];
/* read messages from test data */
var testMessage = Message.fromValues(item.encoded);
var encryptedMessage = Message.fromValues(item.encrypted);
/* decode (ie remove any base64 encoding). Will throw when
* it gets to the cipher part of the encoding, so wrap in try/catch */
try { Message.decode(testMessage); } catch(_) {}
try { Message.decode(encryptedMessage); } catch(_) {}
/* reset channel cipher, to ensure it uses the given iv */
channel.setOptions({cipher: {key: key, iv: iv}});
fixtureTest(channel.channelOptions, testMessage, encryptedMessage, item.msgpack);
}
closeAndFinish(test, realtime);
});
}
var publishIntervalHelper = function(currentMessageNum, channel, dataFn, onPublish){
return function(currentMessageNum) {
console.log('sending: ' + currentMessageNum);
channel.publish('event0', dataFn(), function() {
console.log('publish callback called');
onPublish();
});
};
},
publishAtIntervals = function(numMessages, channel, dataFn, onPublish){
for(var i = numMessages; i > 0; i--) {
setTimeout(publishIntervalHelper(i, channel, dataFn, onPublish), 2*i);
}
};
function _multiple_send(test, text, iterations, delay) {
if(!Crypto) {
test.ok(false, 'Encryption not supported');
test.done();
return;
}
var realtime = helper.AblyRealtime({ useBinaryProtocol: !text});
test.expect(iterations + 3);
var channelName = 'multiple_send_' + (text ? 'text_' : 'binary_') + iterations + '_' + delay,
channel = realtime.channels.get(channelName),
messageText = 'Test message (' + channelName + ')';
Crypto.generateRandomKey(128, function(err, key) {
channel.setOptions({cipher: {key: key}}, function(err) {
if(err) {
test.ok(false, 'Unable to set channel options; err = ' + displayError(err));
closeAndFinish(test, realtime);
return;
}
test.equal(channel.channelOptions.cipher.algorithm, 'aes');
test.equal(channel.channelOptions.cipher.keyLength, 128);
function sendAll(sendCb) {
var sent = 0;
var sendOnce = function() {
channel.publish('event0', messageText);
if(++sent == iterations) {
sendCb(null);
return;
}
setTimeout(sendOnce, delay);
};
sendOnce();
}
function recvAll(recvCb) {
var received = 0;
channel.subscribe('event0', function(msg) {
test.ok(msg.data == messageText);
if(++received == iterations)
recvCb(null);
});
}
async.parallel([sendAll, recvAll], function(err) {
if(err) {
test.ok(false, 'Error sending messages; err = ' + displayError(err));
}
test.ok('Verify all messages received');
closeAndFinish(test, realtime);
});
});
});
}
function extractClientIds(presenceSet) {
return utils.arrMap(presenceSet, function(presmsg) {
return presmsg.clientId;
}).sort();
}
function extractMember(presenceSet, clientId) {
return helper.arrFind(presenceSet, function(member) {
return member.clientId === clientId;
});
}
/***************************************************/
function extractClientIds(presenceSet) {
return utils.arrMap(presenceSet, function(presmsg) {
return presmsg.clientId;
}).sort();
}
function extractMember(presenceSet, clientId) {
return helper.arrFind(presenceSet, function(member) {
return member.clientId === clientId;
});
}
var rest, authToken, authToken2;
var testClientId = 'testclient', testClientId2 = 'testclient2';
var createListenerChannel = function(channelName, callback) {
var channel, realtime;
try {
realtime = helper.AblyRealtime();
realtime.connection.on('connected', function() {
test.equal(realtime.connection.serial, -1, "verify serial is -1 on connect");
test.equal(realtime.connection.recoveryKey, realtime.connection.key + ':' + realtime.connection.serial + ':' + realtime.connection.connectionManager.msgSerial, 'verify correct recovery key');
console.log("Listener connected");
channel = realtime.channels.get(channelName);
channel.attach(function(err) {
console.log("Listener attached to channel " + channelName);
callback(err, realtime, channel);
});
});
} catch(err) {
callback(err, realtime);
}
};
var channel = realtime.channels.get('connectionattributes');
channel.attach(function(err) {
var listenerFor = function(eventName, expectedClientId) {
return function(test, channel, callback) {
var presenceHandler = function(presmsg) {
if(this.event === eventName) {
test.ok(true, 'Presence ' + eventName + ' received');
if(expectedClientId !== undefined) {
test.equal(presmsg.clientId, expectedClientId, 'Verify correct clientId');
}
channel.presence.unsubscribe(presenceHandler);
callback();
}
};
channel.presence.subscribe(presenceHandler);
};
};
var runTestWithEventListener = function(test, channel, eventListener, testRunner) {
try {
createListenerChannel(channel, function(err, listenerRealtime, presenceChannel){
if(err) {
test.ok(false, displayError(err));
closeAndFinish(test, listenerRealtime);
return;
}
console.log("presenceChannel:", presenceChannel.name);
async.parallel([
function(cb) {
eventListener(test, presenceChannel, cb);
},
testRunner
], function(err, res) {
console.log("in callback, err = ", err);
if(err) {
test.ok(false, 'Attach failed with error: ' + displayError(err));
closeAndFinish(test, realtime);
return;
test.ok(false, displayError(err));
}
channel.subscribe(function() {
setTimeout(function() {
console.log("connectionAttributes test: connection serial is " + realtime.connection.serial)
test.equal(realtime.connection.serial, 0, "verify serial is 0 after message received")
test.equal(realtime.connection.recoveryKey, realtime.connection.key + ':' + realtime.connection.serial + ':' + realtime.connection.connectionManager.msgSerial, 'verify recovery key still correct');
realtime.connection.close();
realtime.connection.whenState('closed', function() {
test.equal(realtime.connection.recoveryKey, null, 'verify recovery key null after close');
closeAndFinish(test, realtime);
});
}, 0);
});
channel.publish("name", "data", function(err) {
if(err) {
test.ok(false, 'Publish failed with error: ' + displayError(err));
closeAndFinish(test, realtime);
return;
}
});
test.equal(realtime.connection.serial, -1, "verify serial is -1 after publish but before message received")
// testRunner might or might not call back with an open realtime
var openConnections = (res[1] && res[1].close) ?
[listenerRealtime, res[1]] :
listenerRealtime;
closeAndFinish(test, openConnections);
});
});
monitorConnection(test, realtime);
} catch(e) {
test.ok(false, 'test failed with exception: ' + e.stack);
closeAndFinish(test, realtime);
test.done();
}
};
exports.fromEncoded_cipher_options = function(test) {
if(!Crypto) {
test.ok(false, 'Encryption not supported');
test.done();
return;
}
loadTestData(testResourcesPath + 'crypto-data-256.json', function(err, testData) {
if(err) {
test.ok(false, 'Unable to get test assets; err = ' + displayError(err));
return;
}
var key = BufferUtils.base64Decode(testData.key);
var iv = BufferUtils.base64Decode(testData.iv);
test.expect(testData.items.length);
for(var i = 0; i < testData.items.length; i++) {
var item = testData.items[i];
var testMessage = Message.fromEncoded(item.encoded);
var decryptedMessage = Message.fromEncoded(item.encrypted, {cipher: {key: key, iv: iv}});
test.ok(compareMessage(testMessage, decryptedMessage));
}
test.done();
});
};
return module.exports = helper.withTimeout(exports);
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc