@adobe/acc-js-sdk 1.0.6 → 1.0.9
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/CHANGELOG.md +32 -0
- package/README.md +192 -63
- package/compile.js +1 -0
- package/package-lock.json +2156 -3344
- 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/campaign.js +4 -0
- package/src/client.js +61 -14
- package/src/domUtil.js +6 -3
- package/src/entityAccessor.js +5 -5
- package/src/index.js +58 -2
- package/src/soap.js +44 -18
- package/src/testUtil.js +47 -0
- package/src/xtkCaster.js +80 -6
- package/test/application.test.js +684 -616
- package/test/client.test.js +238 -15
- 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 +35 -7
- package/test/soap.test.js +0 -6
- package/test/testUtil.test.js +64 -0
- package/test/xtkCaster.test.js +219 -1
package/test/client.test.js
CHANGED
|
@@ -22,6 +22,8 @@ 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');
|
|
26
|
+
const { EntityAccessor } = require('../src/entityAccessor.js');
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
describe('ACC Client', function () {
|
|
@@ -604,11 +606,13 @@ describe('ACC Client', function () {
|
|
|
604
606
|
const client = await Mock.makeClient();
|
|
605
607
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
606
608
|
await client.NLWS.xtkSession.logon();
|
|
609
|
+
const key = Mock.makeKey();
|
|
610
|
+
const encrypted = new Cipher(key).encryptPassword("mid");
|
|
607
611
|
|
|
608
612
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
609
|
-
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
|
|
613
|
+
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
|
|
610
614
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
611
|
-
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
|
|
615
|
+
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
|
|
612
616
|
var connectionParameters = await sdk.ConnectionParameters.ofExternalAccount(client, "defaultEmailMid");
|
|
613
617
|
var midClient = await sdk.init(connectionParameters);
|
|
614
618
|
midClient._transport = jest.fn();
|
|
@@ -630,11 +634,13 @@ describe('ACC Client', function () {
|
|
|
630
634
|
const client = await Mock.makeClient();
|
|
631
635
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
632
636
|
await client.NLWS.xtkSession.logon();
|
|
637
|
+
const key = Mock.makeKey();
|
|
638
|
+
const encrypted = new Cipher(key).encryptPassword("mid");
|
|
633
639
|
|
|
634
640
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
635
|
-
client._transport.mockReturnValueOnce(Mock.GET_BAD_EXT_ACCOUNT_RESPONSE);
|
|
641
|
+
client._transport.mockReturnValueOnce(Mock.GET_BAD_EXT_ACCOUNT_RESPONSE(encrypted));
|
|
636
642
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
637
|
-
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
|
|
643
|
+
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
|
|
638
644
|
await expect(async () => {
|
|
639
645
|
return sdk.ConnectionParameters.ofExternalAccount(client, "bad");
|
|
640
646
|
}).rejects.toMatchObject({ errorCode: "SDK-000005" });
|
|
@@ -642,14 +648,16 @@ describe('ACC Client', function () {
|
|
|
642
648
|
|
|
643
649
|
it("Should fail if invalid representation", async () => {
|
|
644
650
|
const client = await Mock.makeClient();
|
|
651
|
+
const key = Mock.makeKey();
|
|
652
|
+
const encrypted = new Cipher(key).encryptPassword("mid");
|
|
645
653
|
|
|
646
654
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
647
655
|
await client.NLWS.xtkSession.logon();
|
|
648
656
|
|
|
649
657
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
650
|
-
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
|
|
658
|
+
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
|
|
651
659
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
652
|
-
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
|
|
660
|
+
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
|
|
653
661
|
|
|
654
662
|
await expect(async () => {
|
|
655
663
|
client._representation = "Dummy";
|
|
@@ -663,14 +671,16 @@ describe('ACC Client', function () {
|
|
|
663
671
|
it("Should fail not fail with SimpleJson representation", async () => {
|
|
664
672
|
const client = await Mock.makeClient();
|
|
665
673
|
client._representation = "SimpleJson";
|
|
674
|
+
const key = Mock.makeKey();
|
|
675
|
+
const encrypted = new Cipher(key).encryptPassword("mid");
|
|
666
676
|
|
|
667
677
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
668
678
|
await client.NLWS.xtkSession.logon();
|
|
669
679
|
|
|
670
680
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
671
|
-
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE);
|
|
681
|
+
client._transport.mockReturnValueOnce(Mock.GET_MID_EXT_ACCOUNT_RESPONSE(encrypted));
|
|
672
682
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
673
|
-
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
|
|
683
|
+
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
|
|
674
684
|
|
|
675
685
|
var connectionParameters = await sdk.ConnectionParameters.ofExternalAccount(client, "defaultEmailMid");
|
|
676
686
|
await sdk.init(connectionParameters);
|
|
@@ -680,9 +690,10 @@ describe('ACC Client', function () {
|
|
|
680
690
|
const client = await Mock.makeClient();
|
|
681
691
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
682
692
|
await client.NLWS.xtkSession.logon();
|
|
683
|
-
|
|
693
|
+
const key = Mock.makeKey();
|
|
694
|
+
|
|
684
695
|
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
685
|
-
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE);
|
|
696
|
+
client._transport.mockReturnValueOnce(Mock.GET_SECRET_KEY_OPTION_RESPONSE(key));
|
|
686
697
|
var cipher = await client._getSecretKeyCipher();
|
|
687
698
|
expect(cipher).not.toBeNull();
|
|
688
699
|
expect(cipher.key).not.toBeNull();
|
|
@@ -1899,7 +1910,7 @@ describe('ACC Client', function () {
|
|
|
1899
1910
|
describe("Bearer token authentication", () => {
|
|
1900
1911
|
// Bearer token authentication is used when embedding IMS for authentication
|
|
1901
1912
|
it("Should create logged client", async() => {
|
|
1902
|
-
const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080"
|
|
1913
|
+
const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080");
|
|
1903
1914
|
const client = await sdk.init(connectionParameters);
|
|
1904
1915
|
client._transport = jest.fn();
|
|
1905
1916
|
client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
@@ -1946,7 +1957,149 @@ describe('ACC Client', function () {
|
|
|
1946
1957
|
var extAccount = await query.executeQuery();
|
|
1947
1958
|
expect(extAccount).toEqual({ extAccount: [] });
|
|
1948
1959
|
});
|
|
1949
|
-
|
|
1960
|
+
|
|
1961
|
+
it("Expired session refresh client callback", async () => {
|
|
1962
|
+
let refreshClient = async () => {
|
|
1963
|
+
const connectionParameters = sdk.ConnectionParameters.ofSecurityToken("http://acc-sdk:8080",
|
|
1964
|
+
"$security_token$", {refreshClient: refreshClient});
|
|
1965
|
+
const newClient = await sdk.init(connectionParameters);
|
|
1966
|
+
newClient._transport = jest.fn();
|
|
1967
|
+
newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
1968
|
+
await newClient.logon();
|
|
1969
|
+
return newClient;
|
|
1970
|
+
}
|
|
1971
|
+
const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
|
|
1972
|
+
"$token$", {refreshClient: refreshClient});
|
|
1973
|
+
const client = await sdk.init(connectionParameters);
|
|
1974
|
+
client.traceAPICalls(true);
|
|
1975
|
+
client._transport = jest.fn();
|
|
1976
|
+
client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
1977
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
|
|
1978
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
1979
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
1980
|
+
<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/'>
|
|
1981
|
+
<SOAP-ENV:Body>
|
|
1982
|
+
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
1983
|
+
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
1984
|
+
<extAccount-collection/>
|
|
1985
|
+
</pdomOutput></ExecuteQueryResponse>
|
|
1986
|
+
</SOAP-ENV:Body>
|
|
1987
|
+
</SOAP-ENV:Envelope>`));
|
|
1988
|
+
await client.logon();
|
|
1989
|
+
var queryDef = {
|
|
1990
|
+
"schema": "nms:extAccount",
|
|
1991
|
+
"operation": "select",
|
|
1992
|
+
"select": {
|
|
1993
|
+
"node": [
|
|
1994
|
+
{ "expr": "@id" },
|
|
1995
|
+
{ "expr": "@name" }
|
|
1996
|
+
]
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
var query = client.NLWS.xtkQueryDef.create(queryDef);
|
|
2000
|
+
var extAccount = await query.executeQuery();
|
|
2001
|
+
expect(extAccount).toEqual({ extAccount: [] });
|
|
2002
|
+
// Same test as before traceAPICalls = false for code coverage
|
|
2003
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
|
|
2004
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
2005
|
+
<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/'>
|
|
2006
|
+
<SOAP-ENV:Body>
|
|
2007
|
+
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
2008
|
+
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
2009
|
+
<extAccount-collection/>
|
|
2010
|
+
</pdomOutput></ExecuteQueryResponse>
|
|
2011
|
+
</SOAP-ENV:Body>
|
|
2012
|
+
</SOAP-ENV:Envelope>`));
|
|
2013
|
+
client.traceAPICalls(false);
|
|
2014
|
+
var query1 = client.NLWS.xtkQueryDef.create(queryDef);
|
|
2015
|
+
const extAccount1 = await query1.executeQuery();
|
|
2016
|
+
expect(extAccount1).toEqual({ extAccount: [] });
|
|
2017
|
+
});
|
|
2018
|
+
|
|
2019
|
+
it("Expired session refresh client callback for code coverage", async () => {
|
|
2020
|
+
let refreshClient = async () => {
|
|
2021
|
+
const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "$session_token$");
|
|
2022
|
+
const newClient = await sdk.init(connectionParameters);
|
|
2023
|
+
newClient._transport = jest.fn();
|
|
2024
|
+
newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
2025
|
+
await newClient.logon();
|
|
2026
|
+
return newClient;
|
|
2027
|
+
}
|
|
2028
|
+
const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
|
|
2029
|
+
"$token$", {refreshClient: refreshClient});
|
|
2030
|
+
const client = await sdk.init(connectionParameters);
|
|
2031
|
+
client.traceAPICalls(true);
|
|
2032
|
+
client._transport = jest.fn();
|
|
2033
|
+
client._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
2034
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
|
|
2035
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
2036
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
2037
|
+
<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/'>
|
|
2038
|
+
<SOAP-ENV:Body>
|
|
2039
|
+
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
2040
|
+
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
2041
|
+
<extAccount-collection/>
|
|
2042
|
+
</pdomOutput></ExecuteQueryResponse>
|
|
2043
|
+
</SOAP-ENV:Body>
|
|
2044
|
+
</SOAP-ENV:Envelope>`));
|
|
2045
|
+
await client.logon();
|
|
2046
|
+
var queryDef = {
|
|
2047
|
+
"schema": "nms:extAccount",
|
|
2048
|
+
"operation": "select",
|
|
2049
|
+
"select": {
|
|
2050
|
+
"node": [
|
|
2051
|
+
{ "expr": "@id" },
|
|
2052
|
+
{ "expr": "@name" }
|
|
2053
|
+
]
|
|
2054
|
+
}
|
|
2055
|
+
};
|
|
2056
|
+
var query = client.NLWS.xtkQueryDef.create(queryDef);
|
|
2057
|
+
var extAccount = await query.executeQuery();
|
|
2058
|
+
expect(extAccount).toEqual({ extAccount: [] });
|
|
2059
|
+
});
|
|
2060
|
+
|
|
2061
|
+
it("Expired session refresh client callback retry failure", async () => {
|
|
2062
|
+
let refreshClient = async () => {
|
|
2063
|
+
const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
|
|
2064
|
+
"$token$", {refreshClient: refreshClient});
|
|
2065
|
+
const newClient = await sdk.init(connectionParameters);
|
|
2066
|
+
newClient._transport = jest.fn();
|
|
2067
|
+
newClient._transport.mockReturnValueOnce(Mock.BEARER_LOGON_RESPONSE);
|
|
2068
|
+
await newClient.logon();
|
|
2069
|
+
return newClient;
|
|
2070
|
+
}
|
|
2071
|
+
const connectionParameters = sdk.ConnectionParameters.ofSecurityToken("http://acc-sdk:8080",
|
|
2072
|
+
"$security_token$", {refreshClient: refreshClient});
|
|
2073
|
+
const client = await sdk.init(connectionParameters);
|
|
2074
|
+
client._transport = jest.fn();
|
|
2075
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
|
|
2076
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`XSV-350008 Session has expired or is invalid. Please reconnect.`));
|
|
2077
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
2078
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
2079
|
+
<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/'>
|
|
2080
|
+
<SOAP-ENV:Body>
|
|
2081
|
+
<ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
2082
|
+
<pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
2083
|
+
<extAccount-collection/>
|
|
2084
|
+
</pdomOutput></ExecuteQueryResponse>
|
|
2085
|
+
</SOAP-ENV:Body>
|
|
2086
|
+
</SOAP-ENV:Envelope>`));
|
|
2087
|
+
await client.logon();
|
|
2088
|
+
var queryDef = {
|
|
2089
|
+
"schema": "nms:extAccount",
|
|
2090
|
+
"operation": "select",
|
|
2091
|
+
"select": {
|
|
2092
|
+
"node": [
|
|
2093
|
+
{ "expr": "@id" },
|
|
2094
|
+
{ "expr": "@name" }
|
|
2095
|
+
]
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
var query = client.NLWS.xtkQueryDef.create(queryDef);
|
|
2099
|
+
await expect(query.executeQuery()).rejects.toMatchObject({ errorCode: "SDK-000012" });
|
|
2100
|
+
expect(client._transport.mock.calls.length).toBe(2);
|
|
2101
|
+
});
|
|
2102
|
+
})
|
|
1950
2103
|
|
|
1951
2104
|
describe("Logon should always return a promise", () => {
|
|
1952
2105
|
|
|
@@ -2130,15 +2283,15 @@ describe('ACC Client', function () {
|
|
|
2130
2283
|
it("Should ignore protocol for local storage root key", async () => {
|
|
2131
2284
|
var connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("http://acc-sdk:8080", "admin", "admin", {});
|
|
2132
2285
|
var client = await sdk.init(connectionParameters);
|
|
2133
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.
|
|
2286
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
|
|
2134
2287
|
|
|
2135
2288
|
connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("https://acc-sdk:8080", "admin", "admin", {});
|
|
2136
2289
|
client = await sdk.init(connectionParameters);
|
|
2137
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.
|
|
2290
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
|
|
2138
2291
|
|
|
2139
2292
|
connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("acc-sdk:8080", "admin", "admin", {});
|
|
2140
2293
|
client = await sdk.init(connectionParameters);
|
|
2141
|
-
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.
|
|
2294
|
+
expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
|
|
2142
2295
|
})
|
|
2143
2296
|
|
|
2144
2297
|
it("Should support no storage", async () => {
|
|
@@ -2197,6 +2350,76 @@ describe('ACC Client', function () {
|
|
|
2197
2350
|
expect(schema["namespace"]).toBe("nms");
|
|
2198
2351
|
expect(schema["name"]).toBe("extAccount");
|
|
2199
2352
|
});
|
|
2353
|
+
});
|
|
2354
|
+
|
|
2355
|
+
describe("Calling SOAP method with parameters as a function", () => {
|
|
2356
|
+
it("Should make SOAP call", async () => {
|
|
2357
|
+
const client = await Mock.makeClient();
|
|
2358
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2359
|
+
await client.NLWS.xtkSession.logon();
|
|
2360
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
2361
|
+
client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
|
|
2362
|
+
const scope = client.NLWS["xtkSession"];
|
|
2363
|
+
const fn = scope["getOption"];
|
|
2364
|
+
const result = await fn.call(scope, "XtkDatabaseId");
|
|
2365
|
+
expect(result).toMatchObject([ "uFE80000000000000F1FA913DD7CC7C480041161C", 6 ]);
|
|
2366
|
+
});
|
|
2367
|
+
|
|
2368
|
+
it("Should make static SOAP call with functional parameters", async () => {
|
|
2369
|
+
const client = await Mock.makeClient();
|
|
2370
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2371
|
+
await client.NLWS.xtkSession.logon();
|
|
2372
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
2373
|
+
const scope = client.NLWS["xtkSession"];
|
|
2374
|
+
const method = scope["staticP1"]; // SOAP method to call
|
|
2375
|
+
const paramsFn = jest.fn(); // function returning SOAP call parameters
|
|
2376
|
+
paramsFn.mockReturnValueOnce(["XtkDatabaseId"]);
|
|
2377
|
+
|
|
2378
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
2379
|
+
<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/'>
|
|
2380
|
+
<SOAP-ENV:Body>
|
|
2381
|
+
<StaticP1Response xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
2382
|
+
</StaticP1Response>
|
|
2383
|
+
</SOAP-ENV:Body>
|
|
2384
|
+
</SOAP-ENV:Envelope>`));
|
|
2385
|
+
|
|
2386
|
+
const result = await method.call(scope, paramsFn);
|
|
2387
|
+
expect(result).toBeNull();
|
|
2388
|
+
expect(paramsFn.mock.calls.length).toBe(1);
|
|
2389
|
+
// first parameter is the XML method
|
|
2390
|
+
const xmlMethod = paramsFn.mock.calls[0][0];
|
|
2391
|
+
expect(EntityAccessor.getAttributeAsString(xmlMethod, "name")).toBe("StaticP1");
|
|
2392
|
+
// second parameter is the call context
|
|
2393
|
+
expect(paramsFn.mock.calls[0][1]).toMatchObject({ schemaId: "xtk:session", namespace: "xtkSession" });
|
|
2394
|
+
});
|
|
2395
|
+
|
|
2396
|
+
it("Should make non static SOAP call with functional parameters", async () => {
|
|
2397
|
+
const client = await Mock.makeClient();
|
|
2398
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2399
|
+
await client.NLWS.xtkSession.logon();
|
|
2400
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
2401
|
+
const scope = client.NLWS["xtkSession"];
|
|
2402
|
+
const method = scope["nonStaticP1"]; // SOAP method to call
|
|
2403
|
+
const paramsFn = jest.fn(); // function returning SOAP call parameters
|
|
2404
|
+
paramsFn.mockReturnValueOnce(["XtkDatabaseId"]);
|
|
2405
|
+
|
|
2406
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
2407
|
+
<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/'>
|
|
2408
|
+
<SOAP-ENV:Body>
|
|
2409
|
+
<StaticP1Response xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
2410
|
+
</StaticP1Response>
|
|
2411
|
+
</SOAP-ENV:Body>
|
|
2412
|
+
</SOAP-ENV:Envelope>`));
|
|
2200
2413
|
|
|
2414
|
+
const object = scope.create({ dummy: true }); // "this" object for the non-static SOAP call
|
|
2415
|
+
const result = await method.call(object, paramsFn);
|
|
2416
|
+
expect(result).toBeNull();
|
|
2417
|
+
expect(paramsFn.mock.calls.length).toBe(1);
|
|
2418
|
+
// first parameter is the XML method
|
|
2419
|
+
const xmlMethod = paramsFn.mock.calls[0][0];
|
|
2420
|
+
expect(EntityAccessor.getAttributeAsString(xmlMethod, "name")).toBe("NonStaticP1");
|
|
2421
|
+
// second parameter is the call context
|
|
2422
|
+
expect(paramsFn.mock.calls[0][1]).toMatchObject({ schemaId: "xtk:session", namespace: "xtkSession" });
|
|
2423
|
+
});
|
|
2201
2424
|
});
|
|
2202
2425
|
});
|
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
|
});
|