@adobe/acc-js-sdk 1.0.6 → 1.0.7

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.
@@ -22,6 +22,7 @@ const { Client, ConnectionParameters } = require('../src/client.js');
22
22
  const DomUtil = require('../src/domUtil.js').DomUtil;
23
23
  const Mock = require('./mock.js').Mock;
24
24
  const { HttpError } = require('../src/transport.js');
25
+ const { Cipher } = require('../src/crypto.js');
25
26
 
26
27
 
27
28
  describe('ACC Client', function () {
@@ -604,11 +605,13 @@ describe('ACC Client', function () {
604
605
  const client = await Mock.makeClient();
605
606
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
606
607
  await client.NLWS.xtkSession.logon();
608
+ const key = Mock.makeKey();
609
+ const encrypted = new Cipher(key).encryptPassword("mid");
607
610
 
608
611
  client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
609
- client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
612
+ client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
610
613
  client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
611
- client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
614
+ client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
612
615
  var connectionParameters = await sdk.ConnectionParameters.ofExternalAccount(client, "defaultEmailMid");
613
616
  var midClient = await sdk.init(connectionParameters);
614
617
  midClient._transport = jest.fn();
@@ -630,11 +633,13 @@ describe('ACC Client', function () {
630
633
  const client = await Mock.makeClient();
631
634
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
632
635
  await client.NLWS.xtkSession.logon();
636
+ const key = Mock.makeKey();
637
+ const encrypted = new Cipher(key).encryptPassword("mid");
633
638
 
634
639
  client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
635
- client._transport.mockReturnValueOnce(Mock.GET_BAD_EXT_ACCOUNT_RESPONSE);
640
+ client._transport.mockReturnValueOnce(Mock.GET_BAD_EXT_ACCOUNT_RESPONSE(encrypted));
636
641
  client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
637
- client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
642
+ client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
638
643
  await expect(async () => {
639
644
  return sdk.ConnectionParameters.ofExternalAccount(client, "bad");
640
645
  }).rejects.toMatchObject({ errorCode: "SDK-000005" });
@@ -642,14 +647,16 @@ describe('ACC Client', function () {
642
647
 
643
648
  it("Should fail if invalid representation", async () => {
644
649
  const client = await Mock.makeClient();
650
+ const key = Mock.makeKey();
651
+ const encrypted = new Cipher(key).encryptPassword("mid");
645
652
 
646
653
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
647
654
  await client.NLWS.xtkSession.logon();
648
655
 
649
656
  client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
650
- client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
657
+ client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
651
658
  client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
652
- client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
659
+ client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
653
660
 
654
661
  await expect(async () => {
655
662
  client._representation = "Dummy";
@@ -663,14 +670,16 @@ describe('ACC Client', function () {
663
670
  it("Should fail not fail with SimpleJson representation", async () => {
664
671
  const client = await Mock.makeClient();
665
672
  client._representation = "SimpleJson";
673
+ const key = Mock.makeKey();
674
+ const encrypted = new Cipher(key).encryptPassword("mid");
666
675
 
667
676
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
668
677
  await client.NLWS.xtkSession.logon();
669
678
 
670
679
  client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
671
- client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
680
+ client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
672
681
  client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
673
- client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
682
+ client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
674
683
 
675
684
  var connectionParameters = await sdk.ConnectionParameters.ofExternalAccount(client, "defaultEmailMid");
676
685
  await sdk.init(connectionParameters);
@@ -680,9 +689,10 @@ describe('ACC Client', function () {
680
689
  const client = await Mock.makeClient();
681
690
  client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
682
691
  await client.NLWS.xtkSession.logon();
683
-
692
+ const key = Mock.makeKey();
693
+
684
694
  client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
685
- client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
695
+ client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
686
696
  var cipher = await client._getSecretKeyCipher();
687
697
  expect(cipher).not.toBeNull();
688
698
  expect(cipher.key).not.toBeNull();
@@ -1899,7 +1909,7 @@ describe('ACC Client', function () {
1899
1909
  describe("Bearer token authentication", () => {
1900
1910
  // Bearer token authentication is used when embedding IMS for authentication
1901
1911
  it("Should create logged client", async() => {
1902
- const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080", "$token$");
1912
+ const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080");
1903
1913
  const client = await sdk.init(connectionParameters);
1904
1914
  client._transport = jest.fn();
1905
1915
  client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
@@ -1946,7 +1956,149 @@ describe('ACC Client', function () {
1946
1956
  var extAccount = await query.executeQuery();
1947
1957
  expect(extAccount).toEqual({ extAccount: [] });
1948
1958
  });
1949
- })
1959
+
1960
+ it("Expired session refresh client callback", async () => {
1961
+ let refreshClient = async (client) => {
1962
+ const connectionParameters = sdk.ConnectionParameters.ofSecurityToken("http://acc-sdk:8080",
1963
+ "$security_token$", {refreshClient: refreshClient});
1964
+ const newClient = await sdk.init(connectionParameters);
1965
+ newClient._transport = jest.fn();
1966
+ newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
1967
+ await newClient.logon();
1968
+ return newClient;
1969
+ }
1970
+ const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
1971
+ "$token$", {refreshClient: refreshClient});
1972
+ const client = await sdk.init(connectionParameters);
1973
+ client.traceAPICalls(true);
1974
+ client._transport = jest.fn();
1975
+ client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
1976
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
1977
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
1978
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
1979
+ <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/'>
1980
+ <SOAP-ENV:Body>
1981
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
1982
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
1983
+ <extAccount-collection/>
1984
+ </pdomOutput></ExecuteQueryResponse>
1985
+ </SOAP-ENV:Body>
1986
+ </SOAP-ENV:Envelope>`));
1987
+ await client.logon();
1988
+ var queryDef = {
1989
+ "schema": "nms:extAccount",
1990
+ "operation": "select",
1991
+ "select": {
1992
+ "node": [
1993
+ { "expr": "@id" },
1994
+ { "expr": "@name" }
1995
+ ]
1996
+ }
1997
+ };
1998
+ var query = client.NLWS.xtkQueryDef.create(queryDef);
1999
+ var extAccount = await query.executeQuery();
2000
+ expect(extAccount).toEqual({ extAccount: [] });
2001
+ // Same test as before traceAPICalls = false for code coverage
2002
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
2003
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
2004
+ <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/'>
2005
+ <SOAP-ENV:Body>
2006
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
2007
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
2008
+ <extAccount-collection/>
2009
+ </pdomOutput></ExecuteQueryResponse>
2010
+ </SOAP-ENV:Body>
2011
+ </SOAP-ENV:Envelope>`));
2012
+ client.traceAPICalls(false);
2013
+ var query1 = client.NLWS.xtkQueryDef.create(queryDef);
2014
+ extAccount1 = await query1.executeQuery();
2015
+ expect(extAccount1).toEqual({ extAccount: [] });
2016
+ });
2017
+
2018
+ it("Expired session refresh client callback for code coverage", async () => {
2019
+ let refreshClient = async (client) => {
2020
+ const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "$session_token$");
2021
+ const newClient = await sdk.init(connectionParameters);
2022
+ newClient._transport = jest.fn();
2023
+ newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
2024
+ await newClient.logon();
2025
+ return newClient;
2026
+ }
2027
+ const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
2028
+ "$token$", {refreshClient: refreshClient});
2029
+ const client = await sdk.init(connectionParameters);
2030
+ client.traceAPICalls(true);
2031
+ client._transport = jest.fn();
2032
+ client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
2033
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
2034
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
2035
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
2036
+ <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/'>
2037
+ <SOAP-ENV:Body>
2038
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
2039
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
2040
+ <extAccount-collection/>
2041
+ </pdomOutput></ExecuteQueryResponse>
2042
+ </SOAP-ENV:Body>
2043
+ </SOAP-ENV:Envelope>`));
2044
+ await client.logon();
2045
+ var queryDef = {
2046
+ "schema": "nms:extAccount",
2047
+ "operation": "select",
2048
+ "select": {
2049
+ "node": [
2050
+ { "expr": "@id" },
2051
+ { "expr": "@name" }
2052
+ ]
2053
+ }
2054
+ };
2055
+ var query = client.NLWS.xtkQueryDef.create(queryDef);
2056
+ var extAccount = await query.executeQuery();
2057
+ expect(extAccount).toEqual({ extAccount: [] });
2058
+ });
2059
+
2060
+ it("Expired session refresh client callback retry failure", async () => {
2061
+ let refreshClient = async (client) => {
2062
+ const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
2063
+ "$token$", {refreshClient: refreshClient});
2064
+ const newClient = await sdk.init(connectionParameters);
2065
+ newClient._transport = jest.fn();
2066
+ newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
2067
+ await newClient.logon();
2068
+ return newClient;
2069
+ }
2070
+ const connectionParameters = sdk.ConnectionParameters.ofSecurityToken("http://acc-sdk:8080",
2071
+ "$security_token$", {refreshClient: refreshClient});
2072
+ const client = await sdk.init(connectionParameters);
2073
+ client._transport = jest.fn();
2074
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
2075
+ client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
2076
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
2077
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
2078
+ <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/'>
2079
+ <SOAP-ENV:Body>
2080
+ <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
2081
+ <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
2082
+ <extAccount-collection/>
2083
+ </pdomOutput></ExecuteQueryResponse>
2084
+ </SOAP-ENV:Body>
2085
+ </SOAP-ENV:Envelope>`));
2086
+ await client.logon();
2087
+ var queryDef = {
2088
+ "schema": "nms:extAccount",
2089
+ "operation": "select",
2090
+ "select": {
2091
+ "node": [
2092
+ { "expr": "@id" },
2093
+ { "expr": "@name" }
2094
+ ]
2095
+ }
2096
+ };
2097
+ var query = client.NLWS.xtkQueryDef.create(queryDef);
2098
+ await expect(query.executeQuery()).rejects.toMatchObject({ errorCode: "SDK-000012" });
2099
+ expect(client._transport.mock.calls.length).toBe(2);
2100
+ });
2101
+ })
1950
2102
 
1951
2103
  describe("Logon should always return a promise", () => {
1952
2104
 
@@ -2130,15 +2282,15 @@ describe('ACC Client', function () {
2130
2282
  it("Should ignore protocol for local storage root key", async () => {
2131
2283
  var connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("http://acc-sdk:8080", "admin", "admin", {});
2132
2284
  var client = await sdk.init(connectionParameters);
2133
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.6.acc-sdk:8080.cache.OptionCache$");
2285
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2134
2286
 
2135
2287
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("https://acc-sdk:8080", "admin", "admin", {});
2136
2288
  client = await sdk.init(connectionParameters);
2137
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.6.acc-sdk:8080.cache.OptionCache$");
2289
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2138
2290
 
2139
2291
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("acc-sdk:8080", "admin", "admin", {});
2140
2292
  client = await sdk.init(connectionParameters);
2141
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.6.acc-sdk:8080.cache.OptionCache$");
2293
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2142
2294
  })
2143
2295
 
2144
2296
  it("Should support no storage", async () => {
@@ -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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
28
- var decrypted = cipher.decryptPassword("@57QS5VHMb9BCsojLVrKI/Q==");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
41
- var decrypted = cipher.decryptPassword("@57QS5VHMb9BCsojLVrKI/Q==");
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("@57QS5VHMb9BCsojLVrKI/Q==");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
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
- var decrypted = cipher.decryptPassword("@57QS5VHMb9BCsojLVrKI/Q==");
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("llL97E5mAvLTxgT1fsAH2kjLqZXKCGHfDyR9q0C6Ivs=");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
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("HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=");
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/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);
@@ -280,37 +291,43 @@ const GET_XTK_QUERY_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
280
291
  </SOAP-ENV:Body>
281
292
  </SOAP-ENV:Envelope>`);
282
293
 
283
- const GET_MID_EXT_ACCOUNT_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
294
+ const GET_MID_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
295
+ return Promise.resolve(`<?xml version='1.0'?>
284
296
  <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/'>
285
297
  <SOAP-ENV:Body>
286
298
  <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
287
299
  <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
288
- <extAccount account="mid" id="2088" name="defaultEmailMid" password="@57QS5VHMb9BCsojLVrKI/Q==" server="http://ffdamid:8080" type="3"/>
300
+ <extAccount account="mid" id="2088" name="defaultEmailMid" password="${encryptedPassword}" server="http://ffdamid:8080" type="3"/>
289
301
  </pdomOutput>
290
302
  </ExecuteQueryResponse>
291
303
  </SOAP-ENV:Body>
292
304
  </SOAP-ENV:Envelope>`);
305
+ }
293
306
 
294
- const GET_BAD_EXT_ACCOUNT_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
307
+ const GET_BAD_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
308
+ return Promise.resolve(`<?xml version='1.0'?>
295
309
  <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/'>
296
310
  <SOAP-ENV:Body>
297
311
  <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
298
312
  <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
299
- <extAccount account="bad" id="2088" name="bad" password="@57QS5VHMb9BCsojLVrKI/Q==" server="http://zz:8080" type="999"/>
313
+ <extAccount account="bad" id="2088" name="bad" password="${encryptedPassword}" server="http://zz:8080" type="999"/>
300
314
  </pdomOutput>
301
315
  </ExecuteQueryResponse>
302
316
  </SOAP-ENV:Body>
303
317
  </SOAP-ENV:Envelope>`);
318
+ }
304
319
 
305
- const GET_SECRET_KEY_OPTION_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
320
+ const GET_SECRET_KEY_OPTION_RESPONSE = (key) => {
321
+ return Promise.resolve(`<?xml version='1.0'?>
306
322
  <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/'>
307
323
  <SOAP-ENV:Body>
308
324
  <GetOptionResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
309
- <pstrValue xsi:type='xsd:string'>HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=</pstrValue>
325
+ <pstrValue xsi:type='xsd:string'>${key}</pstrValue>
310
326
  <pbtType xsi:type='xsd:byte'>6</pbtType>
311
327
  </GetOptionResponse>
312
328
  </SOAP-ENV:Body>
313
329
  </SOAP-ENV:Envelope>`);
330
+ }
314
331
 
315
332
  const GET_LOGON_MID_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
316
333
  <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/'>
@@ -594,6 +611,7 @@ exports.Mock = {
594
611
  makeClient: makeClient,
595
612
  makeAnonymousClient: makeAnonymousClient,
596
613
  withMockConsole: withMockConsole,
614
+ makeKey: makeKey,
597
615
  R_TEST: R_TEST,
598
616
  PING: PING,
599
617
  MC_PING: MC_PING,
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() {
@@ -696,14 +696,22 @@ describe('XtkCaster', function() {
696
696
  expect(XtkCaster._variantStorageAttribute(6)).toBe("stringValue");
697
697
  expect(XtkCaster._variantStorageAttribute("string")).toBe("stringValue");
698
698
  expect(XtkCaster._variantStorageAttribute("int64")).toBe("stringValue");
699
+ expect(XtkCaster._variantStorageAttribute("uuid")).toBe("stringValue");
699
700
  expect(XtkCaster._variantStorageAttribute(12)).toBe("memoValue");
700
701
  expect(XtkCaster._variantStorageAttribute(13)).toBe("memoValue");
701
702
  expect(XtkCaster._variantStorageAttribute("memo")).toBe("memoValue");
702
703
  expect(XtkCaster._variantStorageAttribute("CDATA")).toBe("memoValue");
704
+ expect(XtkCaster._variantStorageAttribute("blob")).toBe("memoValue");
705
+ expect(XtkCaster._variantStorageAttribute("html")).toBe("memoValue");
703
706
  expect(XtkCaster._variantStorageAttribute(1)).toBe("longValue");
704
707
  expect(XtkCaster._variantStorageAttribute(2)).toBe("longValue");
705
708
  expect(XtkCaster._variantStorageAttribute(3)).toBe("longValue");
706
709
  expect(XtkCaster._variantStorageAttribute(15)).toBe("longValue");
710
+ expect(XtkCaster._variantStorageAttribute("byte")).toBe("longValue");
711
+ expect(XtkCaster._variantStorageAttribute("short")).toBe("longValue");
712
+ expect(XtkCaster._variantStorageAttribute("long")).toBe("longValue");
713
+ expect(XtkCaster._variantStorageAttribute("int")).toBe("longValue");
714
+ expect(XtkCaster._variantStorageAttribute("boolean")).toBe("longValue");
707
715
  expect(XtkCaster._variantStorageAttribute(4)).toBe("doubleValue");
708
716
  expect(XtkCaster._variantStorageAttribute(5)).toBe("doubleValue");
709
717
  expect(XtkCaster._variantStorageAttribute("float")).toBe("doubleValue");
@@ -716,4 +724,93 @@ describe('XtkCaster', function() {
716
724
  expect(XtkCaster._variantStorageAttribute("date")).toBe("timeStampValue");
717
725
  expect(() => { XtkCaster._variantStorageAttribute(777); }).toThrow("Cannot get variant storage");
718
726
  });
727
+
728
+ describe("Array tests", () => {
729
+ it("Should return array", () => {
730
+ expect(XtkCaster.asArray(null)).toStrictEqual([]);
731
+ expect(XtkCaster.asArray(undefined)).toStrictEqual([]);
732
+ expect(XtkCaster.asArray(false)).toStrictEqual([false]);
733
+ expect(XtkCaster.asArray("Hello")).toStrictEqual(["Hello"]);
734
+ expect(XtkCaster.asArray([])).toStrictEqual([]);
735
+ expect(XtkCaster.asArray([null])).toStrictEqual([null]);
736
+ })
737
+
738
+ it("Should support arrays", () => {
739
+ expect(XtkCaster.as(null, "array")).toStrictEqual([]);
740
+ expect(XtkCaster.as(undefined, "array")).toStrictEqual([]);
741
+ expect(XtkCaster.as(false, "array")).toStrictEqual([false]);
742
+ expect(XtkCaster.as("Hello", "array")).toStrictEqual(["Hello"]);
743
+ expect(XtkCaster.as([], "array")).toStrictEqual([]);
744
+ expect(XtkCaster.as([null], "array")).toStrictEqual([null]);
745
+ });
746
+ });
747
+
748
+ describe("Timespan test", () => {
749
+ it("Should return timespan", () => {
750
+ expect(XtkCaster.asTimespan(null)).toStrictEqual(0);
751
+ expect(XtkCaster.asTimespan(undefined)).toStrictEqual(0);
752
+ expect(XtkCaster.asTimespan(false)).toStrictEqual(0);
753
+ expect(XtkCaster.asTimespan("Hello")).toStrictEqual(0);
754
+ expect(XtkCaster.asTimespan([])).toStrictEqual(0);
755
+ expect(XtkCaster.asTimespan([null])).toStrictEqual(0);
756
+ expect(XtkCaster.asTimespan(NaN)).toStrictEqual(0);
757
+ expect(XtkCaster.asTimespan(Number.POSITIVE_INFINITY)).toStrictEqual(0);
758
+ expect(XtkCaster.asTimespan(Number.NEGATIVE_INFINITY)).toStrictEqual(0);
759
+ expect(XtkCaster.asTimespan("86400")).toStrictEqual(86400);
760
+ expect(XtkCaster.asTimespan(86400)).toStrictEqual(86400);
761
+ })
762
+
763
+ it("As should support 'timspan'", () => {
764
+ expect(XtkCaster.as(null, "timespan")).toStrictEqual(0);
765
+ expect(XtkCaster.as(undefined, "timespan")).toStrictEqual(0);
766
+ expect(XtkCaster.as(false, "timespan")).toStrictEqual(0);
767
+ expect(XtkCaster.as("Hello", "timespan")).toStrictEqual(0);
768
+ expect(XtkCaster.as([], "timespan")).toStrictEqual(0);
769
+ expect(XtkCaster.as([null], "timespan")).toStrictEqual(0);
770
+ expect(XtkCaster.as("86400", "timespan")).toStrictEqual(86400);
771
+ expect(XtkCaster.as(86400, "timespan")).toStrictEqual(86400);
772
+ });
773
+
774
+ it("As should support type 14", () => {
775
+ expect(XtkCaster.as(null, 14)).toStrictEqual(0);
776
+ expect(XtkCaster.as(undefined, 14)).toStrictEqual(0);
777
+ expect(XtkCaster.as(false, 14)).toStrictEqual(0);
778
+ expect(XtkCaster.as("Hello", 14)).toStrictEqual(0);
779
+ expect(XtkCaster.as([], 14)).toStrictEqual(0);
780
+ expect(XtkCaster.as([null], 14)).toStrictEqual(0);
781
+ expect(XtkCaster.as("86400", 14)).toStrictEqual(86400);
782
+ expect(XtkCaster.as(86400, 14)).toStrictEqual(86400);
783
+ });
784
+ })
785
+
786
+ describe("Other string types", () => {
787
+ it("Type 'html'", () => {
788
+ expect(XtkCaster.as(null, "html")).toStrictEqual("");
789
+ expect(XtkCaster.as(undefined, "html")).toStrictEqual("");
790
+ expect(XtkCaster.as("Hello", "html")).toStrictEqual("Hello");
791
+ expect(XtkCaster.as("0", "html")).toStrictEqual("0");
792
+ });
793
+
794
+ it("Type 'uuid'", () => {
795
+ expect(XtkCaster.as(null, "uuid")).toStrictEqual("");
796
+ expect(XtkCaster.as(undefined, "uuid")).toStrictEqual("");
797
+ expect(XtkCaster.as("Hello", "uuid")).toStrictEqual("Hello");
798
+ expect(XtkCaster.as("0", "uuid")).toStrictEqual("0");
799
+ });
800
+
801
+ it("Type 'blob'", () => {
802
+ expect(XtkCaster.as(null, "blob")).toStrictEqual("");
803
+ expect(XtkCaster.as(undefined, "blob")).toStrictEqual("");
804
+ expect(XtkCaster.as("Hello", "blob")).toStrictEqual("Hello");
805
+ expect(XtkCaster.as("0", "blob")).toStrictEqual("0");
806
+ });
807
+
808
+ it("Type 'int'", () => {
809
+ expect(XtkCaster.as(null, "int")).toStrictEqual(0);
810
+ expect(XtkCaster.as(undefined, "int")).toStrictEqual(0);
811
+ expect(XtkCaster.as("42", "int")).toStrictEqual(42);
812
+ expect(XtkCaster.as("0", "int")).toStrictEqual(0);
813
+ });
814
+ })
815
+
719
816
  });