Skip to content

Commit 5636296

Browse files
committed
Test cases for credentials with spaces in header.
1 parent aaf999a commit 5636296

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

test/strategies/consumer-test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,66 @@ vows.describe('ConsumerStrategy').addBatch({
7777
},
7878
},
7979

80+
'strategy handling a valid request without a request token placing credentials with spaces in header': {
81+
topic: function() {
82+
var strategy = new ConsumerStrategy(
83+
// consumer callback
84+
function(consumerKey, done) {
85+
if (consumerKey == 'abc123') {
86+
done(null, { id: '1' }, 'ssh-secret');
87+
} else {
88+
done(new Error('something is wrong'))
89+
}
90+
},
91+
// token callback
92+
function(requestToken, done) {
93+
done(new Error('token callback should not be called'));
94+
}
95+
);
96+
return strategy;
97+
},
98+
99+
'after augmenting with actions': {
100+
topic: function(strategy) {
101+
var self = this;
102+
var req = {};
103+
strategy.success = function(user, info) {
104+
self.callback(null, user, info);
105+
}
106+
strategy.fail = function(challenge, status) {
107+
self.callback(new Error('should not be called'));
108+
}
109+
strategy.error = function(err) {
110+
self.callback(new Error('should not be called'));
111+
}
112+
113+
req.url = '/oauth/request_token';
114+
req.method = 'POST';
115+
req.headers = {};
116+
req.headers['host'] = '127.0.0.1:3000';
117+
req.headers['authorization'] = 'OAuth oauth_callback="http%3A%2F%2Fmacbook-air.local.jaredhanson.net%3A3001%2Foauth%2Fcallback", oauth_consumer_key="abc123", oauth_nonce="fNyKdt8ZTgTVdEABtUMFzcXRxF4a230q", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1341176111", oauth_version="1.0", oauth_signature="tgsFsPL%2BDDQmfEz6hbCywhO%2BrE4%3D"';
118+
req.query = url.parse(req.url, true).query;
119+
req.connection = { encrypted: false };
120+
process.nextTick(function () {
121+
strategy.authenticate(req);
122+
});
123+
},
124+
125+
'should not generate an error' : function(err, user, info) {
126+
assert.isNull(err);
127+
},
128+
'should authenticate' : function(err, user, info) {
129+
assert.equal(user.id, '1');
130+
},
131+
'should set scheme to OAuth' : function(err, user, info) {
132+
assert.equal(info.scheme, 'OAuth');
133+
},
134+
'should set callbackURL' : function(err, user, info) {
135+
assert.equal(info.oauth.callbackURL, 'http://macbook-air.local.jaredhanson.net:3001/oauth/callback');
136+
},
137+
},
138+
},
139+
80140
'strategy handling a valid request without a request token using host option instead of host header': {
81141
topic: function() {
82142
var strategy = new ConsumerStrategy(

test/strategies/token-test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,71 @@ vows.describe('TokenStrategy').addBatch({
8282
},
8383
},
8484

85+
'strategy handling a valid request with credentials with spaces in header': {
86+
topic: function() {
87+
var strategy = new TokenStrategy(
88+
// consumer callback
89+
function(consumerKey, done) {
90+
if (consumerKey == '1234') {
91+
done(null, { id: '1' }, 'keep-this-secret');
92+
} else {
93+
done(new Error('something is wrong'))
94+
}
95+
},
96+
// verify callback
97+
function(accessToken, done) {
98+
if (accessToken == 'abc-123-xyz-789') {
99+
done(null, { username: 'bob' }, 'lips-zipped');
100+
} else {
101+
done(new Error('something is wrong'))
102+
}
103+
}
104+
);
105+
return strategy;
106+
},
107+
108+
'after augmenting with actions': {
109+
topic: function(strategy) {
110+
var self = this;
111+
var req = {};
112+
strategy.success = function(user, info) {
113+
self.callback(null, user, info);
114+
}
115+
strategy.fail = function(challenge, status) {
116+
self.callback(new Error('should not be called'));
117+
}
118+
strategy.error = function(err) {
119+
self.callback(new Error('should not be called'));
120+
}
121+
122+
req.url = '/1/users/show.json?screen_name=jaredhanson&user_id=1705';
123+
req.method = 'GET';
124+
req.headers = {};
125+
req.headers['host'] = '127.0.0.1:3000';
126+
req.headers['authorization'] = 'OAuth oauth_consumer_key="1234", oauth_nonce="A7E738D9A9684A60A40607017735ADAD", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1339004912", oauth_token="abc-123-xyz-789", oauth_version="1.0", oauth_signature="TBrJJJWS896yWrbklSbhEd9MGQc%3D"';
127+
req.query = url.parse(req.url, true).query;
128+
req.connection = { encrypted: false };
129+
process.nextTick(function () {
130+
strategy.authenticate(req);
131+
});
132+
},
133+
134+
'should not generate an error' : function(err, user, info) {
135+
assert.isNull(err);
136+
},
137+
'should authenticate' : function(err, user, info) {
138+
assert.equal(user.username, 'bob');
139+
},
140+
'should set scheme to OAuth' : function(err, user, info) {
141+
assert.equal(info.scheme, 'OAuth');
142+
},
143+
'should set consumer' : function(err, user, info) {
144+
assert.equal(info.consumer.id, '1');
145+
assert.strictEqual(info.client, info.consumer);
146+
},
147+
},
148+
},
149+
85150
'strategy handling a valid request using host option instead of host header': {
86151
topic: function() {
87152
var strategy = new TokenStrategy(

0 commit comments

Comments
 (0)