Permalink
Browse files

Add test cases for User-Agent.

  • Loading branch information...
1 parent e6fcac7 commit 645b171a2db869462eeb00efd59894ef7bbb3865 @jaredhanson committed May 4, 2013
Showing with 51 additions and 2 deletions.
  1. +2 −2 lib/passport-github/strategy.js
  2. +49 −0 test/strategy-test.js
View
4 lib/passport-github/strategy.js
@@ -24,7 +24,7 @@ var util = require('util')
* - `scope` array of permission scopes to request. valid scopes include:
* 'user', 'public_repo', 'repo', 'gist', or none.
* (see http://developer.github.com/v3/oauth/#scopes for more info)
- * — `userAgent` All API requests MUST include a valid User Agent string.
+ * — `userAgent` All API requests MUST include a valid User Agent string.
* e.g: domain name of your application.
* (see http://developer.github.com/v3/#user-agent-required for more info)
*
@@ -54,7 +54,7 @@ function Strategy(options, verify) {
options.scopeSeparator = options.scopeSeparator || ',';
options.customHeaders = options.customHeaders || {};
- if (!options.customHeaders['User-Agent'] ) {
+ if (!options.customHeaders['User-Agent']) {
options.customHeaders['User-Agent'] = options.userAgent || 'passport-github';
}
View
49 test/strategy-test.js
@@ -18,6 +18,55 @@ vows.describe('GitHubStrategy').addBatch({
'should be named github': function (strategy) {
assert.equal(strategy.name, 'github');
},
+ 'should have default user agent': function (strategy) {
+ assert.equal(strategy._oauth2._customHeaders['User-Agent'], 'passport-github');
+ },
+ },
+
+ 'strategy with user agent option': {
+ topic: function() {
+ return new GitHubStrategy({
+ clientID: 'ABC123',
+ clientSecret: 'secret',
+ userAgent: 'example.com'
+ },
+ function() {});
+ },
+
+ 'should have correct user agent': function (strategy) {
+ assert.equal(strategy._oauth2._customHeaders['User-Agent'], 'example.com');
+ },
+ },
+
+ 'strategy with user agent option in custom headers': {
+ topic: function() {
+ return new GitHubStrategy({
+ clientID: 'ABC123',
+ clientSecret: 'secret',
+ customHeaders: { 'User-Agent': 'example2.com' }
+ },
+ function() {});
+ },
+
+ 'should have correct user agent': function (strategy) {
+ assert.equal(strategy._oauth2._customHeaders['User-Agent'], 'example2.com');
+ },
+ },
+
+ 'strategy with user agent option in custom headers and explicit option': {
+ topic: function() {
+ return new GitHubStrategy({
+ clientID: 'ABC123',
+ clientSecret: 'secret',
+ customHeaders: { 'User-Agent': 'example2.com' },
+ userAgent: 'example3.com'
+ },
+ function() {});
+ },
+
+ 'should prefer custom headers': function (strategy) {
+ assert.equal(strategy._oauth2._customHeaders['User-Agent'], 'example2.com');
+ },
},
'strategy when loading user profile': {

0 comments on commit 645b171

Please sign in to comment.