Skip to content

Commit 2ecde8e

Browse files
committed
Merge branch 'main' into feature/removing-sonar-issues-pt2
# Conflicts: # lib/mcapi/crypto/jwe-crypto.js # lib/mcapi/encryption/field-level-encryption.js # lib/mcapi/encryption/jwe-encryption.js # lib/mcapi/utils/utils.js
2 parents a1ad2f3 + 2514a92 commit 2ecde8e

File tree

5 files changed

+46
-91
lines changed

5 files changed

+46
-91
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mastercard-client-encryption",
3-
"version": "1.4.0",
3+
"version": "1.6.0",
44
"description": "Library for Mastercard API compliant payload encryption/decryption.",
55
"main": "index.js",
66
"engines": {

test/field-level-encryption.test.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,6 @@ describe("Field Level Encryption", () => {
2222
});
2323
});
2424

25-
describe("#hasConfig", () => {
26-
const hasConfig = FieldLevelEncryption.__get__("hasConfig");
27-
28-
it("when valid config, not found endpoint", () => {
29-
const ret = hasConfig(testConfig, "/endpoint");
30-
assert.ok(ret === null);
31-
});
32-
33-
it("when valid config, found endpoint", () => {
34-
const ret = hasConfig(testConfig, "/resource");
35-
assert.ok(ret);
36-
});
37-
38-
it("when config is null", () => {
39-
const ret = hasConfig(null, "/resource");
40-
assert.ok(ret == null);
41-
});
42-
43-
it("when path has wildcard", () => {
44-
const ret = hasConfig(
45-
testConfig,
46-
"https://api.example.com/mappings/0123456"
47-
);
48-
assert.ok(ret.toEncrypt[0].element === "elem2.encryptedData");
49-
assert.ok(ret);
50-
});
51-
});
52-
53-
describe("#elemFromPath", () => {
54-
const elemFromPath = FieldLevelEncryption.__get__("elemFromPath");
55-
56-
it("valid path", () => {
57-
const res = elemFromPath("elem1.elem2", { elem1: { elem2: "test" } });
58-
assert.ok(res.node === "test");
59-
assert.ok(
60-
JSON.stringify(res.parent) === JSON.stringify({ elem2: "test" })
61-
);
62-
});
63-
64-
it("not valid path", () => {
65-
const res = elemFromPath("elem1.elem2", { elem2: "test" });
66-
assert.ok(!res);
67-
});
68-
});
6925

7026
describe("#encrypt", () => {
7127
const fle = new FieldLevelEncryption(testConfig);

test/jwe-encryption.test.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,6 @@ describe("JWE Encryption", () => {
1919
});
2020
});
2121

22-
describe("#hasConfig", () => {
23-
const hasConfig = JweEncryption.__get__("hasConfig");
24-
25-
it("when valid config, not found endpoint", () => {
26-
const ret = hasConfig(testConfig, "/endpoint");
27-
assert.ok(ret === null);
28-
});
29-
30-
it("when valid config, found endpoint", () => {
31-
const ret = hasConfig(testConfig, "/resource");
32-
assert.ok(ret);
33-
});
34-
35-
it("when config is null", () => {
36-
const ret = hasConfig(null, "/resource");
37-
assert.ok(ret == null);
38-
});
39-
40-
it("when path has wildcard", () => {
41-
const ret = hasConfig(
42-
testConfig,
43-
"https://api.example.com/mappings/0123456"
44-
);
45-
assert.ok(ret.toEncrypt[0].element === "elem2.encryptedData");
46-
assert.ok(ret);
47-
});
48-
});
49-
50-
describe("#elemFromPath", () => {
51-
const elemFromPath = JweEncryption.__get__("elemFromPath");
52-
53-
it("valid path", () => {
54-
const res = elemFromPath("elem1.elem2", { elem1: { elem2: "test" } });
55-
assert.ok(res.node === "test");
56-
assert.ok(
57-
JSON.stringify(res.parent) === JSON.stringify({ elem2: "test" })
58-
);
59-
});
60-
61-
it("not valid path", () => {
62-
const res = elemFromPath("elem1.elem2", { elem2: "test" });
63-
assert.ok(!res);
64-
});
65-
});
66-
6722
describe("#encrypt", () => {
6823
it("encrypt body payload", () => {
6924
const encryption = new JweEncryption(testConfig);

test/utils.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const assert = require("assert");
22
const utils = require("../lib/mcapi/utils/utils");
3+
const testConfig = require("./mock/config");
34

45
describe("Utils", () => {
56
describe("#isSet", () => {
@@ -411,4 +412,47 @@ describe("Utils", () => {
411412
}, /Public certificate content is not valid/);
412413
});
413414
});
415+
416+
describe("#utils.hasConfig", () => {
417+
418+
it("when valid config, not found endpoint", () => {
419+
const ret = utils.hasConfig(testConfig, "/endpoint");
420+
assert.ok(ret === null);
421+
});
422+
423+
it("when valid config, found endpoint", () => {
424+
const ret = utils.hasConfig(testConfig, "/resource");
425+
assert.ok(ret);
426+
});
427+
428+
it("when config is null", () => {
429+
const ret = utils.hasConfig(null, "/resource");
430+
assert.ok(ret == null);
431+
});
432+
433+
it("when path has wildcard", () => {
434+
const ret = utils.hasConfig(
435+
testConfig,
436+
"https://api.example.com/mappings/0123456"
437+
);
438+
assert.ok(ret.toEncrypt[0].element === "elem2.encryptedData");
439+
assert.ok(ret);
440+
});
441+
});
442+
443+
describe("#utils.elemFromPath", () => {
444+
it("valid path", () => {
445+
const res = utils.elemFromPath("elem1.elem2", { elem1: { elem2: "test" } });
446+
assert.ok(res.node === "test");
447+
assert.ok(
448+
JSON.stringify(res.parent) === JSON.stringify({ elem2: "test" })
449+
);
450+
});
451+
452+
it("not valid path", () => {
453+
const res = utils.elemFromPath("elem1.elem2", { elem2: "test" });
454+
assert.ok(!res);
455+
});
456+
});
457+
414458
});

0 commit comments

Comments
 (0)