Comparing version 0.0.1 to 0.0.2
@@ -39,7 +39,7 @@ /* jshint node: true */ | ||
var proto = strategy.prototype; | ||
var proto = ('userProfile' in strategy) ? strategy : strategy.prototype; | ||
// override methods | ||
strategy.prototype.userProfile = userProfile.call(this, proto, profile); | ||
strategy.prototype.authenticate = authenticate.call(this, proto, passauth, opts); | ||
proto.userProfile = userProfile.call(this, proto, profile); | ||
proto.authenticate = authenticate.call(this, proto, passauth, opts); | ||
@@ -46,0 +46,0 @@ /* |
{ | ||
"name": "cobbler", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Passport mock for integration tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,7 +12,7 @@ # Cobbler.js | ||
npm install cobbler | ||
npm install cobbler --save-dev | ||
## Usage | ||
var passport = cobbler('passport-github', profile); | ||
var passport = cobbler('passport-github', {..profile..}); | ||
@@ -34,4 +34,36 @@ var server = app.listen(7331, function() { | ||
`cobbler` mocks the calls to the OAuth service and redirects you to the *callback url* allowing you to bypass the network connections, but allows you to go through the full (most of it atleast) process without mocking key functions in managing sessions, authenticated or initialization of `passport`. | ||
`cobbler` mocks the calls to the OAuth service and redirects you to the *callback url* allowing you to bypass the network connections, but allows you to go through the full (most of it at least) process without mocking key functions in managing sessions, authenticated or initialization of `passport`. | ||
--- | ||
If you want to simulate a successful authentication, the "profile" argument should be an object similar to what you would receive from an OAuth `userProfile` call. This will hit your Strategy callback and go through the normal chain of events. | ||
var passport = cobbler('passport-github', { | ||
provider: 'github', | ||
id: 12345, | ||
displayName: 'John Doe' | ||
}); | ||
To simulate a failed authentication, the "profile" argument should be `false`. | ||
var passport = cobbler('passport-github', false); | ||
--- | ||
You can restore the old functions by calling `restore()`. | ||
var passport = cobbler('passport-github', {..profile..}); | ||
// do the test | ||
passport.restore(); | ||
--- | ||
`cobbler` can be passed either the npm name eg. '*passport-github*' or the exports eg. `var passportGithub = require('passport-github');` or the strategy eg. `var GithubStrategy = require('passport-github').Strategy;` | ||
--- | ||
It should be noted that `require` does cache so you may need to clear the `require.cache` of your `app` between tests. | ||
## Notes | ||
@@ -44,2 +76,8 @@ | ||
## TODO | ||
* More test converage for other Passport OAuth Strategies (only Github at this point) | ||
* Ability to set arguments such as `accessToken, refreshToken, params` | ||
* Ability to test `fail` and `error` calls. | ||
## License | ||
@@ -46,0 +84,0 @@ |
@@ -87,2 +87,23 @@ /* jshint node: true */ | ||
}); | ||
it("can be passed the prototype object of the strategy", function(done) { | ||
var passportGithub = require('passport-github'); | ||
var passport = cobbler(passportGithub.Strategy.prototype, profile); | ||
var server = app.listen(7331, function() { | ||
new WalkingDead(url).zombify(zopts) | ||
.when(function(browser, next) { | ||
browser.clickLink('[rel="login-with-github"]', next); | ||
}) | ||
.then(function(browser) { | ||
assert.equal(browser.text("title"), "Welcome!"); | ||
assert.equal(browser.text("h1"), "Hello John Doe!"); | ||
}) | ||
.end(function() { | ||
passport.restore(); | ||
server.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14436
364
84