faye-authentication 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf71f8b18a19f40de998593763092f543e29ece8
4
- data.tar.gz: bdeb27cf3b04249d5cfddf381e993fc9a8a3e7e4
3
+ metadata.gz: a476e51daa73faa2861159259c328e3d78ccb3f5
4
+ data.tar.gz: dfe08cef1c29757f4b5374f1a9a567af79c6beb8
5
5
  SHA512:
6
- metadata.gz: 70703294de6bcabc10ad6a69da8bfc98b62b6bb4f6c13ea9c2c70ab124c2b0e1a9cfabdf2157471fd7ab42ce88eadfc5af7ffc19d63e596b01a1696cb4974a87
7
- data.tar.gz: 2237e1664fb593aa62c06803362670929bf719d23d4c598ed523fa6309e869ae4ea55e61f51bbadf927d612861e3170e14589745810189b57d59c43cdd53ceee
6
+ metadata.gz: 28663fd22810070a9e331540aefdec23058edb469949ca0a3a3ea4e16c0adeb69d7f72bdc9ac5f195da5053c121c78a74d1b75a79035dc53a54856bf75aed22a
7
+ data.tar.gz: 475993a93cb06547ddc9bb53f760b249125dece67734af268de639a1f73f1165449c6207d16840a685fdc1fd7ba361d51881f6ba3b3bd85a47813f231f515116
data/README.md CHANGED
@@ -118,6 +118,14 @@ client.addExtension(new FayeAuthentication(client, '/faye/auth', {whitelist: cha
118
118
  ````
119
119
 
120
120
 
121
+ Faye-authentication will retry each signatures request once if the first attempt failed or returned an invalid signature. The default retry delay is 1000 ms, so 1 second.
122
+ It can be configured :
123
+
124
+ ````javascript
125
+ client.addExtension(new FayeAuthentication(client, '/faye/auth', {retry_delay: 200})); // 200 ms retry delay
126
+ ````
127
+
128
+
121
129
  ### Ruby Faye server extension
122
130
 
123
131
  Instanciate the extension with your secret key and add it to the server :
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.0
1
+ 1.8.0
@@ -4,6 +4,7 @@ function FayeAuthentication(client, endpoint, options) {
4
4
  this._signatures = {};
5
5
  this._outbox = {};
6
6
  this._options = options || {};
7
+ this._options.retry_delay = this._options.retry_delay || 1000;
7
8
  this._waiting_signatures = [];
8
9
  this._timer = null;
9
10
  }
@@ -31,6 +32,11 @@ FayeAuthentication.prototype.resolveWaitingSignatures = function() {
31
32
  var signature = $.grep(response.signatures || [], function(e) {
32
33
  return (e.channel == params.channel && e.clientId == params.clientId);
33
34
  })[0];
35
+ if (typeof signature === 'undefined') {
36
+ self.error('No signature found in ajax reply for channel ' + params.channel + ' and clientId ' + params.clientId);
37
+ } else if (signature && !signature.signature) {
38
+ self.error('Error when fetching signature for channel ' + params.channel + ' and clientId ' + params.clientId + ', error was : "' + signature.error + '"');
39
+ }
34
40
  Faye.Promise.resolve(self._signatures[params.clientId][params.channel], signature ? signature.signature : null);
35
41
  });
36
42
  }, 'json').fail(function(xhr, textStatus, e) {
@@ -105,7 +111,10 @@ FayeAuthentication.prototype.incoming = function(message, callback) {
105
111
  outbox_message.message.retried = true;
106
112
  delete outbox_message.message.id;
107
113
  delete this._outbox[message.id];
108
- this._client._sendMessage(outbox_message.message, {}, callback);
114
+ var self = this;
115
+ setTimeout(function() {
116
+ self._client._sendMessage(outbox_message.message, {}, callback);
117
+ }, this._options.retry_delay);
109
118
  } else {
110
119
  callback(message);
111
120
  }
@@ -12,6 +12,16 @@ describe('faye-authentication', function() {
12
12
  expect(auth.endpoint()).toBe('/custom');
13
13
  });
14
14
 
15
+ it('sets a retry delay by default', function() {
16
+ var auth = new FayeAuthentication(new Faye.Client('http://example.com'));
17
+ expect(auth._options.retry_delay).toBe(1000);
18
+ });
19
+
20
+ it('allows to specify a custom retry delay', function() {
21
+ var auth = new FayeAuthentication(new Faye.Client('http://example.com'), null, {retry_delay: 500});
22
+ expect(auth._options.retry_delay).toBe(500);
23
+ });
24
+
15
25
  });
16
26
 
17
27
  describe('authentication_required', function() {
@@ -24,7 +24,7 @@ describe('Faye extension', function() {
24
24
 
25
25
  describe('With extension', function() {
26
26
  beforeEach(function() {
27
- this.extension = new FayeAuthentication(this.client);
27
+ this.extension = new FayeAuthentication(this.client, null, {retry_delay: 100});
28
28
  this.client.addExtension(this.extension);
29
29
  });
30
30
 
@@ -252,7 +252,7 @@ describe('Faye extension', function() {
252
252
  }, 500);
253
253
  });
254
254
 
255
- it('tries to get a new signature immediately when the used signature is bad or expired', function(done) {
255
+ it('tries to get a new signature when the used signature is bad or expired', function(done) {
256
256
  jasmine.Ajax.stubRequest('/faye/auth').andReturn({
257
257
  'responseText': '{"signature": "bad"}'
258
258
  });
@@ -263,6 +263,31 @@ describe('Faye extension', function() {
263
263
  });
264
264
  });
265
265
 
266
+ it('retries for the signature after a configured delay', function(done) {
267
+ jasmine.Ajax.stubRequest('/faye/auth').andReturn({
268
+ 'responseText': '{"signature": "bad"}'
269
+ });
270
+ var self = this;
271
+ var finished = false;
272
+ this.client.subscribe('/toto').then(undefined, function() {
273
+ finished = true;
274
+ });
275
+
276
+ setTimeout(function() {
277
+
278
+ // Initial 200ms batching delay
279
+
280
+ setTimeout(function() {
281
+ expect(finished).toBe(false);
282
+ }, 200 + 80); // 2nd Batching delay + 80 ms
283
+
284
+ setTimeout(function() {
285
+ expect(finished).toBe(true);
286
+ done();
287
+ }, 200 + 200); // 2nd Batching delay + 200 ms
288
+ }, 200);
289
+ });
290
+
266
291
  it('calls the success callback for a successfully retried message', function(done) {
267
292
 
268
293
  this.client.subscribe('/foo').then(function() {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Siami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.4.2
213
+ rubygems_version: 2.4.5
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: A faye extension to add authentication mechanisms