Skip to content

Commit 7764804

Browse files
author
Hector Virgen
committed
Fixes removal of S cookie for angular adapter.
1 parent f82bc45 commit 7764804

File tree

9 files changed

+17
-155
lines changed

9 files changed

+17
-155
lines changed

api-angular-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-angular.js

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,6 @@
100100
query[key] = this._options.query[key];
101101
}
102102

103-
var sessionToken;
104-
105-
if (this._http.getSessionToken) {
106-
sessionToken = this._http.getSessionToken();
107-
} else if (this._cookies.S) {
108-
sessionToken = this._cookies.S;
109-
}
110-
111-
if (sessionToken) {
112-
query.session_token = sessionToken;
113-
}
114-
115103
var queryParts = [];
116104
for (var i in query) {
117105
if (!query.hasOwnProperty(i)) continue;
@@ -348,12 +336,10 @@
348336
'use strict';
349337

350338
var context = typeof exports !== 'undefined' ? exports : window;
351-
var SESSION_COOKIE_NAME_REGEX = /(?:^| )S=/;
352339

353-
AngularAdapter.$inject = ['$http', '$document', '$window'];
354-
function AngularAdapter($http, $document, $window) {
340+
AngularAdapter.$inject = ['$http', '$window'];
341+
function AngularAdapter($http, $window) {
355342
this._$http = $http;
356-
this._$document = $document;
357343
this._$window = $window;
358344
}
359345

@@ -370,42 +356,6 @@
370356
}).then(formatResponse);
371357
};
372358

373-
AngularAdapter.prototype.getSessionToken = function() {
374-
var cookie = this._$document[0].cookie;
375-
376-
// Note: Read from the cookie directly to ensure that it isn't outdated.
377-
if (!cookie.length) {
378-
return null;
379-
}
380-
381-
var found = cookie.match(SESSION_COOKIE_NAME_REGEX);
382-
383-
if (!found) {
384-
return null;
385-
}
386-
387-
var start = found.index;
388-
389-
if (-1 == start) {
390-
return null;
391-
}
392-
393-
start += 2;
394-
395-
// Regex includes leading space, so account for it.
396-
if (found[0].charAt(0) === ' ') {
397-
start++;
398-
}
399-
400-
var end = cookie.indexOf(";", start);
401-
402-
if (-1 == end) {
403-
end = cookie.length;
404-
}
405-
406-
return unescape(cookie.substring(start, end));
407-
};
408-
409359
var transformResponse = function(data) {
410360
// Do not deserialize the data -- let API client do that.
411361
// Just return the raw response body.
@@ -446,9 +396,9 @@
446396
// and the same instance will be passed around through the Angular app.
447397
module.factory('taggedApi', taggedApiFactory);
448398

449-
taggedApiFactory.$inject = ['$http', '$q'];
450-
function taggedApiFactory($http, $q) {
451-
var angularAdapter = new TaggedApi.AngularAdapter($http);
399+
taggedApiFactory.$inject = ['$http', '$q', '$window'];
400+
function taggedApiFactory($http, $q, $window) {
401+
var angularAdapter = new TaggedApi.AngularAdapter($http, $window);
452402

453403
var api = new TaggedApi('/api/', {
454404
query: {

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tagged-api-client",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"authors": [
55
"Hector Virgen <hvirgen@tagged.com>"
66
],

lib/http_adapter/angular.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
'use strict';
44

55
var context = typeof exports !== 'undefined' ? exports : window;
6-
var SESSION_COOKIE_NAME_REGEX = /(?:^| )S=/;
76

8-
AngularAdapter.$inject = ['$http', '$document', '$window'];
9-
function AngularAdapter($http, $document, $window) {
7+
AngularAdapter.$inject = ['$http', '$window'];
8+
function AngularAdapter($http, $window) {
109
this._$http = $http;
11-
this._$document = $document;
1210
this._$window = $window;
1311
}
1412

@@ -25,42 +23,6 @@
2523
}).then(formatResponse);
2624
};
2725

28-
AngularAdapter.prototype.getSessionToken = function() {
29-
var cookie = this._$document[0].cookie;
30-
31-
// Note: Read from the cookie directly to ensure that it isn't outdated.
32-
if (!cookie.length) {
33-
return null;
34-
}
35-
36-
var found = cookie.match(SESSION_COOKIE_NAME_REGEX);
37-
38-
if (!found) {
39-
return null;
40-
}
41-
42-
var start = found.index;
43-
44-
if (-1 == start) {
45-
return null;
46-
}
47-
48-
start += 2;
49-
50-
// Regex includes leading space, so account for it.
51-
if (found[0].charAt(0) === ' ') {
52-
start++;
53-
}
54-
55-
var end = cookie.indexOf(";", start);
56-
57-
if (-1 == end) {
58-
end = cookie.length;
59-
}
60-
61-
return unescape(cookie.substring(start, end));
62-
};
63-
6426
var transformResponse = function(data) {
6527
// Do not deserialize the data -- let API client do that.
6628
// Just return the raw response body.

lib/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,6 @@
100100
query[key] = this._options.query[key];
101101
}
102102

103-
var sessionToken;
104-
105-
if (this._http.getSessionToken) {
106-
sessionToken = this._http.getSessionToken();
107-
} else if (this._cookies.S) {
108-
sessionToken = this._cookies.S;
109-
}
110-
111-
if (sessionToken) {
112-
query.session_token = sessionToken;
113-
}
114-
115103
var queryParts = [];
116104
for (var i in query) {
117105
if (!query.hasOwnProperty(i)) continue;

lib/wrappers/angular.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// and the same instance will be passed around through the Angular app.
1616
module.factory('taggedApi', taggedApiFactory);
1717

18-
taggedApiFactory.$inject = ['$http', '$q'];
19-
function taggedApiFactory($http, $q) {
20-
var angularAdapter = new TaggedApi.AngularAdapter($http);
18+
taggedApiFactory.$inject = ['$http', '$q', '$window'];
19+
function taggedApiFactory($http, $q, $window) {
20+
var angularAdapter = new TaggedApi.AngularAdapter($http, $window);
2121

2222
var api = new TaggedApi('/api/', {
2323
query: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tagged-api",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"description": "API client for Tagged with support for nodejs and angularjs",
55
"main": "lib/index.js",
66
"scripts": {

test/unit/lib/http_adapter/angular_test.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ describe('Angular Adapter', function() {
1111
}.bind(this));
1212
}.bind(this))
1313
};
14-
this.$document = [
15-
{
16-
cookie: 'foo=bar; S=test_session_token'
17-
}
18-
];
1914
this.$window = {
2015
location: '/foo'
2116
};
22-
this.adapter = new AngularAdapter(this.$http, this.$document, this.$window);
17+
this.adapter = new AngularAdapter(this.$http, this.$window);
2318
});
2419

2520
it('is a constructor', function() {
@@ -31,9 +26,9 @@ describe('Angular Adapter', function() {
3126
AngularAdapter.$inject.should.contain('$http');
3227
});
3328

34-
it('is injected with $document', function() {
29+
it('is injected with $window', function() {
3530
AngularAdapter.should.have.property('$inject');
36-
AngularAdapter.$inject.should.contain('$document');
31+
AngularAdapter.$inject.should.contain('$window');
3732
});
3833

3934
describe('post()', function() {
@@ -94,29 +89,4 @@ describe('Angular Adapter', function() {
9489
this.$http.post.lastCall.args[2].headers.should.have.property('Content-Type', expectedContentType);
9590
});
9691
});
97-
98-
describe('getSessionToken', function() {
99-
it('returns session token from document cookie', function() {
100-
var sessionToken = this.adapter.getSessionToken();
101-
sessionToken.should.equal('test_session_token');
102-
});
103-
104-
it('returns updated session token from document cookie', function() {
105-
this.$document[0].cookie = 'S=updated_session_token';
106-
var sessionToken = this.adapter.getSessionToken();
107-
sessionToken.should.equal('updated_session_token');
108-
});
109-
110-
it('does not choke on very short cookie names', function() {
111-
this.$document[0].cookie = 'SS=not_the_session_cookie; S=updated_session_token';
112-
var sessionToken = this.adapter.getSessionToken();
113-
sessionToken.should.equal('updated_session_token');
114-
});
115-
116-
it('returns null if no session token is found', function() {
117-
this.$document[0].cookie = 'SS=not_the_session_cookie; foo=bar';
118-
var sessionToken = this.adapter.getSessionToken();
119-
expect(sessionToken).to.be.null;
120-
});
121-
});
12292
});

test/unit/lib/index_test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Tagged API', function() {
1515
defaultParam1: 'defaultValue1',
1616
defaultParam2: 'defaultValue2'
1717
},
18-
cookies: 'S=test_session_token',
18+
cookies: 'L=test_autologin_token',
1919
clientId: 'testClientId',
2020
headers: {
2121
X_Custom_Test: 'text'
@@ -199,14 +199,6 @@ describe('Tagged API', function() {
199199
this.http.post.lastCall.args[0].clientId.should.contain(this.options.clientId);
200200
});
201201

202-
it('passes session token from cookies as a "session_token" query parameter', function() {
203-
this.api.execute('anything');
204-
this.clock.tick(1);
205-
var lastCallArgs = this.http.post.lastCall.args[0];
206-
lastCallArgs.should.have.property('url');
207-
lastCallArgs.url.should.contain('session_token=test_session_token');
208-
});
209-
210202
it('resolves promise with parsed response data', function() {
211203
var expectedResult = { foo: 'bar' };
212204
var promise = this.api.execute('anything');

0 commit comments

Comments
 (0)