@adobe/acc-js-sdk 1.0.5 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.vscode/launch.json +0 -1
- package/CHANGELOG.md +40 -0
- package/README.md +199 -63
- package/compile.js +3 -0
- package/package-lock.json +2175 -3383
- package/package.json +6 -7
- package/samples/002 - basics - schemas.js +3 -3
- package/samples/020 - encryption.js +5 -5
- package/src/application.js +427 -77
- package/src/cache.js +275 -0
- package/src/campaign.js +4 -0
- package/src/client.js +108 -30
- package/src/domUtil.js +6 -3
- package/src/entityAccessor.js +5 -5
- package/src/index.js +58 -2
- package/src/methodCache.js +21 -2
- package/src/optionCache.js +5 -1
- package/src/soap.js +46 -19
- package/src/testUtil.js +47 -0
- package/src/util.js +0 -229
- package/src/xtkCaster.js +80 -6
- package/src/xtkEntityCache.js +19 -3
- package/test/application.test.js +684 -616
- package/test/caches.test.js +148 -2
- package/test/client.test.js +341 -14
- package/test/crypto.test.js +16 -12
- package/test/domUtil.test.js +150 -2
- package/test/escape.test.js +79 -47
- package/test/index.test.js +69 -1
- package/test/mock.js +59 -9
- package/test/soap.test.js +0 -6
- package/test/testUtil.test.js +64 -0
- package/test/util.test.js +2 -1
- package/test/xtkCaster.test.js +219 -1
package/test/crypto.test.js
CHANGED
|
@@ -19,61 +19,65 @@ governing permissions and limitations under the License.
|
|
|
19
19
|
|
|
20
20
|
const assert = require('assert');
|
|
21
21
|
const crypto = require('../src/crypto.js');
|
|
22
|
+
const { Mock } = require('./mock.js');
|
|
22
23
|
const Cipher = crypto.Cipher;
|
|
23
24
|
|
|
24
25
|
describe('crypto', function() {
|
|
25
26
|
|
|
26
27
|
it("Should decrypt password", function() {
|
|
27
|
-
const cipher = new Cipher(
|
|
28
|
-
|
|
28
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
29
|
+
const encrypted = cipher.encryptPassword("mid");
|
|
30
|
+
var decrypted = cipher.decryptPassword(encrypted);
|
|
29
31
|
assert.equal(decrypted, "mid");
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
it("Should fail on invalid encrypted string", function() {
|
|
33
|
-
const cipher = new Cipher(
|
|
35
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
34
36
|
assert.throws(function() {
|
|
35
37
|
cipher.decryptPassword("Hello");
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
40
|
|
|
39
41
|
it("Should decrypt password twice", function() {
|
|
40
|
-
const cipher = new Cipher(
|
|
41
|
-
|
|
42
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
43
|
+
const encrypted = cipher.encryptPassword("mid");
|
|
44
|
+
var decrypted = cipher.decryptPassword(encrypted);
|
|
42
45
|
assert.equal(decrypted, "mid");
|
|
43
|
-
decrypted = cipher.decryptPassword(
|
|
46
|
+
decrypted = cipher.decryptPassword(encrypted);
|
|
44
47
|
assert.equal(decrypted, "mid");
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
it("Should decrypt password after failure", function() {
|
|
48
|
-
const cipher = new Cipher(
|
|
51
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
49
52
|
assert.throws(function() {
|
|
50
53
|
cipher.decryptPassword("@Hello");
|
|
51
54
|
});
|
|
52
55
|
// make sure state is valid after failure
|
|
53
|
-
|
|
56
|
+
const encrypted = cipher.encryptPassword("mid");
|
|
57
|
+
var decrypted = cipher.decryptPassword(encrypted);
|
|
54
58
|
assert.equal(decrypted, "mid");
|
|
55
59
|
});
|
|
56
60
|
|
|
57
61
|
it("Should handle plain text passwords", function() {
|
|
58
|
-
const cipher = new Cipher(
|
|
62
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
59
63
|
var decrypted = cipher.decryptPassword("__PLAINTEXT__pass");
|
|
60
64
|
assert.equal(decrypted, "pass");
|
|
61
65
|
});
|
|
62
66
|
|
|
63
67
|
it("Should fail if no marker", function() {
|
|
64
|
-
const cipher = new Cipher(
|
|
68
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
65
69
|
expect(() => { cipher.decryptPassword("57QS5VHMb9BCsojLVrKI/Q=="); }).toThrow("SDK-000011");
|
|
66
70
|
});
|
|
67
71
|
|
|
68
72
|
it("Should support empty passwords", function() {
|
|
69
|
-
const cipher = new Cipher(
|
|
73
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
70
74
|
assert.equal(cipher.decryptPassword(""), "");
|
|
71
75
|
assert.equal(cipher.decryptPassword(null), "");
|
|
72
76
|
assert.equal(cipher.decryptPassword(undefined), "");
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
it("Encrypt - decrypt", function() {
|
|
76
|
-
const cipher = new Cipher(
|
|
80
|
+
const cipher = new Cipher(Mock.makeKey());
|
|
77
81
|
expect(cipher.decryptPassword(cipher.encryptPassword(""))).toBe("");
|
|
78
82
|
expect(cipher.decryptPassword(cipher.encryptPassword("1"))).toBe("1");
|
|
79
83
|
expect(cipher.decryptPassword(cipher.encryptPassword("Hello"))).toBe("Hello");
|
package/test/domUtil.test.js
CHANGED
|
@@ -18,8 +18,7 @@ governing permissions and limitations under the License.
|
|
|
18
18
|
*********************************************************************************/
|
|
19
19
|
|
|
20
20
|
const assert = require('assert');
|
|
21
|
-
const { DomUtil } = require('../src/domUtil.js');
|
|
22
|
-
const { Util } = require('../src/util.js');
|
|
21
|
+
const { DomUtil, XPath, XPathElement } = require('../src/domUtil.js');
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
describe('DomUtil', function() {
|
|
@@ -546,4 +545,153 @@ describe('DomUtil', function() {
|
|
|
546
545
|
});
|
|
547
546
|
});
|
|
548
547
|
|
|
548
|
+
describe("XPath", () => {
|
|
549
|
+
|
|
550
|
+
it("Should create XPath", () => {
|
|
551
|
+
expect(new XPath("").asString()).toBe("");
|
|
552
|
+
expect(new XPath(" ").asString()).toBe("");
|
|
553
|
+
expect(new XPath(null).asString()).toBe("");
|
|
554
|
+
expect(new XPath(undefined).asString()).toBe("");
|
|
555
|
+
expect(new XPath("@name").asString()).toBe("@name");
|
|
556
|
+
expect(new XPath("country/@name").asString()).toBe("country/@name");
|
|
557
|
+
expect(new XPath("..").asString()).toBe("..");
|
|
558
|
+
expect(new XPath(".").asString()).toBe(".");
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
it("Should create expanded XPath", () => {
|
|
562
|
+
expect(new XPath("[@name]").asString()).toBe("@name");
|
|
563
|
+
expect(new XPath("[country/@name]").asString()).toBe("country/@name");
|
|
564
|
+
})
|
|
565
|
+
|
|
566
|
+
it("toString", () => {
|
|
567
|
+
expect(new XPath("").toString()).toBe("");
|
|
568
|
+
expect(new XPath(" ").toString()).toBe("");
|
|
569
|
+
expect(new XPath(null).toString()).toBe("");
|
|
570
|
+
expect(new XPath(undefined).toString()).toBe("");
|
|
571
|
+
expect(new XPath("@name").toString()).toBe("@name");
|
|
572
|
+
expect(new XPath("country/@name").toString()).toBe("country/@name");
|
|
573
|
+
expect(new XPath("..").toString()).toBe("..");
|
|
574
|
+
expect(new XPath(".").toString()).toBe(".");
|
|
575
|
+
})
|
|
576
|
+
|
|
577
|
+
it("Should test empty XPath", () => {
|
|
578
|
+
expect(new XPath("").isEmpty()).toBe(true);
|
|
579
|
+
expect(new XPath(" ").isEmpty()).toBe(true);
|
|
580
|
+
expect(new XPath(null).isEmpty()).toBe(true);
|
|
581
|
+
expect(new XPath(undefined).isEmpty()).toBe(true);
|
|
582
|
+
expect(new XPath("@name").isEmpty()).toBe(false);
|
|
583
|
+
expect(new XPath("country/@name").isEmpty()).toBe(false);
|
|
584
|
+
expect(new XPath("..").isEmpty()).toBe(false);
|
|
585
|
+
expect(new XPath(".").isEmpty()).toBe(false);
|
|
586
|
+
})
|
|
587
|
+
|
|
588
|
+
it("Should test absolute XPath", () => {
|
|
589
|
+
expect(new XPath("").isAbsolute()).toBe(false);
|
|
590
|
+
expect(new XPath(" ").isAbsolute()).toBe(false);
|
|
591
|
+
expect(new XPath(null).isAbsolute()).toBe(false);
|
|
592
|
+
expect(new XPath(undefined).isAbsolute()).toBe(false);
|
|
593
|
+
expect(new XPath("@name").isAbsolute()).toBe(false);
|
|
594
|
+
expect(new XPath("country/@name").isAbsolute()).toBe(false);
|
|
595
|
+
expect(new XPath("..").isAbsolute()).toBe(false);
|
|
596
|
+
expect(new XPath(".").isAbsolute()).toBe(false);
|
|
597
|
+
expect(new XPath("/").isAbsolute()).toBe(true);
|
|
598
|
+
expect(new XPath("/country/@name").isAbsolute()).toBe(true);
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
it("Should test self XPath", () => {
|
|
602
|
+
expect(new XPath("").isSelf()).toBe(false);
|
|
603
|
+
expect(new XPath(" ").isSelf()).toBe(false);
|
|
604
|
+
expect(new XPath(null).isSelf()).toBe(false);
|
|
605
|
+
expect(new XPath(undefined).isSelf()).toBe(false);
|
|
606
|
+
expect(new XPath("@name").isSelf()).toBe(false);
|
|
607
|
+
expect(new XPath("country/@name").isSelf()).toBe(false);
|
|
608
|
+
expect(new XPath("..").isSelf()).toBe(false);
|
|
609
|
+
expect(new XPath(".").isSelf()).toBe(true);
|
|
610
|
+
expect(new XPath("/").isSelf()).toBe(false);
|
|
611
|
+
expect(new XPath("/country/@name").isSelf()).toBe(false);
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
it("Should test root XPath", () => {
|
|
615
|
+
expect(new XPath("").isRootPath()).toBe(false);
|
|
616
|
+
expect(new XPath(" ").isRootPath()).toBe(false);
|
|
617
|
+
expect(new XPath(null).isRootPath()).toBe(false);
|
|
618
|
+
expect(new XPath(undefined).isRootPath()).toBe(false);
|
|
619
|
+
expect(new XPath("@name").isRootPath()).toBe(false);
|
|
620
|
+
expect(new XPath("country/@name").isRootPath()).toBe(false);
|
|
621
|
+
expect(new XPath("..").isRootPath()).toBe(false);
|
|
622
|
+
expect(new XPath(".").isRootPath()).toBe(false);
|
|
623
|
+
expect(new XPath("/").isRootPath()).toBe(true);
|
|
624
|
+
expect(new XPath("/country/@name").isRootPath()).toBe(false);
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
it("Should return XPath elements", () => {
|
|
628
|
+
|
|
629
|
+
function elements(xpath) {
|
|
630
|
+
const result = [];
|
|
631
|
+
const list = xpath.getElements();
|
|
632
|
+
for (const e of list) {
|
|
633
|
+
result.push(e._pathElement);
|
|
634
|
+
}
|
|
635
|
+
return result;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
expect(elements(new XPath(""))).toEqual([ ]);
|
|
639
|
+
expect(elements(new XPath(" "))).toEqual([ ]);
|
|
640
|
+
expect(elements(new XPath(null))).toEqual([ ]);
|
|
641
|
+
expect(elements(new XPath(undefined))).toEqual([ ]);
|
|
642
|
+
expect(elements(new XPath("@name"))).toEqual([ "@name" ]);
|
|
643
|
+
expect(elements(new XPath("country/@name"))).toEqual([ "country", "@name" ]);
|
|
644
|
+
expect(elements(new XPath(".."))).toEqual([ ".." ]);
|
|
645
|
+
expect(elements(new XPath("."))).toEqual([ "." ]);
|
|
646
|
+
expect(elements(new XPath("/"))).toEqual([ ]);
|
|
647
|
+
expect(elements(new XPath("/country/@name"))).toEqual([ "country", "@name" ]);
|
|
648
|
+
})
|
|
649
|
+
|
|
650
|
+
it("Should get relative path", () => {
|
|
651
|
+
expect(new XPath("").getRelativePath().asString()).toBe("");
|
|
652
|
+
expect(new XPath(" ").getRelativePath().asString()).toBe("");
|
|
653
|
+
expect(new XPath(null).getRelativePath().asString()).toBe("");
|
|
654
|
+
expect(new XPath(undefined).getRelativePath().asString()).toBe("");
|
|
655
|
+
expect(new XPath("@name").getRelativePath().asString()).toBe("@name");
|
|
656
|
+
expect(new XPath("country/@name").getRelativePath().asString()).toBe("country/@name");
|
|
657
|
+
expect(new XPath("..").getRelativePath().asString()).toBe("..");
|
|
658
|
+
expect(new XPath(".").getRelativePath().asString()).toBe(".");
|
|
659
|
+
expect(new XPath("/").getRelativePath().asString()).toBe("");
|
|
660
|
+
expect(new XPath("/country/@name").getRelativePath().asString()).toBe("country/@name");
|
|
661
|
+
})
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
describe("XPathElement", () => {
|
|
665
|
+
it("Should create XPathElement", () => {
|
|
666
|
+
expect(() => { new XPathElement(""); }).toThrow("Invalid empty xpath element");
|
|
667
|
+
expect(() => { new XPathElement(" "); }).toThrow("Invalid empty xpath element");
|
|
668
|
+
expect(() => { new XPathElement(null); }).toThrow("Invalid empty xpath element");
|
|
669
|
+
expect(() => { new XPathElement(undefined); }).toThrow("Invalid empty xpath element");
|
|
670
|
+
expect(new XPathElement("@name").asString()).toBe("@name");
|
|
671
|
+
expect(new XPathElement("country").asString()).toBe("country");
|
|
672
|
+
expect(new XPathElement("..").asString()).toBe("..");
|
|
673
|
+
expect(new XPathElement(".").asString()).toBe(".");
|
|
674
|
+
})
|
|
675
|
+
|
|
676
|
+
it("toString", () => {
|
|
677
|
+
expect(new XPathElement("@name").toString()).toBe("@name");
|
|
678
|
+
expect(new XPathElement("country").toString()).toBe("country");
|
|
679
|
+
expect(new XPathElement("..").toString()).toBe("..");
|
|
680
|
+
expect(new XPathElement(".").toString()).toBe(".");
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
it("Should test if path element is self", () => {
|
|
684
|
+
expect(new XPathElement("@name").isSelf()).toBe(false);
|
|
685
|
+
expect(new XPathElement("country").isSelf()).toBe(false);
|
|
686
|
+
expect(new XPathElement("..").isSelf()).toBe(false);
|
|
687
|
+
expect(new XPathElement(".").isSelf()).toBe(true);
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
it("Should test if path element is the parent path (..)", () => {
|
|
691
|
+
expect(new XPathElement("@name").isParent()).toBe(false);
|
|
692
|
+
expect(new XPathElement("country").isParent()).toBe(false);
|
|
693
|
+
expect(new XPathElement("..").isParent()).toBe(true);
|
|
694
|
+
expect(new XPathElement(".").isParent()).toBe(false);
|
|
695
|
+
})
|
|
696
|
+
})
|
|
549
697
|
});
|
package/test/escape.test.js
CHANGED
|
@@ -18,65 +18,97 @@ governing permissions and limitations under the License.
|
|
|
18
18
|
*********************************************************************************/
|
|
19
19
|
const sdk = require('../src/index.js');
|
|
20
20
|
|
|
21
|
-
describe('
|
|
22
|
-
|
|
23
|
-
describe('Escaping strings', function() {
|
|
24
|
-
it("Should escape null strings", () => {
|
|
25
|
-
expect(sdk.escapeXtk(null)).toBe("''");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("Should escape undefined strings", () => {
|
|
29
|
-
expect(sdk.escapeXtk(undefined)).toBe("''");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("Should escape empty strings", () => {
|
|
33
|
-
expect(sdk.escapeXtk("")).toBe("''");
|
|
34
|
-
});
|
|
21
|
+
describe('escaping', function() {
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
describe('escapeXtk', function() {
|
|
24
|
+
|
|
25
|
+
describe('Escaping strings', function() {
|
|
26
|
+
it("Should escape null strings", () => {
|
|
27
|
+
expect(sdk.escapeXtk(null)).toBe("''");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("Should escape undefined strings", () => {
|
|
31
|
+
expect(sdk.escapeXtk(undefined)).toBe("''");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("Should escape empty strings", () => {
|
|
35
|
+
expect(sdk.escapeXtk("")).toBe("''");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("Should escape empty simple strings", () => {
|
|
39
|
+
expect(sdk.escapeXtk("Hello")).toBe("'Hello'");
|
|
40
|
+
expect(sdk.escapeXtk("Hello world")).toBe("'Hello world'");
|
|
41
|
+
expect(sdk.escapeXtk(" ")).toBe("' '");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("Should escape simple quotes", () => {
|
|
45
|
+
expect(sdk.escapeXtk("Hello 'world'")).toBe("'Hello \\'world\\''");
|
|
46
|
+
});
|
|
47
|
+
})
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
expect(sdk.escapeXtk("Hello 'world'")).toBe("'Hello \\'world\\''");
|
|
44
|
-
});
|
|
45
|
-
})
|
|
49
|
+
describe('Tagged template litteral', function() {
|
|
46
50
|
|
|
47
|
-
|
|
51
|
+
it("Should escape in template litteral", () => {
|
|
52
|
+
expect(sdk.escapeXtk`Hello world`).toBe("Hello world");
|
|
53
|
+
expect(sdk.escapeXtk`Hello 'world'`).toBe("Hello 'world'"); // only variables are escaped
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const empty = "";
|
|
56
|
+
expect(sdk.escapeXtk``).toBe("");
|
|
57
|
+
expect(sdk.escapeXtk`${empty}`).toBe("''");
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(sdk.escapeXtk`${empty}`).toBe("''");
|
|
59
|
+
const name = "Joe's";
|
|
60
|
+
expect(sdk.escapeXtk`Hello ${name}`).toBe("Hello 'Joe\\'s'"); // variable value is quoted and escaped
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
// A more relevant test
|
|
63
|
+
const userName = 'Alex';
|
|
64
|
+
expect({ expr: sdk.escapeXtk`@name = ${userName}` }).toEqual({ expr: "@name = 'Alex'" });
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
// Should support multiple variables
|
|
67
|
+
expect({ expr: sdk.escapeXtk`@name = ${userName} or @name = ${name}` }).toEqual({ expr: "@name = 'Alex' or @name = 'Joe\\'s'" });
|
|
68
|
+
})
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
it("Should support constants", () => {
|
|
71
|
+
expect(sdk.escapeXtk([],[])).toBe("''");
|
|
72
|
+
})
|
|
66
73
|
})
|
|
67
74
|
|
|
68
|
-
it("
|
|
69
|
-
expect(sdk.escapeXtk(
|
|
75
|
+
it("examples in jsdoc", () => {
|
|
76
|
+
expect(sdk.escapeXtk("Rock 'n' Roll")).toBe("'Rock \\'n\\' Roll'");
|
|
77
|
+
expect(sdk.escapeXtk`@name=${"Rock 'n' Roll"}`).toBe("@name='Rock \\'n\\' Roll'");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('QueryDef & template litteral', () => {
|
|
81
|
+
|
|
70
82
|
})
|
|
71
|
-
})
|
|
72
83
|
|
|
73
|
-
it("examples in jsdoc", () => {
|
|
74
|
-
expect(sdk.escapeXtk("Rock 'n' Roll")).toBe("'Rock \\'n\\' Roll'");
|
|
75
|
-
expect(sdk.escapeXtk`@name=${"Rock 'n' Roll"}`).toBe("@name='Rock \\'n\\' Roll'");
|
|
76
84
|
});
|
|
77
85
|
|
|
78
|
-
describe('
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
describe('escapeForLike', function() {
|
|
87
|
+
it('Should support null and undefined', () => {
|
|
88
|
+
expect(sdk.escapeForLike(null)).toBe('');
|
|
89
|
+
expect(sdk.escapeForLike(undefined)).toBe('');
|
|
90
|
+
expect(sdk.escapeForLike('')).toBe('');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('Should escape simple strings', () => {
|
|
94
|
+
expect(sdk.escapeForLike('Hello')).toBe('Hello');
|
|
95
|
+
expect(sdk.escapeForLike('Hello world')).toBe('Hello world');
|
|
96
|
+
expect(sdk.escapeForLike('1234')).toBe('1234');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('Should escape special chars', () => {
|
|
100
|
+
expect(sdk.escapeForLike('99.9%')).toBe('99.9\\%');
|
|
101
|
+
expect(sdk.escapeForLike("John 'Rusty' Toe")).toBe("John \\'Rusty\\' Toe");
|
|
102
|
+
expect(sdk.escapeForLike("Hello_Cruel_World")).toBe("Hello\\_Cruel\\_World");
|
|
103
|
+
expect(sdk.escapeForLike("John \\Rusty\\ Toe")).toBe("John \\\\Rusty\\\\ Toe");
|
|
104
|
+
// $ is not a special char
|
|
105
|
+
expect(sdk.escapeForLike('$99.9')).toBe('$99.9');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('Should escape Xtk Variables', () => {
|
|
109
|
+
expect(sdk.escapeForLike('$99.9', false)).toBe('$99.9');
|
|
110
|
+
expect(sdk.escapeForLike('1+$id', true)).toBe("1+' + Char('36') + 'id");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
81
113
|
|
|
82
|
-
});
|
|
114
|
+
});
|
package/test/index.test.js
CHANGED
|
@@ -73,6 +73,74 @@ describe('ACC SDK', function() {
|
|
|
73
73
|
sdk._transport(old);
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
-
})
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("expandXPath", () => {
|
|
79
|
+
it("Should support empty paths", () => {
|
|
80
|
+
expect(sdk.expandXPath(null)).toBe(null);
|
|
81
|
+
expect(sdk.expandXPath(undefined)).toBe(undefined);
|
|
82
|
+
expect(sdk.expandXPath("")).toBe("");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("Should preserve already expanded xpath", () => {
|
|
86
|
+
expect(sdk.expandXPath("[@email]")).toBe("[@email]");
|
|
87
|
+
expect(sdk.expandXPath("[@recipient-id]")).toBe("[@recipient-id]");
|
|
88
|
+
expect(sdk.expandXPath("[recipient/@id]")).toBe("[recipient/@id]");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("Should not add brackets if not necessary", () => {
|
|
92
|
+
expect(sdk.expandXPath("@email")).toBe("@email");
|
|
93
|
+
expect(sdk.expandXPath("@email_address")).toBe("@email_address");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("Should add brackets if necessary", () => {
|
|
97
|
+
expect(sdk.expandXPath("@recipient-id")).toBe("[@recipient-id]");
|
|
98
|
+
expect(sdk.expandXPath("email/@address")).toBe("[email/@address]");
|
|
99
|
+
expect(sdk.expandXPath("nms:recipient")).toBe("[nms:recipient]");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("unexpandXPath", () => {
|
|
104
|
+
it("Should support empty paths", () => {
|
|
105
|
+
expect(sdk.unexpandXPath(null)).toBe(null);
|
|
106
|
+
expect(sdk.unexpandXPath(undefined)).toBe(undefined);
|
|
107
|
+
expect(sdk.unexpandXPath("")).toBe("");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("Should remove brackets", () => {
|
|
111
|
+
expect(sdk.unexpandXPath("[@email]")).toBe("@email");
|
|
112
|
+
expect(sdk.unexpandXPath("[@recipient-id]")).toBe("@recipient-id");
|
|
113
|
+
expect(sdk.unexpandXPath("[recipient/@id]")).toBe("recipient/@id");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("Should preseve already unexpanded pathx", () => {
|
|
117
|
+
expect(sdk.unexpandXPath("@email")).toBe("@email");
|
|
118
|
+
expect(sdk.unexpandXPath("@email_address")).toBe("@email_address");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("Should support array-paths", () => {
|
|
122
|
+
expect(sdk.unexpandXPath("coll[0]")).toBe("coll[0]");
|
|
123
|
+
expect(sdk.unexpandXPath("[coll[0]]")).toBe("coll[0]");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("xtkConstText", () => {
|
|
128
|
+
it("Should handle various types", () => {
|
|
129
|
+
// Strings are quoted and escaped
|
|
130
|
+
expect(sdk.xtkConstText("Hello", "string")).toBe("'Hello'");
|
|
131
|
+
expect(sdk.xtkConstText("", "string")).toBe("''");
|
|
132
|
+
expect(sdk.xtkConstText(123, "string")).toBe("'123'");
|
|
133
|
+
expect(sdk.xtkConstText("Hello'World", "memo")).toBe("'Hello\\'World'");
|
|
134
|
+
// Numbers are unchanged
|
|
135
|
+
expect(sdk.xtkConstText(123, "long")).toBe("123");
|
|
136
|
+
expect(sdk.xtkConstText(-42.3, "double")).toBe("-42.3");
|
|
137
|
+
expect(sdk.xtkConstText("", "long")).toBe("0");
|
|
138
|
+
expect(sdk.xtkConstText(undefined, "short")).toBe("0");
|
|
139
|
+
// Timestamps are surrounded by ##
|
|
140
|
+
expect(sdk.xtkConstText("2022-02-15T09:49:04.000Z", "datetime")).toBe("#2022-02-15T09:49:04.000Z#");
|
|
141
|
+
expect(sdk.xtkConstText("", "datetime")).toBe("##");
|
|
142
|
+
expect(sdk.xtkConstText(undefined, "date")).toBe("##");
|
|
143
|
+
});
|
|
144
|
+
});
|
|
77
145
|
|
|
78
146
|
});
|
package/test/mock.js
CHANGED
|
@@ -17,6 +17,17 @@ governing permissions and limitations under the License.
|
|
|
17
17
|
*
|
|
18
18
|
*********************************************************************************/
|
|
19
19
|
const sdk = require('../src/index.js');
|
|
20
|
+
const crypto = require("crypto");
|
|
21
|
+
|
|
22
|
+
const makeKey = () => {
|
|
23
|
+
const a = [];
|
|
24
|
+
for (let i=0; i<32; i++) {
|
|
25
|
+
a.push(Math.floor(crypto.randomInt(0, 256)));
|
|
26
|
+
}
|
|
27
|
+
const buffer = Buffer.from(a);
|
|
28
|
+
const s = buffer.toString('base64');
|
|
29
|
+
return s;
|
|
30
|
+
}
|
|
20
31
|
|
|
21
32
|
async function makeAnonymousClient(options) {
|
|
22
33
|
const connectionParameters = sdk.ConnectionParameters.ofAnonymousUser("http://acc-sdk:8080", options);
|
|
@@ -63,7 +74,7 @@ const LOGON_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
|
63
74
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
64
75
|
<SOAP-ENV:Body>
|
|
65
76
|
<LogonResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
66
|
-
<pstrSessionToken xsi:type='xsd:string'>
|
|
77
|
+
<pstrSessionToken xsi:type='xsd:string'>___$session_token$</pstrSessionToken>
|
|
67
78
|
<pSessionInfo xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
68
79
|
<sessionInfo>
|
|
69
80
|
<serverInfo advisedClientBuildNumber="0" allowSQL="false" buildNumber="9219" commitId="f5f3ec3" databaseId="uFE80000000000000F1FA913DD7CC7C480041161C" defaultNameSpace="cus" fohVersion="2" instanceName="ffdamkt" majNumber="6" minClientBuildNumber="8969" minNumber="7" minNumberTechnical="0" releaseName="20.3" securityTimeOut="86400" serverDate="2020-07-05 14:11:31.986Z" servicePack="0" sessionTimeOut="86400" useVault="false"/>
|
|
@@ -75,11 +86,32 @@ const LOGON_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
|
75
86
|
</userInfo>
|
|
76
87
|
</sessionInfo>
|
|
77
88
|
</pSessionInfo>
|
|
78
|
-
<pstrSecurityToken xsi:type='xsd:string'
|
|
89
|
+
<pstrSecurityToken xsi:type='xsd:string'>@$security_token$==</pstrSecurityToken>
|
|
79
90
|
</LogonResponse>
|
|
80
91
|
</SOAP-ENV:Body>
|
|
81
92
|
</SOAP-ENV:Envelope>`);
|
|
82
93
|
|
|
94
|
+
const BEARER_LOGON_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
95
|
+
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
96
|
+
<SOAP-ENV:Body>
|
|
97
|
+
<BearerTokenLogonResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
98
|
+
<pstrSessionToken xsi:type='xsd:string'>___$session_token$</pstrSessionToken>
|
|
99
|
+
<pSessionInfo xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
100
|
+
<sessionInfo>
|
|
101
|
+
<serverInfo advisedClientBuildNumber="0" allowSQL="false" buildNumber="9219" commitId="f5f3ec3" databaseId="uFE80000000000000F1FA913DD7CC7C480041161C" defaultNameSpace="cus" fohVersion="2" instanceName="ffdamkt" majNumber="6" minClientBuildNumber="8969" minNumber="7" minNumberTechnical="0" releaseName="20.3" securityTimeOut="86400" serverDate="2020-07-05 14:11:31.986Z" servicePack="0" sessionTimeOut="86400" useVault="false"/>
|
|
102
|
+
<userInfo datakitInDatabase="true" homeDir="" instanceLocale="en" locale="en" login="admin" loginCS="Administrator (admin)" loginId="1059" noConsoleCnx="false" orgUnitId="0" theme="" timezone="Europe/Paris">
|
|
103
|
+
<login-group id="1060"/>
|
|
104
|
+
<login-right right="admin"/>
|
|
105
|
+
<installed-package name="campaign" namespace="nms"/>
|
|
106
|
+
<installed-package name="core" namespace="nms"/>
|
|
107
|
+
</userInfo>
|
|
108
|
+
</sessionInfo>
|
|
109
|
+
</pSessionInfo>
|
|
110
|
+
<pstrSecurityToken xsi:type='xsd:string'>@$security_token$==</pstrSecurityToken>
|
|
111
|
+
</BearerTokenLogonResponse>
|
|
112
|
+
</SOAP-ENV:Body>
|
|
113
|
+
</SOAP-ENV:Envelope>`);
|
|
114
|
+
|
|
83
115
|
const LOGON_RESPONSE_NO_USERINFO = Promise.resolve(`<?xml version='1.0'?>
|
|
84
116
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
85
117
|
<SOAP-ENV:Body>
|
|
@@ -198,7 +230,17 @@ const GET_XTK_SESSION_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
|
198
230
|
</method>
|
|
199
231
|
<method name="NonStatic"></method>
|
|
200
232
|
<method name="TestCnx" static="true"></method>
|
|
201
|
-
|
|
233
|
+
<method name="NonStaticP1">
|
|
234
|
+
<parameters>
|
|
235
|
+
<param name="name" type="string"/>
|
|
236
|
+
</parameters>
|
|
237
|
+
</method>
|
|
238
|
+
<method name="StaticP1" static="true">
|
|
239
|
+
<parameters>
|
|
240
|
+
<param name="name" type="string"/>
|
|
241
|
+
</parameters>
|
|
242
|
+
</method>
|
|
243
|
+
</methods>
|
|
202
244
|
</schema>
|
|
203
245
|
</pdomDoc>
|
|
204
246
|
</GetEntityIfMoreRecentResponse>
|
|
@@ -259,37 +301,43 @@ const GET_XTK_QUERY_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
|
259
301
|
</SOAP-ENV:Body>
|
|
260
302
|
</SOAP-ENV:Envelope>`);
|
|
261
303
|
|
|
262
|
-
const GET_MID_EXT_ACCOUNT_RESPONSE =
|
|
304
|
+
const GET_MID_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
|
|
305
|
+
return Promise.resolve(`<?xml version='1.0'?>
|
|
263
306
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
264
307
|
<SOAP-ENV:Body>
|
|
265
308
|
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
266
309
|
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
267
|
-
<extAccount account="mid" id="2088" name="defaultEmailMid" password="
|
|
310
|
+
<extAccount account="mid" id="2088" name="defaultEmailMid" password="${encryptedPassword}" server="http://ffdamid:8080" type="3"/>
|
|
268
311
|
</pdomOutput>
|
|
269
312
|
</ExecuteQueryResponse>
|
|
270
313
|
</SOAP-ENV:Body>
|
|
271
314
|
</SOAP-ENV:Envelope>`);
|
|
315
|
+
}
|
|
272
316
|
|
|
273
|
-
const GET_BAD_EXT_ACCOUNT_RESPONSE =
|
|
317
|
+
const GET_BAD_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
|
|
318
|
+
return Promise.resolve(`<?xml version='1.0'?>
|
|
274
319
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
275
320
|
<SOAP-ENV:Body>
|
|
276
321
|
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
277
322
|
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
278
|
-
<extAccount account="bad" id="2088" name="bad" password="
|
|
323
|
+
<extAccount account="bad" id="2088" name="bad" password="${encryptedPassword}" server="http://zz:8080" type="999"/>
|
|
279
324
|
</pdomOutput>
|
|
280
325
|
</ExecuteQueryResponse>
|
|
281
326
|
</SOAP-ENV:Body>
|
|
282
327
|
</SOAP-ENV:Envelope>`);
|
|
328
|
+
}
|
|
283
329
|
|
|
284
|
-
const GET_SECRET_KEY_OPTION_RESPONSE =
|
|
330
|
+
const GET_SECRET_KEY_OPTION_RESPONSE = (key) => {
|
|
331
|
+
return Promise.resolve(`<?xml version='1.0'?>
|
|
285
332
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
286
333
|
<SOAP-ENV:Body>
|
|
287
334
|
<GetOptionResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
288
|
-
<pstrValue xsi:type='xsd:string'
|
|
335
|
+
<pstrValue xsi:type='xsd:string'>${key}</pstrValue>
|
|
289
336
|
<pbtType xsi:type='xsd:byte'>6</pbtType>
|
|
290
337
|
</GetOptionResponse>
|
|
291
338
|
</SOAP-ENV:Body>
|
|
292
339
|
</SOAP-ENV:Envelope>`);
|
|
340
|
+
}
|
|
293
341
|
|
|
294
342
|
const GET_LOGON_MID_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
295
343
|
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
@@ -573,11 +621,13 @@ exports.Mock = {
|
|
|
573
621
|
makeClient: makeClient,
|
|
574
622
|
makeAnonymousClient: makeAnonymousClient,
|
|
575
623
|
withMockConsole: withMockConsole,
|
|
624
|
+
makeKey: makeKey,
|
|
576
625
|
R_TEST: R_TEST,
|
|
577
626
|
PING: PING,
|
|
578
627
|
MC_PING: MC_PING,
|
|
579
628
|
MC_PING_ERROR: MC_PING_ERROR,
|
|
580
629
|
LOGON_RESPONSE: LOGON_RESPONSE,
|
|
630
|
+
BEARER_LOGON_RESPONSE: BEARER_LOGON_RESPONSE,
|
|
581
631
|
LOGON_RESPONSE_NO_SESSIONTOKEN: LOGON_RESPONSE_NO_SESSIONTOKEN,
|
|
582
632
|
LOGON_RESPONSE_NO_SECURITYTOKEN: LOGON_RESPONSE_NO_SECURITYTOKEN,
|
|
583
633
|
LOGOFF_RESPONSE: LOGOFF_RESPONSE,
|
package/test/soap.test.js
CHANGED
|
@@ -154,11 +154,8 @@ describe('SOAP', function() {
|
|
|
154
154
|
const env = DomUtil.parse(request.data).documentElement;
|
|
155
155
|
const header = hasChildElement(env, "SOAP-ENV:Header");
|
|
156
156
|
expect(DomUtil.findElement(header, "Cookie")).toBeFalsy();
|
|
157
|
-
hasChildElement(header, "X-Security-Token");
|
|
158
157
|
const body = hasChildElement(env, "SOAP-ENV:Body");
|
|
159
158
|
const method = hasChildElement(body, "m:Empty", undefined, "xmlns:m", "urn:xtk:session", "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/");
|
|
160
|
-
// sessiontoken is always required as first parameter, even if not set
|
|
161
|
-
expect(DomUtil.findElement(method, "sessiontoken")).toBeTruthy();
|
|
162
159
|
});
|
|
163
160
|
|
|
164
161
|
it('Should have set authentication tokens', function() {
|
|
@@ -168,11 +165,8 @@ describe('SOAP', function() {
|
|
|
168
165
|
assert.equal(request.headers["Cookie"], "__sessiontoken=$session$", "Session token matches");
|
|
169
166
|
const env = DomUtil.parse(request.data).documentElement;
|
|
170
167
|
const header = hasChildElement(env, "SOAP-ENV:Header");
|
|
171
|
-
hasChildElement(header, "Cookie", "__sessiontoken=$session$");
|
|
172
|
-
hasChildElement(header, "X-Security-Token", "$security$");
|
|
173
168
|
const body = hasChildElement(env, "SOAP-ENV:Body");
|
|
174
169
|
const method = hasChildElement(body, "m:Empty");
|
|
175
|
-
hasChildElement(method, "sessiontoken", "$session$", "xsi:type", "xsd:string");
|
|
176
170
|
});
|
|
177
171
|
|
|
178
172
|
it('Should set boolean parameters', function() {
|