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

auth0-rules-testharness

v1.1.0

Published

deploy, execute, and test the output of Auth0 Rules using a webtask sandbox environment.

Downloads

140

Readme

What is it?

The auth0-rules-testharness library provides an easy way to deploy, execute, and test the output of Auth0 Rules using a real webtask sandbox environment. It is very simple to use, and requires under 5 minutes to get started testing your Auth0 Rules!

This README offers full instructions. However, for an easy to understand seed project that helps users get started immediately, please see auth0-rules-testharness-sample.

See here for further documentation on Auth0 Rules.

Depending on your needs there are several pragmatic ways to test Rules without resorting to actually deploying and executing them in a webtask sandbox environment. One solution is to use the webtask runtime. Doing this offers a series of components that replicate the behaviour of the runtime component of https://webtask.io.

However, sometimes you just want to execute your Rule against the same sandbox environment it will be deployed to at Runtime in Auth0, and test everything works as expected. You may also wish to write your Rules using a test driven development approach, and gain real feedback as you code - this is where this npm module can help. It actually takes your Rule script, and any user, context and callback you give it, then spins up a webtask, executes your Rule passing the results to the provided callback, and finally tears the environment down again.

Notes

It is worth noting that under the covers, the script this npm module generates for deployment to a webtask environment depends upon auth0-authz-rules-api. If you wish to study and understand the generated script code that wraps the Rule being tested, then this is the place to look ;)

For a similar NPM module to deploy, execute, and test the output of Auth0 Custom DB Scripts using a real webtask sandbox environment, please see auth0-custom-db-testharness.

Prerequisites

Assumes you have an Auth0 Tenant webtask container to run your Rules against.

Create a free Auth0 Account

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.

What is Auth0?

See bottom of this README for further info...

How to use it?

Just install it as an npm dependency and reference in your testsuite.

$ npm install auth0-rules-testharness

Below is a complete testsuite illustrating how you might go about using this library. Please note, the user and context can be as lightweight or as realistic as you wish according to your test needs.

You can get your webtask token from your auth0 dashboard

It is referenced in Step 2.

'use strict';

var expect = require('chai').expect;
var runInSandbox = require("auth0-rules-testharness");

var user = {
  "email": "[email protected]",
  "email_verified": true,
  "name": "Richard Seldon"
};

var context = {
  "clientID": "wWXS5rz3asdfdfkzbCXho3zNPNv77c",
  "clientName": "My Auth0 Client",
  "connection": "MY-DB"
};

var configuration = {
  NAME: 'world'
};

var params = {
  timeout: 5,
  ca: '',
  tenant: 'my-super-tenant',
  url: 'https://sandbox.it.auth0.com',
  token: '<webtask-token>'
};


describe('auth0-rules-testharness', function () {

  var ruleScript = `function (user, context, callback) {
  console.log('hello,', configuration.NAME);
  user.foo = "bar";
  callback(null, user, context);
}`;

  it('should console log "hello, world" - available in output array', function (done) {

    var callback = function (err, result, output, stats) {
      // console.log('output: ', output);
      expect(output[0]).to.equal('hello, world');
      done();
    };

    var args = [user, context, callback];
    runInSandbox(ruleScript, args, configuration, params);
  });

  it('should append attribute "foo" to user with value "bar" - available in result object', function (done) {

    var callback = function (err, result, output, stats) {
      // console.log('result: ', result);
      expect(result.foo).to.equal('bar');
      done();
    };

    var args = [user, context, callback];
    runInSandbox(ruleScript, args, configuration, params);
  });

});

Above, hopefully everything is reasonably self-documenting if you are already familiar with Auth0 Rules. The signature of a rule is as follows:

function (user, context, callback) {
  // TODO: implement your rule
  callback(null, user, context);
}

As you can see, we need to provide a user, context and callback.

This library allows the end-user to offer any user or context objec they want, and expects any Tests you want to run on the results to be in the callback function.

The configuration object can contain any special configuration constants you may have. For example, testing your rule when it expects an API endpoint etc.

The params object takes a set of expected attribute values

var params = {
  timeout: 5,
  ca: '',
  tenant: 'my-super-tenant',
  url: 'https://sandbox.it.auth0.com',
  token: '<webtask-token>'
};

Params Attributes Description

  • timeout: refers the timeout in seconds for the webtask to execute.
  • ca: you can just leave as empty string.
  • tenant: your tenant name in Auth0
  • url: sandbox container url - 'https://sandbox.it.auth0.com' for public cloud
  • token: the webtask token. You can get your webtask token from your auth0 dashboard.

That is it! You should be up and running in under 5 minutes with an easy way to execute and test your Rules against a webtask sandbox environment.

Special Warning

It is possible that if one Rule fails due to malformed Script content, it could bring down the Webtask Container for a short period of time, affecting any other webtasks deployed in the same container. For this reason, usage of this library against a PRODUCTION webtask environment is strongly discouraged.

Please note this is not a limitation of this library, but rather do with the behaviour of webtasks themselves - this is identical behaviour to writing a malformed Rule in the Auth0 Dashboard and executing it with an authentication request. Please see here for more information on webtasks, the underlying technology that Auth0 Rules are based upon.

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, among others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

Create a free Auth0 Account

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.