ti2-tourplan 1.0.142 → 1.0.143
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/.claude/settings.local.json +10 -0
- package/index.js +8 -6
- package/package.json +1 -1
- package/request-headers.test.js +91 -0
package/index.js
CHANGED
|
@@ -28,10 +28,12 @@ const defaultXmlOptions = {
|
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
const urlRegExp = /^(?!mailto:)(?:(?:http|https|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:(\/|\?|#)[^\s]*)?$/i;
|
|
31
|
-
|
|
31
|
+
// Content-Length counts bytes. String length undercounts multibyte UTF-8
|
|
32
|
+
// characters, and Tourplan then parses a truncated document (TC-2059).
|
|
33
|
+
const getHeaders = xmlPayload => ({
|
|
32
34
|
Accept: 'application/xml',
|
|
33
35
|
'Content-Type': 'application/xml; charset=utf-8',
|
|
34
|
-
'Content-Length':
|
|
36
|
+
'Content-Length': Buffer.byteLength(xmlPayload, 'utf8'),
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -250,7 +252,7 @@ class BuyerPlugin {
|
|
|
250
252
|
method: 'post',
|
|
251
253
|
url: endpoint,
|
|
252
254
|
data: testData,
|
|
253
|
-
headers: getHeaders(
|
|
255
|
+
headers: getHeaders(testData),
|
|
254
256
|
});
|
|
255
257
|
|
|
256
258
|
// The API returns 200 even for DTD errors, so check the response content
|
|
@@ -350,7 +352,7 @@ class BuyerPlugin {
|
|
|
350
352
|
// data: {
|
|
351
353
|
// url: endpoint,
|
|
352
354
|
// data,
|
|
353
|
-
// headers: getHeaders(
|
|
355
|
+
// headers: getHeaders(data),
|
|
354
356
|
// },
|
|
355
357
|
// }));
|
|
356
358
|
// } catch (err) {
|
|
@@ -365,7 +367,7 @@ class BuyerPlugin {
|
|
|
365
367
|
method: 'post',
|
|
366
368
|
url: endpoint,
|
|
367
369
|
data,
|
|
368
|
-
headers: getHeaders(
|
|
370
|
+
headers: getHeaders(data),
|
|
369
371
|
};
|
|
370
372
|
const reply = R.path(['data'], await axios(axiospayload));
|
|
371
373
|
if (this.xmlProxyUrl) {
|
|
@@ -538,7 +540,7 @@ class BuyerPlugin {
|
|
|
538
540
|
method: 'post',
|
|
539
541
|
url: endpoint,
|
|
540
542
|
data: requestData,
|
|
541
|
-
headers: getHeaders(
|
|
543
|
+
headers: getHeaders(requestData),
|
|
542
544
|
}));
|
|
543
545
|
if (verbose) console.log('reply', cleanLog(reply));
|
|
544
546
|
const returnObj = await xmlParser.parseStringPromise(reply);
|
package/package.json
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* globals describe, it, expect, jest */
|
|
2
|
+
|
|
3
|
+
const http = require('http');
|
|
4
|
+
const realAxios = require('axios');
|
|
5
|
+
const { XMLValidator } = require('fast-xml-parser');
|
|
6
|
+
const Plugin = require('./index');
|
|
7
|
+
const { escapeInvalidXmlChars, hostConnectXmlOptions } = require('./utils');
|
|
8
|
+
|
|
9
|
+
const okReply = '<?xml version="1.0"?><Reply><AddServiceReply><BookingId>1</BookingId></AddServiceReply></Reply>';
|
|
10
|
+
|
|
11
|
+
const makeAxios = (reply = okReply) => {
|
|
12
|
+
const calls = [];
|
|
13
|
+
const axios = jest.fn(async config => {
|
|
14
|
+
calls.push(config);
|
|
15
|
+
return { data: reply };
|
|
16
|
+
});
|
|
17
|
+
return { axios, calls };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const expectUtf8ContentLength = config => {
|
|
21
|
+
expect(config.headers['Content-Length']).toBe(Buffer.byteLength(config.data, 'utf8'));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('Tourplan request Content-Length', () => {
|
|
25
|
+
const endpoint = 'https://test.example.com';
|
|
26
|
+
const xmlOptions = { prettyPrinting: { enabled: false }, dtd: { include: true, name: 'tourConnect_4_00_000.dtd' } };
|
|
27
|
+
|
|
28
|
+
it.each([
|
|
29
|
+
['ASCII', 'Pickup 07:30 - meet driver in the lobby'],
|
|
30
|
+
['em dash', 'Pickup 07:30 — meet driver in the lobby'],
|
|
31
|
+
['accented letters', 'Café Zürich, señor'],
|
|
32
|
+
['euro sign', 'Deposit €50 paid'],
|
|
33
|
+
['arrow', 'Sydney → Cairns'],
|
|
34
|
+
['CJK', '日本のお客様'],
|
|
35
|
+
])('callTourplan declares the UTF-8 byte length for %s remarks', async (_label, notes) => {
|
|
36
|
+
const app = new Plugin();
|
|
37
|
+
const { axios, calls } = makeAxios();
|
|
38
|
+
await app.callTourplan({
|
|
39
|
+
endpoint,
|
|
40
|
+
axios,
|
|
41
|
+
xmlOptions,
|
|
42
|
+
model: { AddServiceRequest: { Opt: 'SYDACSYDHOTSTD', Remarks: notes } },
|
|
43
|
+
});
|
|
44
|
+
const addService = calls.find(c => c.data.includes('AddServiceRequest'));
|
|
45
|
+
const dtdDetection = calls.find(c => c.data.includes('AuthenticationRequest'));
|
|
46
|
+
expectUtf8ContentLength(addService);
|
|
47
|
+
// The DTD probe body is ASCII; this only checks it uses the same header helper.
|
|
48
|
+
expectUtf8ContentLength(dtdDetection);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('queryAllotment declares the UTF-8 byte length', async () => {
|
|
52
|
+
const app = new Plugin();
|
|
53
|
+
const { axios, calls } = makeAxios('<Reply><GetInventoryReply></GetInventoryReply></Reply>');
|
|
54
|
+
await app.queryAllotment({
|
|
55
|
+
axios,
|
|
56
|
+
token: { endpoint, username: 'agent—ops', password: 'pw' },
|
|
57
|
+
payload: { startDate: '01/08/2022', endDate: '15/08/2022', keyPath: 'MAGLUX|SYDACMAGLUXDELXRO' },
|
|
58
|
+
});
|
|
59
|
+
const inventory = calls.find(c => c.data.includes('GetInventoryRequest'));
|
|
60
|
+
expect(Buffer.byteLength(inventory.data, 'utf8')).toBeGreaterThan(inventory.data.length);
|
|
61
|
+
expectUtf8ContentLength(inventory);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Node's HTTP parser, like Tourplan, reads exactly Content-Length bytes of the body.
|
|
65
|
+
it('sends a complete HostConnect AddServiceRequest with an em dash over HTTP', async () => {
|
|
66
|
+
const received = [];
|
|
67
|
+
const server = http.createServer((req, res) => {
|
|
68
|
+
const chunks = [];
|
|
69
|
+
req.on('data', chunk => chunks.push(chunk));
|
|
70
|
+
req.on('end', () => {
|
|
71
|
+
received.push(Buffer.concat(chunks).toString('utf8'));
|
|
72
|
+
res.setHeader('Content-Type', 'application/xml');
|
|
73
|
+
res.end(okReply);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
await new Promise(resolve => { server.listen(0, '127.0.0.1', resolve); });
|
|
77
|
+
try {
|
|
78
|
+
await new Plugin().callTourplan({
|
|
79
|
+
endpoint: `http://127.0.0.1:${server.address().port}/`,
|
|
80
|
+
axios: realAxios,
|
|
81
|
+
xmlOptions: hostConnectXmlOptions,
|
|
82
|
+
model: { AddServiceRequest: { Opt: 'SYDACSYDHOTSTD', Remarks: escapeInvalidXmlChars('Pickup 07:30 \u2014 meet driver') } },
|
|
83
|
+
});
|
|
84
|
+
} finally {
|
|
85
|
+
server.close();
|
|
86
|
+
}
|
|
87
|
+
expect(received).toHaveLength(1);
|
|
88
|
+
expect(received[0].endsWith('</Request>')).toBe(true);
|
|
89
|
+
expect(XMLValidator.validate(received[0])).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|