fiftyone.pipeline.core 4.4.7 → 4.4.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/elementData.js +13 -12
- package/errorMessages.js +1 -1
- package/examples/examples.test.js +1 -1
- package/examples/flowElementsForExamples/async.js +1 -1
- package/examples/flowElementsForExamples/sync.js +1 -1
- package/flowData.js +4 -6
- package/flowElement.js +3 -2
- package/helpers.js +18 -16
- package/javascriptbuilder.js +7 -7
- package/jsonbundler.js +3 -4
- package/package.json +11 -11
- package/pipeline.js +8 -7
- package/pipelineBuilder.js +3 -3
- package/setHeadersElement.js +145 -142
- package/tests/core.test.js +23 -23
- package/tests/coreTestSetup.js +4 -4
- package/tests/elementData.test.js +3 -3
- package/tests/javascriptbuilder.test.js +4 -4
- package/tests/jsoutput.js +202 -202
- package/tests/logs-errors-and-stops.test.js +1 -1
- package/tests/setHeadersElement.test.js +65 -68
- /package/{.eslintrc.json → .eslintrc} +0 -0
package/tests/jsoutput.js
CHANGED
|
@@ -20,218 +20,218 @@
|
|
|
20
20
|
* such notice(s) shall fulfill the requirements of that article.
|
|
21
21
|
* ********************************************************************* */
|
|
22
22
|
|
|
23
|
-
fiftyoneDegreesManager = function() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
fiftyoneDegreesManager = function () { // eslint-disable-line
|
|
24
|
+
'use-strict';
|
|
25
|
+
const json = { nullValueReasons: { 'testengine.four': 'This property is not available' }, javascriptProperties: ['testengine.three'], testengine: { one: 1, two: 2, three: "console.log('ok')", four: null } };
|
|
26
|
+
|
|
27
|
+
// Log any errors returned in the JSON object.
|
|
28
|
+
if (json.error !== undefined) {
|
|
29
|
+
console.log(json.error);
|
|
30
|
+
}
|
|
31
|
+
// Set to true when the JSON object is complete.
|
|
32
|
+
const completed = false;
|
|
33
|
+
|
|
34
|
+
// changeFuncs is an array of functions. When onChange is called and passed
|
|
35
|
+
// a function, the function is registered and is called when processing is
|
|
36
|
+
// complete.
|
|
37
|
+
const changeFuncs = [];
|
|
38
|
+
|
|
39
|
+
// Counter is used to count how many pieces of callbacks are expected. Every
|
|
40
|
+
// time the completedCallback method is called, the counter is decremented
|
|
41
|
+
// by 1. The counter's initial value is 1 as the method is always called
|
|
42
|
+
// once to continue execution.
|
|
43
|
+
let callbackCounter = 1;
|
|
44
|
+
|
|
45
|
+
// startsWith polyfill.
|
|
46
|
+
const startsWith = function (source, searchValue) {
|
|
47
|
+
return source.lastIndexOf(searchValue, 0) === 0;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Get cookies with the '51D_' prefix that have been added to the request
|
|
51
|
+
// and return the data as key value pairs. This method is needed to extract
|
|
52
|
+
// cookie values for inclusion in the GET or POST request for situations
|
|
53
|
+
// where CORS will prevent cookies being sent to third parties.
|
|
54
|
+
const getFodCookies = function () {
|
|
55
|
+
const keyValuePairs = document.cookie.split(/; */);
|
|
56
|
+
const fodCookies = [];
|
|
57
|
+
for (let i = 0; i < keyValuePairs.length; i++) {
|
|
58
|
+
const name = keyValuePairs[i].substring(0, keyValuePairs[i].indexOf('='));
|
|
59
|
+
if (startsWith(name, '51D_')) {
|
|
60
|
+
const value = keyValuePairs[i].substring(keyValuePairs[i].indexOf('=') + 1);
|
|
61
|
+
fodCookies[name] = value;
|
|
62
|
+
}
|
|
30
63
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var callbackCounter = 1;
|
|
44
|
-
|
|
45
|
-
// startsWith polyfill.
|
|
46
|
-
var startsWith = function(source, searchValue){
|
|
47
|
-
return source.lastIndexOf(searchValue, 0) === 0;
|
|
64
|
+
return fodCookies;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Extract key value pairs from the '51D_' prefixed cookies and concatenates
|
|
68
|
+
// them to form a query string for the subsequent json refresh.
|
|
69
|
+
const getParametersFromCookies = function () { // eslint-disable-line
|
|
70
|
+
const fodCookies = getFodCookies();
|
|
71
|
+
const keyValuePairs = [];
|
|
72
|
+
for (const key in fodCookies) {
|
|
73
|
+
if (fodCookies.hasOwnProperty(key)) {
|
|
74
|
+
keyValuePairs.push(key + '=' + fodCookies[key]);
|
|
75
|
+
}
|
|
48
76
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return keyValuePairs;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// Delete a cookie.
|
|
81
|
-
function deleteCookie(name) {
|
|
82
|
-
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
77
|
+
return keyValuePairs;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Delete a cookie.
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param name
|
|
84
|
+
*/
|
|
85
|
+
function deleteCookie (name) { // eslint-disable-line
|
|
86
|
+
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Fetch a value safely from the json object. If a key somewhere down the
|
|
90
|
+
// '.' separated hierarchy of keys is not present then 'undefined' is
|
|
91
|
+
// returned rather than letting an exception occur.
|
|
92
|
+
const getFromJson = function (key) {
|
|
93
|
+
let result;
|
|
94
|
+
if (typeof (key) === 'string') {
|
|
95
|
+
let functions = json;
|
|
96
|
+
const segments = key.split('.');
|
|
97
|
+
let i = 0;
|
|
98
|
+
while (functions !== undefined && i < segments.length) {
|
|
99
|
+
functions = functions[segments[i++]];
|
|
100
|
+
}
|
|
101
|
+
if (typeof (functions) === 'string') {
|
|
102
|
+
result = functions;
|
|
103
|
+
}
|
|
83
104
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
functions = functions[segments[i++]];
|
|
96
|
-
}
|
|
97
|
-
if (typeof(functions) === "string") {
|
|
98
|
-
result = functions;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Executed at the end of the processJSproperties method or for each piece
|
|
105
|
-
// of JavaScript which has 51D code injected. When there are 0 pieces of
|
|
106
|
-
// JavaScript left to process then reload the JSON object.
|
|
107
|
-
var completedCallback = function(resolve, reject){
|
|
108
|
-
callbackCounter--;
|
|
109
|
-
if (callbackCounter === 0){
|
|
110
|
-
} else if (callbackCounter < 0){
|
|
111
|
-
reject('Too many callbacks.');
|
|
112
|
-
}
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Executed at the end of the processJSproperties method or for each piece
|
|
109
|
+
// of JavaScript which has 51D code injected. When there are 0 pieces of
|
|
110
|
+
// JavaScript left to process then reload the JSON object.
|
|
111
|
+
const completedCallback = function (resolve, reject) {
|
|
112
|
+
callbackCounter--;
|
|
113
|
+
if (callbackCounter === 0) {
|
|
114
|
+
} else if (callbackCounter < 0) {
|
|
115
|
+
reject('Too many callbacks.');
|
|
113
116
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
func();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Executes any Javascript contained in the json data. Sets the processedJs
|
|
120
|
+
// flag to true when there is no further Javascript to be processed.
|
|
121
|
+
const processJSproperties = function (resolve, reject) {
|
|
122
|
+
if (json.javascriptProperties !== undefined) {
|
|
123
|
+
if (json.javascriptProperties.length > 0) {
|
|
124
|
+
// Execute each of the Javascript property code snippets using the
|
|
125
|
+
// index of the value to access the value to avoid problems with
|
|
126
|
+
// JavaScript returning erroneous values.
|
|
127
|
+
for (let index = 0;
|
|
128
|
+
index < json.javascriptProperties.length;
|
|
129
|
+
index++) {
|
|
130
|
+
const name = json.javascriptProperties[index];
|
|
131
|
+
|
|
132
|
+
// Create new function bound to this instance and execute it.
|
|
133
|
+
// This is needed to ensure the scope of the function is
|
|
134
|
+
// associated with this instance if any members are altered or
|
|
135
|
+
// added. Avoids global scoped variables.
|
|
136
|
+
let body = getFromJson(name);
|
|
137
|
+
|
|
138
|
+
if (body !== undefined) {
|
|
139
|
+
let func;
|
|
140
|
+
const searchString = '// 51D replace this comment with callback function.';
|
|
141
|
+
|
|
142
|
+
if (body.indexOf(searchString) !== -1) {
|
|
143
|
+
callbackCounter++;
|
|
144
|
+
body = body.replace(/\/\/ 51D replace this comment with callback function./g, 'callbackFunc(resolveFunc, rejectFunc);');
|
|
145
|
+
func = new Function('callbackFunc', 'resolveFunc', 'rejectFunc',// eslint-disable-line
|
|
146
|
+
'try {\n' +
|
|
147
|
+
body + '\n' +
|
|
148
|
+
'} catch (err) {\n' +
|
|
149
|
+
'console.log(err);' +
|
|
150
|
+
'}'
|
|
151
|
+
);
|
|
152
|
+
func(completedCallback, resolve, reject);
|
|
153
|
+
} else {
|
|
154
|
+
func = new Function( // eslint-disable-line
|
|
155
|
+
'try {\n' +
|
|
156
|
+
body + '\n' +
|
|
157
|
+
'} catch (err) {\n' +
|
|
158
|
+
'console.log(err);' +
|
|
159
|
+
'}'
|
|
160
|
+
);
|
|
161
|
+
func();
|
|
163
162
|
}
|
|
163
|
+
}
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// Check if the JSON object still has any JavaScript snippets to run.
|
|
170
|
-
var hasJSFunctions = function() {
|
|
171
|
-
for (var i = i; i < json.javascriptProperties; i++) {
|
|
172
|
-
var body = getFromJson(json.javascriptProperties[i]);
|
|
173
|
-
if (body !== undefined && body.length > 0) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return false;
|
|
165
|
+
}
|
|
178
166
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
167
|
+
completedCallback(resolve, reject);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Check if the JSON object still has any JavaScript snippets to run.
|
|
171
|
+
const hasJSFunctions = function () { // eslint-disable-line
|
|
172
|
+
// TODO: Fix i = i
|
|
173
|
+
for (var i = i; i < json.javascriptProperties; i++) { // eslint-disable-line
|
|
174
|
+
const body = getFromJson(json.javascriptProperties[i]);
|
|
175
|
+
if (body !== undefined && body.length > 0) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
183
178
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
179
|
+
return false;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// Process the JavaScript properties.
|
|
183
|
+
const process = function (resolve, reject) {
|
|
184
|
+
processJSproperties(resolve, reject);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Function logs errors, used to 'reject' a promise or for error callbacks.
|
|
188
|
+
const catchError = function (value) {
|
|
189
|
+
console.log(value.message || value);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// Populate this instance of the FOD object with getters to access the
|
|
193
|
+
// properties. If the value is null then get the noValueMessage from the
|
|
194
|
+
// JSON object corresponding to the property.
|
|
195
|
+
const update = function (data) {
|
|
196
|
+
const self = this;
|
|
197
|
+
Object.getOwnPropertyNames(data).forEach(function (key) {
|
|
198
|
+
self[key] = {};
|
|
199
|
+
for (const i in data[key]) {
|
|
200
|
+
var obj = self[key];
|
|
201
|
+
(function (i) {
|
|
202
|
+
Object.defineProperty(obj, i, {
|
|
203
|
+
get: function () {
|
|
204
|
+
if (data[key][i] === null && (i !== 'javascriptProperties' || i !== 'nullValueReasons')) {
|
|
205
|
+
return data.nullValueReasons[key + '.' + i];
|
|
206
|
+
} else {
|
|
207
|
+
return data[key][i];
|
|
208
|
+
}
|
|
211
209
|
}
|
|
212
|
-
|
|
210
|
+
});
|
|
211
|
+
})(i);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
this.onChange = function (resolve) {
|
|
217
|
+
changeFuncs.push(resolve);
|
|
218
|
+
if (started === false) { // eslint-disable-line
|
|
219
|
+
process(resolve, catchError);
|
|
220
|
+
started = true; // eslint-disable-line
|
|
213
221
|
}
|
|
222
|
+
};
|
|
214
223
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.complete = function(resolve) {
|
|
224
|
-
if(completed){
|
|
225
|
-
resolve(this);
|
|
226
|
-
}else{
|
|
227
|
-
var parent = this;
|
|
228
|
-
process(resolve, catchError);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
224
|
+
this.complete = function (resolve) {
|
|
225
|
+
if (completed) {
|
|
226
|
+
resolve(this);
|
|
227
|
+
} else {
|
|
228
|
+
process(resolve, catchError);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
232
|
+
// Update this instance with the initial JSON payload.
|
|
233
|
+
update.call(this, json);
|
|
234
|
+
this.complete(json);
|
|
235
|
+
};
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
const fod = new fiftyoneDegreesManager(); // eslint-disable-line
|
|
@@ -74,7 +74,7 @@ test('stop flag works', done => {
|
|
|
74
74
|
syncFlowData.get('neverRun');
|
|
75
75
|
} catch (e) {
|
|
76
76
|
expect(e.indexOf(util.format(errorMessages.noElementData,
|
|
77
|
-
'neverRun','async, sync')) !== -1).toBe(true);
|
|
77
|
+
'neverRun', 'async, sync')) !== -1).toBe(true);
|
|
78
78
|
}
|
|
79
79
|
done();
|
|
80
80
|
});
|
|
@@ -25,29 +25,28 @@ const PipelineBuilder = require('../pipelineBuilder');
|
|
|
25
25
|
const Helpers = require('../helpers');
|
|
26
26
|
const each = require('jest-each').default;
|
|
27
27
|
const AspectPropertyValue = require('../aspectPropertyValue');
|
|
28
|
-
const
|
|
29
|
-
var httpMocks = require('node-mocks-http');
|
|
28
|
+
const httpMocks = require('node-mocks-http');
|
|
30
29
|
|
|
31
|
-
const unknownValue = new AspectPropertyValue(null, 'Unknown')
|
|
32
|
-
const testValue = new AspectPropertyValue(null, 'test')
|
|
33
|
-
const browserValue = new AspectPropertyValue(null, 'SEC-CH-UA,SEC-CH-UA-Full-Version')
|
|
34
|
-
const platformValue = new AspectPropertyValue(null, 'SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version')
|
|
35
|
-
const hardwareValue = new AspectPropertyValue(null, 'SEC-CH-UA-Model,SEC-CH-UA-Mobile,SEC-CH-UA-Arch')
|
|
36
|
-
// Value which contains at least one duplicate value from each of other SetHeader values.
|
|
37
|
-
const duplicateValue = new AspectPropertyValue(null, 'SEC-CH-UA,SEC-CH-UA-Platform,SEC-CH-UA-Model')
|
|
30
|
+
const unknownValue = new AspectPropertyValue(null, 'Unknown');
|
|
31
|
+
const testValue = new AspectPropertyValue(null, 'test');
|
|
32
|
+
const browserValue = new AspectPropertyValue(null, 'SEC-CH-UA,SEC-CH-UA-Full-Version');
|
|
33
|
+
const platformValue = new AspectPropertyValue(null, 'SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version');
|
|
34
|
+
const hardwareValue = new AspectPropertyValue(null, 'SEC-CH-UA-Model,SEC-CH-UA-Mobile,SEC-CH-UA-Arch');
|
|
35
|
+
// Value which contains at least one duplicate value from each of other SetHeader values.
|
|
36
|
+
const duplicateValue = new AspectPropertyValue(null, 'SEC-CH-UA,SEC-CH-UA-Platform,SEC-CH-UA-Model');
|
|
38
37
|
|
|
39
38
|
// Set up the properties in the element.
|
|
40
|
-
setup.device.properties[
|
|
41
|
-
name:
|
|
39
|
+
setup.device.properties['SetHeaderBrowserAccept-CH'] = {
|
|
40
|
+
name: 'SetHeaderBrowserAccept-CH'
|
|
42
41
|
};
|
|
43
|
-
setup.device.properties[
|
|
44
|
-
name:
|
|
42
|
+
setup.device.properties['SetHeaderPlatformAccept-CH'] = {
|
|
43
|
+
name: 'SetHeaderPlatformAccept-CH'
|
|
45
44
|
};
|
|
46
|
-
setup.device.properties[
|
|
47
|
-
name:
|
|
45
|
+
setup.device.properties['SetHeaderHardwareAccept-CH'] = {
|
|
46
|
+
name: 'SetHeaderHardwareAccept-CH'
|
|
48
47
|
};
|
|
49
|
-
setup.device.properties
|
|
50
|
-
name:
|
|
48
|
+
setup.device.properties.SetHeaderHardwareSomeOtherHeader = {
|
|
49
|
+
name: 'SetHeaderHardwareSomeOtherHeader'
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
const pipeline = new PipelineBuilder()
|
|
@@ -56,68 +55,66 @@ const pipeline = new PipelineBuilder()
|
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* Test response header value to be set for UACH
|
|
59
|
-
*
|
|
58
|
+
*
|
|
60
59
|
*/
|
|
61
60
|
each([
|
|
62
|
-
[
|
|
63
|
-
{
|
|
64
|
-
{
|
|
65
|
-
[
|
|
66
|
-
{
|
|
67
|
-
{
|
|
68
|
-
[
|
|
69
|
-
{
|
|
70
|
-
{
|
|
71
|
-
[
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
[
|
|
75
|
-
{
|
|
76
|
-
{
|
|
77
|
-
[
|
|
78
|
-
{
|
|
79
|
-
{
|
|
80
|
-
[
|
|
81
|
-
{
|
|
82
|
-
{
|
|
83
|
-
[
|
|
84
|
-
{
|
|
85
|
-
{
|
|
86
|
-
[
|
|
87
|
-
{
|
|
88
|
-
{
|
|
61
|
+
['Ignore all unknown values.',
|
|
62
|
+
{ 'SetHeaderBrowserAccept-CH': unknownValue, 'SetHeaderPlatformAccept-CH': unknownValue, 'SetHeaderHardwareAccept-CH': unknownValue },
|
|
63
|
+
{ 'Accept-CH': 'nil' }],
|
|
64
|
+
['Ignore unknown values.',
|
|
65
|
+
{ 'SetHeaderBrowserAccept-CH': unknownValue, 'SetHeaderPlatformAccept-CH': unknownValue, 'SetHeaderHardwareAccept-CH': testValue },
|
|
66
|
+
{ 'Accept-CH': 'test' }],
|
|
67
|
+
['Single property, single header.',
|
|
68
|
+
{ 'SetHeaderBrowserAccept-CH': browserValue },
|
|
69
|
+
{ 'Accept-CH': 'SEC-CH-UA,SEC-CH-UA-Full-Version' }],
|
|
70
|
+
['Two properties, single header.',
|
|
71
|
+
{ 'SetHeaderPlatformAccept-CH': platformValue, 'SetHeaderHardwareAccept-CH': hardwareValue },
|
|
72
|
+
{ 'Accept-CH': 'SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version,SEC-CH-UA-Model,SEC-CH-UA-Mobile,SEC-CH-UA-Arch' }],
|
|
73
|
+
['Multiple properties, single header.',
|
|
74
|
+
{ 'SetHeaderBrowserAccept-CH': browserValue, 'SetHeaderPlatformAccept-CH': platformValue, 'SetHeaderHardwareAccept-CH': hardwareValue },
|
|
75
|
+
{ 'Accept-CH': 'SEC-CH-UA,SEC-CH-UA-Full-Version,SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version,SEC-CH-UA-Model,SEC-CH-UA-Mobile,SEC-CH-UA-Arch' }],
|
|
76
|
+
['String value (not aspectproperty).',
|
|
77
|
+
{ 'SetHeaderBrowserAccept-CH': browserValue.value },
|
|
78
|
+
{ 'Accept-CH': browserValue.value }],
|
|
79
|
+
['Undefined value.',
|
|
80
|
+
{ 'SetHeaderBrowserAccept-CH': undefined },
|
|
81
|
+
{ 'Accept-CH': 'nil' }],
|
|
82
|
+
['Set multiple headers.',
|
|
83
|
+
{ 'SetHeaderBrowserAccept-CH': browserValue, SetHeaderHardwareSomeOtherHeader: platformValue },
|
|
84
|
+
{ 'Accept-CH': browserValue.value, SomeOtherHeader: platformValue.value }],
|
|
85
|
+
['Properties with duplicate values.',
|
|
86
|
+
{ 'SetHeaderPlatformAccept-CH': platformValue, 'SetHeaderHardwareAccept-CH': duplicateValue },
|
|
87
|
+
{ 'Accept-CH': 'SEC-CH-UA-Platform,SEC-CH-UA-Platform-Version,SEC-CH-UA,SEC-CH-UA-Model' }]
|
|
89
88
|
])
|
|
90
|
-
.test('testGetResponseHeaderValue - %s', async (name, device, expectedHeaders) => {
|
|
89
|
+
.test('testGetResponseHeaderValue - %s', async (name, device, expectedHeaders) => {
|
|
91
90
|
// Set up a mock repsonse object to collect the headers which are
|
|
92
91
|
// added to it.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
const response = httpMocks.createResponse();
|
|
93
|
+
setup.device.additionalValues = device;
|
|
94
|
+
const flowData = pipeline.createFlowData();
|
|
95
|
+
const result = await flowData.process();
|
|
96
|
+
// Call the method.
|
|
97
|
+
Helpers.setResponseHeaders(response, result);
|
|
98
|
+
// Check the correct headers were added to the response.
|
|
99
|
+
for (const [key, value] of Object.entries(expectedHeaders)) {
|
|
100
|
+
if (value === 'nil') {
|
|
101
|
+
expect(response.getHeader('Accept-CH')).toBe(undefined);
|
|
102
|
+
} else {
|
|
103
|
+
expect(response.getHeader(key)).toBe(value);
|
|
104
|
+
}
|
|
106
105
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
});
|
|
106
|
+
});
|
|
110
107
|
|
|
111
108
|
test('testGetResponseHeaderValue - append to existing header', async () => {
|
|
112
109
|
// Set up a mock repsonse object to collect the headers which are
|
|
113
110
|
// added to it.
|
|
114
|
-
|
|
115
|
-
response.setHeader(
|
|
116
|
-
setup.device.additionalValues = {
|
|
111
|
+
const response = httpMocks.createResponse();
|
|
112
|
+
response.setHeader('Accept-CH', 'existing');
|
|
113
|
+
setup.device.additionalValues = { 'SetHeaderBrowserAccept-CH': browserValue };
|
|
117
114
|
const flowData = pipeline.createFlowData();
|
|
118
|
-
|
|
115
|
+
const result = await flowData.process();
|
|
119
116
|
// Call the method.
|
|
120
117
|
Helpers.setResponseHeaders(response, result);
|
|
121
118
|
// Check the correct headers were added to the response.
|
|
122
|
-
expect(response.getHeader(
|
|
123
|
-
});
|
|
119
|
+
expect(response.getHeader('Accept-CH')).toBe(`existing,${browserValue.value}`);
|
|
120
|
+
});
|
|
File without changes
|