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 +4 -4
- data/README.md +8 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/faye-authentication.js +10 -1
- data/spec/javascripts/faye-authentication_spec.js +10 -0
- data/spec/javascripts/faye-extension_spec.js +27 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a476e51daa73faa2861159259c328e3d78ccb3f5
|
4
|
+
data.tar.gz: dfe08cef1c29757f4b5374f1a9a567af79c6beb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
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.
|
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-
|
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.
|
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
|