faye-authentication 0.1.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.
@@ -0,0 +1,282 @@
1
+ /*
2
+
3
+ Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine
4
+ BDD framework for JavaScript.
5
+
6
+ http://github.com/pivotal/jasmine-ajax
7
+
8
+ Jasmine Home page: http://pivotal.github.com/jasmine
9
+
10
+ Copyright (c) 2008-2013 Pivotal Labs
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ "Software"), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, and/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ */
32
+
33
+ (function() {
34
+ function extend(destination, source) {
35
+ for (var property in source) {
36
+ destination[property] = source[property];
37
+ }
38
+ return destination;
39
+ }
40
+
41
+ function MockAjax(global) {
42
+ var requestTracker = new RequestTracker(),
43
+ stubTracker = new StubTracker(),
44
+ realAjaxFunction = global.XMLHttpRequest,
45
+ mockAjaxFunction = fakeRequest(requestTracker, stubTracker);
46
+
47
+ this.install = function() {
48
+ global.XMLHttpRequest = mockAjaxFunction;
49
+ };
50
+
51
+ this.uninstall = function() {
52
+ global.XMLHttpRequest = realAjaxFunction;
53
+
54
+ this.stubs.reset();
55
+ this.requests.reset();
56
+ };
57
+
58
+ this.stubRequest = function(url, data) {
59
+ var stub = new RequestStub(url, data);
60
+ stubTracker.addStub(stub);
61
+ return stub;
62
+ };
63
+
64
+ this.withMock = function(closure) {
65
+ this.install();
66
+ try {
67
+ closure();
68
+ } finally {
69
+ this.uninstall();
70
+ }
71
+ };
72
+
73
+ this.requests = requestTracker;
74
+ this.stubs = stubTracker;
75
+ }
76
+
77
+ function StubTracker() {
78
+ var stubs = [];
79
+
80
+ this.addStub = function(stub) {
81
+ stubs.push(stub);
82
+ };
83
+
84
+ this.reset = function() {
85
+ stubs = [];
86
+ };
87
+
88
+ this.findStub = function(url, data) {
89
+ for (var i = stubs.length - 1; i >= 0; i--) {
90
+ var stub = stubs[i];
91
+ if (stub.matches(url, data)) {
92
+ return stub;
93
+ }
94
+ }
95
+ };
96
+ }
97
+
98
+ function fakeRequest(requestTracker, stubTracker) {
99
+ function FakeXMLHttpRequest() {
100
+ requestTracker.track(this);
101
+ this.requestHeaders = {};
102
+ }
103
+
104
+ extend(FakeXMLHttpRequest.prototype, new window.XMLHttpRequest());
105
+ extend(FakeXMLHttpRequest.prototype, {
106
+ open: function() {
107
+ this.method = arguments[0];
108
+ this.url = arguments[1];
109
+ this.username = arguments[3];
110
+ this.password = arguments[4];
111
+ this.readyState = 1;
112
+ this.onreadystatechange();
113
+ },
114
+
115
+ setRequestHeader: function(header, value) {
116
+ this.requestHeaders[header] = value;
117
+ },
118
+
119
+ abort: function() {
120
+ this.readyState = 0;
121
+ this.status = 0;
122
+ this.statusText = "abort";
123
+ this.onreadystatechange();
124
+ },
125
+
126
+ readyState: 0,
127
+
128
+ onload: function() {
129
+ },
130
+
131
+ onreadystatechange: function(isTimeout) {
132
+ },
133
+
134
+ status: null,
135
+
136
+ send: function(data) {
137
+ this.params = data;
138
+ this.readyState = 2;
139
+ this.onreadystatechange();
140
+
141
+ var stub = stubTracker.findStub(this.url, data);
142
+ if (stub) {
143
+ this.response(stub);
144
+ }
145
+ },
146
+
147
+ data: function() {
148
+ var data = {};
149
+ if (typeof this.params !== 'string') { return data; }
150
+ var params = this.params.split('&');
151
+
152
+ for (var i = 0; i < params.length; ++i) {
153
+ var kv = params[i].replace(/\+/g, ' ').split('=');
154
+ var key = decodeURIComponent(kv[0]);
155
+ data[key] = data[key] || [];
156
+ data[key].push(decodeURIComponent(kv[1]));
157
+ }
158
+ return data;
159
+ },
160
+
161
+ getResponseHeader: function(name) {
162
+ return this.responseHeaders[name];
163
+ },
164
+
165
+ getAllResponseHeaders: function() {
166
+ var responseHeaders = [];
167
+ for (var i in this.responseHeaders) {
168
+ if (this.responseHeaders.hasOwnProperty(i)) {
169
+ responseHeaders.push(i + ': ' + this.responseHeaders[i]);
170
+ }
171
+ }
172
+ return responseHeaders.join('\r\n');
173
+ },
174
+
175
+ responseText: null,
176
+
177
+ response: function(response) {
178
+ this.status = response.status;
179
+ this.statusText = response.statusText || "";
180
+ this.responseText = response.responseText || "";
181
+ this.readyState = 4;
182
+ this.responseHeaders = response.responseHeaders ||
183
+ {"Content-type": response.contentType || "application/json" };
184
+
185
+ this.onload();
186
+ this.onreadystatechange();
187
+ },
188
+
189
+ responseTimeout: function() {
190
+ this.readyState = 4;
191
+ jasmine.clock().tick(30000);
192
+ this.onreadystatechange('timeout');
193
+ }
194
+ });
195
+
196
+ return FakeXMLHttpRequest;
197
+ }
198
+
199
+ function RequestTracker() {
200
+ var requests = [];
201
+
202
+ this.track = function(request) {
203
+ requests.push(request);
204
+ };
205
+
206
+ this.first = function() {
207
+ return requests[0];
208
+ };
209
+
210
+ this.count = function() {
211
+ return requests.length;
212
+ };
213
+
214
+ this.reset = function() {
215
+ requests = [];
216
+ };
217
+
218
+ this.mostRecent = function() {
219
+ return requests[requests.length - 1];
220
+ };
221
+
222
+ this.at = function(index) {
223
+ return requests[index];
224
+ };
225
+
226
+ this.filter = function(url_to_match) {
227
+ if (requests.length == 0) return [];
228
+ var matching_requests = [];
229
+
230
+ for (var i = 0; i < requests.length; i++) {
231
+ if (url_to_match instanceof RegExp &&
232
+ url_to_match.test(requests[i].url)) {
233
+ matching_requests.push(requests[i]);
234
+ } else if (url_to_match instanceof Function &&
235
+ url_to_match(requests[i])) {
236
+ matching_requests.push(requests[i]);
237
+ } else {
238
+ if (requests[i].url == url_to_match) {
239
+ matching_requests.push(requests[i]);
240
+ }
241
+ }
242
+ }
243
+
244
+ return matching_requests;
245
+ };
246
+ }
247
+
248
+ function RequestStub(url, stubData) {
249
+ var split = url.split('?');
250
+ this.url = split[0];
251
+
252
+ var normalizeQuery = function(query) {
253
+ return query ? query.split('&').sort().join('&') : undefined;
254
+ };
255
+
256
+ this.query = normalizeQuery(split[1]);
257
+ this.data = normalizeQuery(stubData);
258
+
259
+ this.andReturn = function(options) {
260
+ this.status = options.status || 200;
261
+
262
+ this.contentType = options.contentType;
263
+ this.responseText = options.responseText;
264
+ };
265
+
266
+ this.matches = function(fullUrl, data) {
267
+ var urlSplit = fullUrl.split('?'),
268
+ url = urlSplit[0],
269
+ query = urlSplit[1];
270
+ return this.url === url && this.query === normalizeQuery(query) && (!this.data || this.data === normalizeQuery(data));
271
+ };
272
+ }
273
+
274
+ if (typeof window === "undefined" && typeof exports === "object") {
275
+ exports.MockAjax = MockAjax;
276
+ jasmine.Ajax = new MockAjax(exports);
277
+ } else {
278
+ window.MockAjax = MockAjax;
279
+ jasmine.Ajax = new MockAjax(window);
280
+ }
281
+ }());
282
+
@@ -0,0 +1,136 @@
1
+ /*
2
+ CryptoJS v3.1.2
3
+ code.google.com/p/crypto-js
4
+ (c) 2009-2013 by Jeff Mott. All rights reserved.
5
+ code.google.com/p/crypto-js/wiki/License
6
+ */
7
+ (function () {
8
+ // Shortcuts
9
+ var C = CryptoJS;
10
+ var C_lib = C.lib;
11
+ var WordArray = C_lib.WordArray;
12
+ var Hasher = C_lib.Hasher;
13
+ var C_algo = C.algo;
14
+
15
+ // Reusable object
16
+ var W = [];
17
+
18
+ /**
19
+ * SHA-1 hash algorithm.
20
+ */
21
+ var SHA1 = C_algo.SHA1 = Hasher.extend({
22
+ _doReset: function () {
23
+ this._hash = new WordArray.init([
24
+ 0x67452301, 0xefcdab89,
25
+ 0x98badcfe, 0x10325476,
26
+ 0xc3d2e1f0
27
+ ]);
28
+ },
29
+
30
+ _doProcessBlock: function (M, offset) {
31
+ // Shortcut
32
+ var H = this._hash.words;
33
+
34
+ // Working variables
35
+ var a = H[0];
36
+ var b = H[1];
37
+ var c = H[2];
38
+ var d = H[3];
39
+ var e = H[4];
40
+
41
+ // Computation
42
+ for (var i = 0; i < 80; i++) {
43
+ if (i < 16) {
44
+ W[i] = M[offset + i] | 0;
45
+ } else {
46
+ var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
47
+ W[i] = (n << 1) | (n >>> 31);
48
+ }
49
+
50
+ var t = ((a << 5) | (a >>> 27)) + e + W[i];
51
+ if (i < 20) {
52
+ t += ((b & c) | (~b & d)) + 0x5a827999;
53
+ } else if (i < 40) {
54
+ t += (b ^ c ^ d) + 0x6ed9eba1;
55
+ } else if (i < 60) {
56
+ t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
57
+ } else /* if (i < 80) */ {
58
+ t += (b ^ c ^ d) - 0x359d3e2a;
59
+ }
60
+
61
+ e = d;
62
+ d = c;
63
+ c = (b << 30) | (b >>> 2);
64
+ b = a;
65
+ a = t;
66
+ }
67
+
68
+ // Intermediate hash value
69
+ H[0] = (H[0] + a) | 0;
70
+ H[1] = (H[1] + b) | 0;
71
+ H[2] = (H[2] + c) | 0;
72
+ H[3] = (H[3] + d) | 0;
73
+ H[4] = (H[4] + e) | 0;
74
+ },
75
+
76
+ _doFinalize: function () {
77
+ // Shortcuts
78
+ var data = this._data;
79
+ var dataWords = data.words;
80
+
81
+ var nBitsTotal = this._nDataBytes * 8;
82
+ var nBitsLeft = data.sigBytes * 8;
83
+
84
+ // Add padding
85
+ dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
86
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
87
+ dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
88
+ data.sigBytes = dataWords.length * 4;
89
+
90
+ // Hash final blocks
91
+ this._process();
92
+
93
+ // Return final computed hash
94
+ return this._hash;
95
+ },
96
+
97
+ clone: function () {
98
+ var clone = Hasher.clone.call(this);
99
+ clone._hash = this._hash.clone();
100
+
101
+ return clone;
102
+ }
103
+ });
104
+
105
+ /**
106
+ * Shortcut function to the hasher's object interface.
107
+ *
108
+ * @param {WordArray|string} message The message to hash.
109
+ *
110
+ * @return {WordArray} The hash.
111
+ *
112
+ * @static
113
+ *
114
+ * @example
115
+ *
116
+ * var hash = CryptoJS.SHA1('message');
117
+ * var hash = CryptoJS.SHA1(wordArray);
118
+ */
119
+ C.SHA1 = Hasher._createHelper(SHA1);
120
+
121
+ /**
122
+ * Shortcut function to the HMAC's object interface.
123
+ *
124
+ * @param {WordArray|string} message The message to hash.
125
+ * @param {WordArray|string} key The secret key.
126
+ *
127
+ * @return {WordArray} The HMAC.
128
+ *
129
+ * @static
130
+ *
131
+ * @example
132
+ *
133
+ * var hmac = CryptoJS.HmacSHA1(message, key);
134
+ */
135
+ C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
136
+ }());
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faye-authentication
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Siami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0.rc1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0.rc1
55
+ - !ruby/object:Gem::Dependency
56
+ name: jasmine
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faye
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thin
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.18'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.18'
125
+ description: A faye extension to add authentication mechanisms
126
+ email:
127
+ - adrien.siami@dimelo.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - app/assets/javascripts/faye-authentication.js
140
+ - faye-authentication.gemspec
141
+ - lib/faye/authentication.rb
142
+ - lib/faye/authentication/engine.rb
143
+ - lib/faye/authentication/extension.rb
144
+ - lib/faye/authentication/http_client.rb
145
+ - lib/faye/authentication/version.rb
146
+ - spec/javascripts/faye-authentication_spec.js
147
+ - spec/javascripts/faye-extension_spec.js
148
+ - spec/javascripts/helpers/.gitkeep
149
+ - spec/javascripts/support/jasmine.yml
150
+ - spec/javascripts/support/jasmine_helper.rb
151
+ - spec/lib/faye/authentication/extension_spec.rb
152
+ - spec/lib/faye/authentication/http_client_spec.rb
153
+ - spec/lib/faye/authentication_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/utils/javascripts/core.js
156
+ - spec/utils/javascripts/faye.js
157
+ - spec/utils/javascripts/hmac.js
158
+ - spec/utils/javascripts/jquery.js
159
+ - spec/utils/javascripts/mock-ajax.js
160
+ - spec/utils/javascripts/sha1.js
161
+ homepage: https://github.com/dimelo/faye-authentication
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.2.2
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: A faye extension to add authentication mechanisms
185
+ test_files:
186
+ - spec/javascripts/faye-authentication_spec.js
187
+ - spec/javascripts/faye-extension_spec.js
188
+ - spec/javascripts/helpers/.gitkeep
189
+ - spec/javascripts/support/jasmine.yml
190
+ - spec/javascripts/support/jasmine_helper.rb
191
+ - spec/lib/faye/authentication/extension_spec.rb
192
+ - spec/lib/faye/authentication/http_client_spec.rb
193
+ - spec/lib/faye/authentication_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/utils/javascripts/core.js
196
+ - spec/utils/javascripts/faye.js
197
+ - spec/utils/javascripts/hmac.js
198
+ - spec/utils/javascripts/jquery.js
199
+ - spec/utils/javascripts/mock-ajax.js
200
+ - spec/utils/javascripts/sha1.js