-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "auth0-rule-as-action", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Run an Auth0 Rule as an Action", | ||
"author": "Patrick Kubiak <[email protected]>", | ||
"main": "dist/RuleToAction.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
"use strict"; | ||
|
||
import { createRequire } from "module"; | ||
const require = createRequire(import.meta.url); | ||
|
||
import { beforeEach, afterEach, describe, it } from "mocha"; | ||
const chai = require('chai'); | ||
const spies = require('chai-spies'); | ||
chai.use(spies); | ||
|
||
const sandbox = chai.spy.sandbox(); | ||
|
||
import { createEvent } from "./_mocks/event.js"; | ||
import { api } from "./_mocks/api.js"; | ||
import { setupApiSpy } from "./_helpers/setupApiSpy.js"; | ||
import { convert } from "../src/RuleToAction.mjs" | ||
|
||
let event; | ||
|
||
describe('RuleToAction', function () { | ||
|
||
beforeEach(function () { | ||
// reset Auth0 event | ||
event = createEvent(); | ||
// spy on all Auth0 api methods | ||
setupApiSpy(sandbox, api); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('using rules', function() { | ||
it('denies access for rule that throws error', async function () { | ||
// Prepare | ||
let rule = function (user, context, callback) { | ||
return callback( | ||
new UnauthorizedError("This app is unavailable") | ||
Check failure on line 38 in test/RuleToAction.test.js GitHub Actions / build
Check failure on line 38 in test/RuleToAction.test.js GitHub Actions / build
|
||
); | ||
} | ||
let context = {}; | ||
|
||
// Act | ||
await convert(event, api, rule, context); | ||
|
||
// Assert | ||
chai.expect(api.access.deny).to.have.been.called.with("This app is unavailable"); | ||
}); | ||
|
||
it('converts exampleRule rule', async function () { | ||
// Prepare | ||
let rule = function exampleRule(user, context, callback) { | ||
// ID and Access token claims | ||
context.idToken["https://example.com/testIDToken"] = "testIDTokenValue"; | ||
context.accessToken["https://example.com/testAccessToken"] = "testAccessTokenValue"; | ||
// SAML | ||
context.samlConfiguration.mappings = { | ||
'https://example.com/SAML/Attributes/Role': 'role', | ||
'https://example.com/SAML/Attributes/RoleSessionName': 'session' | ||
}; | ||
|
||
callback(null, user, context); | ||
} | ||
let context = {}; | ||
|
||
// Act | ||
await convert(event, api, rule, context); | ||
|
||
// Assert | ||
chai.expect(api.idToken.setCustomClaim).to.have.been.called.with("https://example.com/testIDToken", "testIDTokenValue"); | ||
chai.expect(api.accessToken.setCustomClaim).to.have.been.called.with("https://example.com/testAccessToken", "testAccessTokenValue"); | ||
chai.expect(api.samlResponse.setAttribute).to.have.been.called.with("https://example.com/SAML/Attributes/Role", "role"); | ||
chai.expect(api.samlResponse.setAttribute).to.have.been.called.with("https://example.com/SAML/Attributes/RoleSessionName", "session"); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters