Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auth0-ext-compilers

Package Overview
Dependencies
Maintainers
37
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth0-ext-compilers - npm Package Compare versions

Comparing version 5.5.3 to 6.0.0

lib/errors/ExtensibilityUserError.js

198

lib/adapter.js

@@ -1,126 +0,118 @@

'use strict';
"use strict";
module.exports = {
respondWithError,
wrap,
respondWithError,
wrap,
};
function respondWithError(error, res) {
if (!(error instanceof Error)) {
error = new Error(error.message || String(error) || "Unknown error");
}
function respondWithError(error, res) {
if (!(error instanceof Error)) {
error = new Error(error.message || String(error) || 'Unknown error')
}
if (!error.statusCode) {
error.statusCode = 500;
}
const statusCode = error.statusCode;
const headers = {
'Content-Type': 'application/json',
};
const payload = {
message: error.message,
statusCode: error.statusCode,
};
['code', 'errno', 'error', 'error_description', 'data']
.forEach(key => {
if (error[key]) payload[key] = error[key];
});
if (error.statusCode === 500 && error.stack) {
payload.stack = error.stack;
}
let json;
try {
json = JSON.stringify(payload);
} catch (e) {
const error = new Error('Error serializing error: ' + e.message);
error.statusCode = 500;
return respondWithError(error, res);
}
res.writeHead(statusCode, headers);
res.end(json);
const payload = {
status: "error",
data: {},
};
Object.getOwnPropertyNames(error).forEach((key) => {
payload.data[key] = error[key];
})
let json;
try {
json = JSON.stringify(payload)
} catch (e) {
const error = new Error("Error serializing error: " + e.message);
return respondWithError(error, res);
}
res.writeHead(200, { "Content-Type": "application/json" });
res.end(json);
}
function wrap(webtaskFn, payloadAdapter) {
if (!payloadAdapter) {
// The default payload adapter is an identity function
payloadAdapter = payload => payload;
if (!payloadAdapter) {
// The default payload adapter is an identity function
payloadAdapter = (payload) => payload;
}
let parseBody;
const bodylessMethods = ["GET", "HEAD", "OPTIONS"];
return handler;
function handler(ctx, req, res) {
// There will be no body to parse.
if (bodylessMethods.indexOf(req.method) !== -1) {
return webtaskFn(ctx, buildResponse);
}
let parseBody;
const bodylessMethods = ['GET', 'HEAD', 'OPTIONS'];
// The body has already been parsed before control is handed over to the compiler.
// This means that the platform already did the parsing.
if (ctx.body) {
return webtaskFn(ctx, buildResponse);
}
return handler;
if (!parseBody) {
// Defer loading wreck until needed
const Wreck = require("wreck");
parseBody = Wreck.read.bind(Wreck);
}
function handler (ctx, req, res) {
// There will be no body to parse.
if (bodylessMethods.indexOf(req.method) !== -1) {
return webtaskFn(ctx, buildResponse);
}
// The body has yet to be parsed. Delegate this logic to wreck.
return parseBody(req, { json: true }, (error, body) => {
if (error) {
return buildResponse(error);
}
// The body has already been parsed before control is handed over to the compiler.
// This means that the platform already did the parsing.
if (ctx.body) {
return webtaskFn(ctx, buildResponse);
}
ctx.body = body;
if (!parseBody) {
// Defer loading wreck until needed
const Wreck = require('wreck');
return webtaskFn(ctx, buildResponse);
});
parseBody = Wreck.read.bind(Wreck);
}
function buildResponse(error /*, arg1, arg2, ...*/) {
if (error) {
return respondWithError(error, res);
}
// The body has yet to be parsed. Delegate this logic to wreck.
return parseBody(req, { json: true }, (error, body) => {
if (error) {
return buildResponse(error);
}
const response = {
statusCode: 200,
headers: {},
status: 'success',
// Marshall the non-error callback arguments into the wire format
// that the extension <--> auth0-server protocol expects
data: payloadAdapter.apply(
null,
Array.prototype.slice.call(arguments, 1)
),
};
ctx.body = body;
// Currently the respond function assumes json as the only format that
// will be sent over the wire. In the future we could inspect the request
// and do applicable content negotiation.
let json;
return webtaskFn(ctx, buildResponse);
});
try {
json = JSON.stringify(response);
} catch (e) {
return respondWithError(
new Error(
"Error when JSON serializing the result of the extension point"
),
res
);
}
response.headers["Content-Type"] = "application/json";
function buildResponse(error /*, arg1, arg2, ...*/) {
if (error) {
return respondWithError(error, res);
}
const response = {
statusCode: 200,
headers: { },
// Marshall the non-error callback arguments into the wire format
// that the extension <--> auth0-server protocol expects
data: payloadAdapter.apply(null, Array.prototype.slice.call(arguments, 1)),
}
res.writeHead(response.statusCode, response.headers);
res.end(json);
// Currently the respond function assumes json as the only format that
// will be sent over the wire. In the future we could inspect the request
// and do applicable content negotiation.
let json;
try {
json = JSON.stringify(response.data);
} catch (e) {
return respondWithError(new Error('Error when JSON serializing the result of the extension point'), res);
}
response.headers['Content-Type'] = 'application/json';
res.writeHead(response.statusCode, response.headers);
res.end(json);
return;
}
return;
}
}
}
}

@@ -5,9 +5,33 @@ 'use strict';

const Factory = require('./compilerFactory');
const ExtensibilityUserError = require('../errors/ExtensibilityUserError');
module.exports = Factory.createCompiler(clientCredentialsExchangeHandler);
class InvalidRequestError extends ExtensibilityUserError {
constructor(message) {
super(message);
}
}
class InvalidScopeError extends ExtensibilityUserError {
constructor(message) {
super(message);
}
}
class ServerError extends ExtensibilityUserError {
constructor(message) {
super(message);
}
}
const PRELUDE_ITEMS = [
InvalidRequestError,
InvalidScopeError,
ServerError
];
module.exports = Factory.createCompiler(clientCredentialsExchangeHandler, PRELUDE_ITEMS);
function clientCredentialsExchangeHandler (func, webtaskContext, cb) {
return Authz.is_authorized(webtaskContext, error => {
if (error) return cb(error);
if (typeof webtaskContext.body !== 'object')

@@ -23,9 +47,9 @@ return cb(new Error('Body received by extensibility point is not an object'));

const context = typeof webtaskContext.body.context === 'object'
? webtaskContext.body.context
: {};
? webtaskContext.body.context
: {};
context.webtask = webtaskContext;
return func(webtaskContext.body.client, webtaskContext.body.scope, webtaskContext.body.audience, context, cb);
});
});
}
const Adapter = require('../adapter');
const ExtensibilityUserError = require('../errors/ExtensibilityUserError')
module.exports = {

@@ -8,2 +8,10 @@ createCompiler,

function addPreludeItems(script, items) {
return `
${ExtensibilityUserError.toString()}
${items.map(i => i.toString()).join("\n")}
${script}
`;
}
/**

@@ -17,3 +25,3 @@ * Factory Function to be used internally by Extensibility Points Implementations

*/
function createCompiler(handler) {
function createCompiler(handler, preludeItems = []) {
/**

@@ -26,3 +34,5 @@ * Extensibility Point Compiler.

return function extensibilityPointCompiler(options, cb) {
options.nodejsCompiler(options.script, function (error, func) {
const script = addPreludeItems(options.script, preludeItems);
options.nodejsCompiler(script, function (error, func) {
if (error) {

@@ -48,2 +58,2 @@ // Return a wrapped webtask function that will generate an error

};
}
}

@@ -5,9 +5,17 @@ 'use strict';

const Factory = require('./compilerFactory');
const ExtensibilityUserError = require('../errors/ExtensibilityUserError');
module.exports = Factory.createCompiler(userRegistrationHandler);
class PreUserRegistrationError extends ExtensibilityUserError {
constructor(message, friendlyMessage) {
super(message);
this.friendlyMessage = friendlyMessage || message;
}
}
module.exports = Factory.createCompiler(userRegistrationHandler, [PreUserRegistrationError]);
function userRegistrationHandler (func, webtaskContext, cb) {
return Authz.is_authorized(webtaskContext, error => {
if (error) return cb(error);
if (!webtaskContext.body || typeof webtaskContext.body !== 'object') {

@@ -14,0 +22,0 @@ return cb(new Error('Body received by extensibility point is not an object'));

@@ -8,3 +8,3 @@ {

},
"version": "5.5.3",
"version": "6.0.0",
"description": "Webtask compilers for Auth0 platform extensibility points",

@@ -33,2 +33,3 @@ "engines": {

"mocha": "^7.0.1",
"sinon": "^9.0.2",
"webtask-runtime": "^1.3.0"

@@ -35,0 +36,0 @@ },

@@ -106,1 +106,61 @@ This repository contains [webtask compilers](https://webtask.io/docs/webtask-compilers) that enable custom programming models for Auth0 platform extensibility points.

```
### Response Contracts Guidlines
When building a compiler for a hook, all responses should be status code 200.
If the following guidelines are not followed, the client (auth0-ext) will not process the response correctly.
```
{
status: 'success' | 'error',
data: {}
}
```
#### Success
Response should contain:
`status = 'success'`
Success conditions should be when the code ran to completion and returning the response in the `data` property.
Example response:
```json
{
"status": "success",
"data": {
"user": {
"user_metadata": "object",
"app_metadata": "object",
// other properties are ignored
}
}
}
```
#### Error
Response should contain:
`status = 'error'`
Error conditions should be when there is an error thrown in the script. This error object should be passed in to the `data` property.
Example response:
```json
{
"status": "error",
"data": {
"stack": "ServerError: server error message\n at module.exports ...",
"message": "server error message",
"name": "ServerError"
}
}
```

@@ -37,4 +37,7 @@ /* eslint-env node, mocha */

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -64,4 +67,7 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -98,4 +104,7 @@ Assert.equal(typeof data, 'object');

parseBody: false,
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -132,4 +141,7 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -165,4 +177,6 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "success");
Assert.ok(data);

@@ -189,6 +203,6 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -209,6 +223,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -229,6 +243,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -249,6 +263,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -270,6 +284,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -291,6 +305,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, 'error');
done();

@@ -301,2 +315,134 @@ });

describe("when an error is thrown", () => {
it("transforms vanilla Errors into an error payload", function (done) {
compiler(
{
nodejsCompiler,
script: `module.exports = function(client, scope, audience, context, cb) {
cb(new Error('vanilla error'));
};`,
},
function (error, func) {
Assert.ifError(error);
simulate(
func,
{
body: { client: { id: "client" }, audience: "audience" },
headers: {},
method: "POST",
},
function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.ok(data);
Assert.equal(status, "error");
Assert.equal(data.message, "vanilla error");
done();
}
);
}
);
});
it("transforms InvalidRequestErrors into an error payload", function (done) {
compiler(
{
nodejsCompiler,
script: `module.exports = function(client, scope, audience, context, cb) {
cb(new InvalidRequestError('bad request'));
};`,
},
function (error, func) {
Assert.ifError(error);
simulate(
func,
{
body: { client: { id: "client" }, audience: "audience" },
headers: {},
method: "POST",
},
function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.ok(data);
Assert.equal(status, "error");
Assert.equal(data.name, "InvalidRequestError");
Assert.equal(data.message, "bad request");
done();
}
);
}
);
});
it("transforms InvalidScopeErrors into an error payload", function (done) {
compiler(
{
nodejsCompiler,
script: `module.exports = function(client, scope, audience, context, cb) {
cb(new InvalidScopeError('bad scope'));
};`,
},
function (error, func) {
Assert.ifError(error);
simulate(
func,
{
body: { client: { id: "client" }, audience: "audience" },
headers: {},
method: "POST",
},
function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.ok(data);
Assert.equal(status, "error");
Assert.equal(data.name, "InvalidScopeError");
Assert.equal(data.message, "bad scope");
done();
}
);
}
);
});
it("transforms Server Error into an error payload", function (done) {
compiler(
{
nodejsCompiler,
script: `module.exports = function(client, scope, audience, context, cb) {
cb(new ServerError('server failure'));
};`,
},
function (error, func) {
Assert.ifError(error);
simulate(
func,
{
body: { client: { id: "client" }, audience: "audience" },
headers: {},
method: "POST",
},
function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.ok(data);
Assert.equal(status, "error");
Assert.equal(data.name, "ServerError");
Assert.equal(data.message, "server failure");
done();
}
);
}
);
});
});
});

@@ -37,4 +37,5 @@ /* eslint-env node, mocha */

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -62,4 +63,5 @@ Assert.equal(typeof data, 'object');

parseBody: false,
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -86,4 +88,5 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -110,6 +113,6 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, "error");
done();

@@ -131,6 +134,6 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status } = envelope;
Assert.equal(status, "error");
done();

@@ -137,0 +140,0 @@ });

@@ -37,4 +37,5 @@ /* eslint-env node, mocha */

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -64,4 +65,5 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -98,4 +100,5 @@ Assert.equal(typeof data, 'object');

parseBody: false,
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -132,4 +135,5 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -165,4 +169,5 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.ok(data);

@@ -189,7 +194,7 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body received by extensibility point is not an object');
done();

@@ -210,7 +215,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.user received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body.user received by extensibility point is not an object');
done();

@@ -231,7 +236,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.client received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body.client received by extensibility point is not an object');
done();

@@ -252,7 +257,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.scope received by extensibility point is neither empty nor an array');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body.scope received by extensibility point is neither empty nor an array');
done();

@@ -273,7 +278,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.audience received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body.audience received by extensibility point is not a string');
done();

@@ -295,7 +300,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Unauthorized extensibility point');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, "Unauthorized extensibility point");
done();

@@ -317,7 +322,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Unauthorized extensibility point');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, "Unauthorized extensibility point");
done();

@@ -324,0 +329,0 @@ });

@@ -38,7 +38,7 @@ /* eslint-env node, mocha */

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.recipient received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.recipient received by extensibility point is not a string');
done();

@@ -59,7 +59,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.text received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.text received by extensibility point is not a string');
done();

@@ -81,7 +82,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { data } = envelope;
Assert.equal(data.message, 'Body.context received by extensibility point is not an object');
done();

@@ -107,7 +108,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.message_type received by extensibility point is not `sms` or `voice`');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.message_type received by extensibility point is not `sms` or `voice`');
done();

@@ -133,5 +135,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.notEqual(error.message, 'Body.context.message_type received by extensibility point is not `sms` or `voice`');
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.notEqual(data.message, 'Body.context.message_type received by extensibility point is not `sms` or `voice`');
done();

@@ -158,5 +162,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.notEqual(error.message, 'Body.context.action received by extensibility point is not `enrollment` or `second-factor-authentication`');
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.notEqual(data.message, 'Body.context.action received by extensibility point is not `enrollment` or `second-factor-authentication`');
done();

@@ -183,7 +189,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.action received by extensibility point is not `enrollment` or `second-factor-authentication`');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.action received by extensibility point is not `enrollment` or `second-factor-authentication`');
done();

@@ -211,7 +218,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.language received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.language received by extensibility point is not a string');
done();

@@ -240,7 +248,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.code received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.code received by extensibility point is not a string');
done();

@@ -270,7 +279,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.ip received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.ip received by extensibility point is not a string');
done();

@@ -302,7 +312,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.user_agent received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.user_agent received by extensibility point is not a string');
done();

@@ -335,7 +346,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.client received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.client received by extensibility point is not an object');
done();

@@ -368,7 +380,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.client.client_id received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.client.client_id received by extensibility point is not a string');
done();

@@ -402,7 +415,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.client.name received by extensibility point is not a string');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.client.name received by extensibility point is not a string');
done();

@@ -436,7 +450,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.client.client_metadata received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.client.client_metadata received by extensibility point is not an object');
done();

@@ -473,7 +488,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.user received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "error");
Assert.equal(data.message, 'Body.context.user received by extensibility point is not an object');
done();

@@ -508,4 +524,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.equal(error, null);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "success");
Assert.ok(data);
done();

@@ -542,4 +561,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.equal(error, null);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "success");
Assert.ok(data);
done();

@@ -576,4 +598,7 @@ });

method: 'POST',
}, function (error, data) {
Assert.equal(error, null);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, "success");
Assert.ok(data);
done();

@@ -580,0 +605,0 @@ });

@@ -21,10 +21,4 @@ 'use strict';

error.title = payload.title;
error.statusCode = payload.status;
error.detail = payload.detail;
for (let key in payload) {
if (!error[key]) {
error[key] = payload[key];
}
error[key] = payload[key];
}

@@ -31,0 +25,0 @@ return cb(error);

@@ -37,4 +37,7 @@ /* eslint-env node, mocha */

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -59,4 +62,7 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
}, function (error, envelope) {
Assert.ifError(error);
Assert.ok(envelope);
const { status, data } = envelope;
Assert.equal(status, 'success');
Assert.ok(data);

@@ -84,7 +90,8 @@ Assert.equal(typeof data, 'object');

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Body received by extensibility point is not an object');
done();

@@ -105,7 +112,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.user received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Body.user received by extensibility point is not an object');
done();

@@ -126,7 +134,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Body.context received by extensibility point is not an object');
done();

@@ -147,7 +156,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Body.context.connection received by extensibility point is not an object');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Body.context.connection received by extensibility point is not an object');
done();

@@ -169,7 +179,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Unauthorized extensibility point');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Unauthorized extensibility point');
done();

@@ -191,7 +202,8 @@ });

method: 'POST',
}, function (error, data) {
Assert.ok(error);
Assert.equal(error.statusCode, 500);
Assert.equal(error.message, 'Unauthorized extensibility point');
Assert.equal(data, undefined);
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.message, 'Unauthorized extensibility point');
done();

@@ -201,2 +213,25 @@ });

});
it('provides a custom error object', function (done) {
compiler({
nodejsCompiler,
script: 'module.exports = function(user, context, cb) { cb(new PreUserRegistrationError("message", "friendly message")); };'
}, function (error, func) {
Assert.ifError(error);
simulate(func, {
body: { user: {}, context: { connection: {} } },
headers: {},
method: 'POST',
}, function (error, envelope) {
Assert.ifError(error);
const { status, data } = envelope;
Assert.equal(status, 'error');
Assert.equal(data.name, 'PreUserRegistrationError');
Assert.equal(data.message, 'message');
Assert.equal(data.friendlyMessage, 'friendly message');
done();
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc