npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cobbler

v0.0.6

Published

Passport mock for integration tests

Downloads

7

Readme

Cobbler.js

Build Status Code Climate David DM

A spy who creates false passports, visas, diplomas and other documents

Mocking Passport OAuth for integration tests

Install

npm install cobbler --save-dev

Usage

Stratgies

var passport = cobbler('passport-github', {..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!");
    })
    .end(function() {
      passport.restore();
      server.close();
      done();
   });
});

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);

Login Session

cobbler provides a way to "login as a user" without actually going through the actual login (above).

var passport = cobbler('session', '12345');

Note the first agrument string 'session' (case-sensitive). The 2nd argument should be the object that is passed to the passport.deserializeUser method. ex.

passport.deserializeUser(function(id, done) {
  User.findOne({_id: id})
    .exec(function(err, resource) {
      if (err) {
        return done(err, null);
      }
      done(null, resource);
    });
});

id would be a user.id.


Your passport.deserializeUser will actually be invoked

Restoring

You can restore the old functions by calling restore().

var passport = cobbler('passport-github', {..profile..});

// do the test

passport.restore();

API

cobbler, for stratgies, 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;

For sessions, the first argument must be "session".


It should be noted that you may need to clear the require.cache of your app between tests.

Notes

TODO

  • More test coverage 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.
  • Ability to set callback url code and error query params

Contributors. Many Thanks!

License

MIT