Permalink
Browse files

Rearrange code.

  • Loading branch information...
jaredhanson committed Jun 15, 2012
1 parent a31351d commit fc928cf6a0f3d9f6bfd5192a0b7b5c07de582d45
Showing with 95 additions and 95 deletions.
  1. +36 −36 lib/passport-openid/strategy.js
  2. +59 −59 test/strategy-test.js
@@ -196,6 +196,13 @@ Strategy.prototype.authenticate = function(req) {
}
}
+Strategy.prototype.saveAssociation = function(fn) {
+ openid.saveAssociation = function(provider, type, handle, secret, expiry, callback) {
+ fn(handle, provider, type, secret, expiry, callback)
+ }
+ return this; // return this for chaining
+}
+
Strategy.prototype.loadAssociation = function(fn) {
openid.loadAssociation = function(handle, callback) {
fn(handle, function(err, provider, algorithm, secret) {
@@ -211,83 +218,76 @@ Strategy.prototype.loadAssociation = function(fn) {
return this; // return this for chaining
}
-Strategy.prototype.saveAssociation = function(fn) {
- openid.saveAssociation = function(provider, type, handle, secret, expiry, callback) {
- fn(handle, provider, type, secret, expiry, callback)
- }
- return this; // return this for chaining
-}
-
/**
- * Register a function used to load discovered info from cache.
+ * Register a function used to cache discovered info.
*
* Caching discovered information about a provider can significantly speed up
* the verification of positive assertions. Registering a function allows an
- * application to implement laoding of this info as necessary.
+ * application to implement storage of this info as necessary.
*
- * The function accepts two arguments: `identifier` (which serves as a key to
- * the provider information), and `done` a callback to invoke when the
- * information has been loaded.
+ * The function accepts three arguments: `identifier` (which serves as a key to
+ * the provider information), `provider` (the provider information being
+ * cached), and `done` a callback to invoke when the information has been
+ * stored.
*
- * This function is used to retrieve data previously cached with the
- * corresponding `saveDiscoveredInfo` function.
+ * After the data has been cached, the corresponding `loadDiscoveredInfo`
+ * function will be used to look it up when needed.
*
- * This corresponds directly to the `loadDiscoveredInformation` provided by the
+ * This corresponds directly to the `saveDiscoveredInformation` provided by the
* underlying node-openid module. Refer to that for more information.
*
* Examples:
*
- * strategy.loadDiscoveredInfo(function(identifier, done) {
- * loadInfo(identifier, function(err, provider) {
+ * strategy.saveDiscoveredInfo(function(identifier, provider, done) {
+ * saveInfo(identifier, provider, function(err) {
* if (err) { return done(err) }
* return done();
* });
- * });
+ * };
*
* @param {Function} fn
* @return {Strategy} for chaining
* @api public
*/
-Strategy.prototype.loadDiscoveredInfo =
-Strategy.prototype.loadDiscoveredInformation = function(fn) {
- openid.loadDiscoveredInformation = fn;
+Strategy.prototype.saveDiscoveredInfo =
+Strategy.prototype.saveDiscoveredInformation = function(fn) {
+ openid.saveDiscoveredInformation = fn;
return this; // return this for chaining
}
/**
- * Register a function used to cache discovered info.
+ * Register a function used to load discovered info from cache.
*
* Caching discovered information about a provider can significantly speed up
* the verification of positive assertions. Registering a function allows an
- * application to implement storage of this info as necessary.
+ * application to implement laoding of this info as necessary.
*
- * The function accepts three arguments: `identifier` (which serves as a key to
- * the provider information), `provider` (the provider information being
- * cached), and `done` a callback to invoke when the information has been
- * stored.
+ * The function accepts two arguments: `identifier` (which serves as a key to
+ * the provider information), and `done` a callback to invoke when the
+ * information has been loaded.
*
- * After the data has been cached, the corresponding `loadDiscoveredInfo`
- * function will be used to look it up when needed.
+ * This function is used to retrieve data previously cached with the
+ * corresponding `saveDiscoveredInfo` function.
*
- * This corresponds directly to the `saveDiscoveredInformation` provided by the
+ * This corresponds directly to the `loadDiscoveredInformation` provided by the
* underlying node-openid module. Refer to that for more information.
*
* Examples:
*
- * strategy.saveDiscoveredInfo(function(identifier, provider, done) {
- * saveInfo(identifier, provider, function(err) {
+ * strategy.loadDiscoveredInfo(function(identifier, done) {
+ * loadInfo(identifier, function(err, provider) {
* if (err) { return done(err) }
* return done();
* });
- * };
+ * });
*
* @param {Function} fn
* @return {Strategy} for chaining
* @api public
*/
-Strategy.prototype.saveDiscoveredInfo =
-Strategy.prototype.saveDiscoveredInformation = function(fn) {
- openid.saveDiscoveredInformation = fn;
+Strategy.prototype.loadDiscoveredInfo =
+Strategy.prototype.loadDiscoveredInformation = function(fn) {
+ openid.loadDiscoveredInformation = fn;
return this; // return this for chaining
}
View
@@ -1102,50 +1102,6 @@ vows.describe('OpenIDStrategy').addBatch({
},
},
- 'strategy with loadAssociation function': {
- topic: function() {
- var strategy = new OpenIDStrategy({
- returnURL: 'https://www.example.com/auth/openid/return',
- },
- function(identifier, done) {
- done(null, { identifier: identifier });
- }
- );
-
- strategy.loadAssociation(function(handle, done) {
- var provider = { endpoint: 'https://www.google.com/accounts/o8/ud',
- version: 'http://specs.openid.net/auth/2.0',
- localIdentifier: 'http://www.google.com/profiles/jaredhanson',
- claimedIdentifier: 'http://jaredhanson.net' };
-
- strategy._args = {};
- strategy._args.handle = handle;
- done(null, provider, 'sha256', 'shh-its-secret');
- });
- return strategy;
- },
-
- 'after calling openid.loadAssociation': {
- topic: function(strategy) {
- var self = this;
- var handle = 'foo-xyz-123';
-
- openid.loadAssociation(handle, function(err, association) {
- self.callback(null, strategy, association);
- });
- },
-
- 'should call registered function' : function(err, strategy) {
- assert.equal(strategy._args.handle, 'foo-xyz-123');
- },
- 'should supply provider' : function(err, strategy, association) {
- assert.equal(association.provider.endpoint, 'https://www.google.com/accounts/o8/ud');
- assert.equal(association.type, 'sha256');
- assert.equal(association.secret, 'shh-its-secret');
- },
- },
- },
-
'strategy with saveAssociation function': {
topic: function() {
var strategy = new OpenIDStrategy({
@@ -1195,7 +1151,7 @@ vows.describe('OpenIDStrategy').addBatch({
},
},
- 'strategy with loadDiscoveredInfo function': {
+ 'strategy with loadAssociation function': {
topic: function() {
var strategy = new OpenIDStrategy({
returnURL: 'https://www.example.com/auth/openid/return',
@@ -1205,38 +1161,36 @@ vows.describe('OpenIDStrategy').addBatch({
}
);
- strategy.loadDiscoveredInfo(function(identifier, done) {
+ strategy.loadAssociation(function(handle, done) {
var provider = { endpoint: 'https://www.google.com/accounts/o8/ud',
version: 'http://specs.openid.net/auth/2.0',
localIdentifier: 'http://www.google.com/profiles/jaredhanson',
claimedIdentifier: 'http://jaredhanson.net' };
strategy._args = {};
- strategy._args.identifier = identifier;
- done(null, provider);
+ strategy._args.handle = handle;
+ done(null, provider, 'sha256', 'shh-its-secret');
});
return strategy;
},
- 'should alias function' : function(strategy) {
- assert.strictEqual(strategy.loadDiscoveredInfo, strategy.loadDiscoveredInformation);
- },
-
- 'after calling openid.loadDiscoveredInformation': {
+ 'after calling openid.loadAssociation': {
topic: function(strategy) {
var self = this;
- var key = 'http://jaredhanson.net';
+ var handle = 'foo-xyz-123';
- openid.loadDiscoveredInformation(key, function(err, provider) {
- self.callback(null, strategy, provider);
+ openid.loadAssociation(handle, function(err, association) {
+ self.callback(null, strategy, association);
});
},
'should call registered function' : function(err, strategy) {
- assert.equal(strategy._args.identifier, 'http://jaredhanson.net');
+ assert.equal(strategy._args.handle, 'foo-xyz-123');
},
- 'should supply provider' : function(err, strategy, provider) {
- assert.equal(provider.endpoint, 'https://www.google.com/accounts/o8/ud');
+ 'should supply provider' : function(err, strategy, association) {
+ assert.equal(association.provider.endpoint, 'https://www.google.com/accounts/o8/ud');
+ assert.equal(association.type, 'sha256');
+ assert.equal(association.secret, 'shh-its-secret');
},
},
},
@@ -1285,6 +1239,52 @@ vows.describe('OpenIDStrategy').addBatch({
},
},
+ 'strategy with loadDiscoveredInfo function': {
+ topic: function() {
+ var strategy = new OpenIDStrategy({
+ returnURL: 'https://www.example.com/auth/openid/return',
+ },
+ function(identifier, done) {
+ done(null, { identifier: identifier });
+ }
+ );
+
+ strategy.loadDiscoveredInfo(function(identifier, done) {
+ var provider = { endpoint: 'https://www.google.com/accounts/o8/ud',
+ version: 'http://specs.openid.net/auth/2.0',
+ localIdentifier: 'http://www.google.com/profiles/jaredhanson',
+ claimedIdentifier: 'http://jaredhanson.net' };
+
+ strategy._args = {};
+ strategy._args.identifier = identifier;
+ done(null, provider);
+ });
+ return strategy;
+ },
+
+ 'should alias function' : function(strategy) {
+ assert.strictEqual(strategy.loadDiscoveredInfo, strategy.loadDiscoveredInformation);
+ },
+
+ 'after calling openid.loadDiscoveredInformation': {
+ topic: function(strategy) {
+ var self = this;
+ var key = 'http://jaredhanson.net';
+
+ openid.loadDiscoveredInformation(key, function(err, provider) {
+ self.callback(null, strategy, provider);
+ });
+ },
+
+ 'should call registered function' : function(err, strategy) {
+ assert.equal(strategy._args.identifier, 'http://jaredhanson.net');
+ },
+ 'should supply provider' : function(err, strategy, provider) {
+ assert.equal(provider.endpoint, 'https://www.google.com/accounts/o8/ud');
+ },
+ },
+ },
+
'strategy constructed without a validate callback': {
'should throw an error': function (strategy) {
assert.throws(function() {

0 comments on commit fc928cf

Please sign in to comment.