ti2-tourplan 1.0.7 → 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.
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Error>
3
+ <Details>TourConnectException: 7001 Authentication error</Details>
4
+ </Error>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Reply>
3
+ <AuthenticationReply></AuthenticationReply>
4
+ </Reply>'
5
+
package/index.js CHANGED
@@ -33,6 +33,38 @@ class Plugin {
33
33
  });
34
34
  }
35
35
 
36
+ async validateToken({
37
+ token: {
38
+ endpoint,
39
+ username,
40
+ password,
41
+ },
42
+ }) {
43
+ try {
44
+ const model = {
45
+ AuthenticationRequest: {
46
+ Login: username,
47
+ Password: password,
48
+ },
49
+ };
50
+ let data = Normalizer.stripEnclosingQuotes(
51
+ js2xmlparser.parse('Request', model, xmlOptions),
52
+ );
53
+ data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
54
+ const reply = R.path(['data'], await axios({
55
+ metod: 'post',
56
+ url: endpoint,
57
+ data,
58
+ headers: getHeaders({ length: data.length }),
59
+ }));
60
+ const replyObj = await xmlParser.parseStringPromise(reply);
61
+ assert(R.path(['Reply', 'AuthenticationReply', 0], replyObj) === '');
62
+ return true;
63
+ } catch (err) {
64
+ return false;
65
+ }
66
+ }
67
+
36
68
  async queryAllotment({
37
69
  token: {
38
70
  endpoint = this.endpoint,
package/index.test.js CHANGED
@@ -39,6 +39,24 @@ describe('search tests', () => {
39
39
  password: process.env.ti2_tourplan_password,
40
40
  };
41
41
  const dateFormat = 'DD/MM/YYYY';
42
+ describe('tooling', () => {
43
+ describe('validateToken', () => {
44
+ it('valid token', async () => {
45
+ axios.mockImplementation(getFixture);
46
+ const retVal = await app.validateToken({
47
+ token,
48
+ });
49
+ expect(retVal).toBeTruthy();
50
+ });
51
+ it('invalid token', async () => {
52
+ axios.mockImplementation(getFixture);
53
+ const retVal = await app.validateToken({
54
+ token: { ...token, username: 'somerandom' },
55
+ });
56
+ expect(retVal).toBeFalsy();
57
+ });
58
+ });
59
+ });
42
60
  it('read allotment empty', async () => {
43
61
  const request = axios.mockImplementation(getFixture);
44
62
  const retVal = await app.queryAllotment({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {