ti2-tourplan 1.0.7 → 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/index.js
CHANGED
|
@@ -31,6 +31,57 @@ class Plugin {
|
|
|
31
31
|
Object.entries(params).forEach(([attr, value]) => {
|
|
32
32
|
this[attr] = value;
|
|
33
33
|
});
|
|
34
|
+
this.tokenTemplate = () => ({
|
|
35
|
+
endpoint: {
|
|
36
|
+
type: 'text',
|
|
37
|
+
regExp: /^(?!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,
|
|
38
|
+
description: 'The uri for the tourplan adapter',
|
|
39
|
+
},
|
|
40
|
+
username: {
|
|
41
|
+
type: 'text',
|
|
42
|
+
regExp: /.+/,
|
|
43
|
+
description: 'The tourplan provided username',
|
|
44
|
+
default: 'en',
|
|
45
|
+
},
|
|
46
|
+
password: {
|
|
47
|
+
type: 'text',
|
|
48
|
+
regExp: /.+/,
|
|
49
|
+
description: 'The tourplan provided password',
|
|
50
|
+
default: 'en',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async validateToken({
|
|
56
|
+
token: {
|
|
57
|
+
endpoint,
|
|
58
|
+
username,
|
|
59
|
+
password,
|
|
60
|
+
},
|
|
61
|
+
}) {
|
|
62
|
+
try {
|
|
63
|
+
const model = {
|
|
64
|
+
AuthenticationRequest: {
|
|
65
|
+
Login: username,
|
|
66
|
+
Password: password,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
let data = Normalizer.stripEnclosingQuotes(
|
|
70
|
+
js2xmlparser.parse('Request', model, xmlOptions),
|
|
71
|
+
);
|
|
72
|
+
data = data.replace(xmlOptions.dtd.name, `Request SYSTEM "${xmlOptions.dtd.name}"`);
|
|
73
|
+
const reply = R.path(['data'], await axios({
|
|
74
|
+
metod: 'post',
|
|
75
|
+
url: endpoint,
|
|
76
|
+
data,
|
|
77
|
+
headers: getHeaders({ length: data.length }),
|
|
78
|
+
}));
|
|
79
|
+
const replyObj = await xmlParser.parseStringPromise(reply);
|
|
80
|
+
assert(R.path(['Reply', 'AuthenticationReply', 0], replyObj) === '');
|
|
81
|
+
return true;
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
34
85
|
}
|
|
35
86
|
|
|
36
87
|
async queryAllotment({
|
package/index.test.js
CHANGED
|
@@ -39,6 +39,49 @@ 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
|
+
describe('template tests', () => {
|
|
60
|
+
let template;
|
|
61
|
+
it('get the template', async () => {
|
|
62
|
+
template = await app.tokenTemplate();
|
|
63
|
+
const rules = Object.keys(template);
|
|
64
|
+
expect(rules).toContain('endpoint');
|
|
65
|
+
expect(rules).toContain('password');
|
|
66
|
+
expect(rules).toContain('username');
|
|
67
|
+
});
|
|
68
|
+
it('username', () => {
|
|
69
|
+
const username = template.username.regExp;
|
|
70
|
+
expect(username.test('')).toBeFalsy();
|
|
71
|
+
expect(username.test('someuser')).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
it('endpoint', () => {
|
|
74
|
+
const endpoint = template.endpoint.regExp;
|
|
75
|
+
expect(endpoint.test('something')).toBeFalsy();
|
|
76
|
+
expect(endpoint.test('https://www.google.com')).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
it('password', () => {
|
|
79
|
+
const password = template.password.regExp;
|
|
80
|
+
expect(password.test('')).toBeFalsy();
|
|
81
|
+
expect(password.test('somepassword')).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
42
85
|
it('read allotment empty', async () => {
|
|
43
86
|
const request = axios.mockImplementation(getFixture);
|
|
44
87
|
const retVal = await app.queryAllotment({
|