Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function getPassedContext(event, body) {

// if the key is just `ctx_` or `ctx-` and there is a value, parse it as JSON
if (!k[1] && value) {
ctx[key] = JSON.parse(value);
Object.assign(ctx, JSON.parse(value));
} else {
// Check for any type conversions on the query parameter
let type = event.queryStringParameters["t_" + key];
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "leo-auth",
"version": "4.0.4",
"version": "4.0.5",
"description": "Auth sdk",
"homepage": "https://leoplatform.io",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test-all": "npm run compile && npm run coverage-all",
"tests": "mocha --recursive -w",
"test": "mocha --recursive -g",
"coverage-all": "cross-env NODE_ENV=utest node ./node_modules/nyc/bin/nyc.js --all node ./node_modules/mocha/bin/mocha --timeout 5000 \"./{,!(node_modules)/**/}*.utest.js\"",
Expand Down
30 changes: 28 additions & 2 deletions test/index.utest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,41 @@ describe('index', function () {
let sdk = require("..");
let user = await sdk.getUser({
queryStringParameters: {
ctx_: "{\"test\":\"value\"}"
ctx_: JSON.stringify({
string: "value",
number: 42,
float: 3.14159,
boolean_true: true,
boolean_false: false,
null_value: null,
object: {
nested_string: "nested",
nested_number: -99,
nested_array: [1, 2, { deep: "object" }],
nested_object: {
another_level: {
foo: "bar"
}
}
},
array: [
"item1",
123,
false,
{ arr_nested: [1, 2, 3], arr_obj: { a: 1, b: 2 }},
[["deep", "array"], [true, null]]
],
empty_object: {},
undefined_value: undefined // undefined will be omitted by JSON.stringify
})
},
requestContext: {
identity: {
caller: "identity-1234"
}
}
});
assert.deepEqual(user.context, { key: "identity-1234", ctx_: { test: "value" } });
assert.deepEqual(user.context, { key: "identity-1234", string: "value", number: 42, float: 3.14159, boolean_true: true, boolean_false: false, null_value: null, object: { nested_string: "nested", nested_number: -99, nested_array: [1, 2, { deep: "object" }], nested_object: { another_level: { foo: "bar" } } }, array: [ "item1", 123, false, { arr_nested: [1, 2, 3], arr_obj: { a: 1, b: 2 } }, [["deep", "array"], [true, null]] ], empty_object: {}});
});
});

Expand Down