Skip to content

Commit 7c5a814

Browse files
left track properties and evaluation options validations more permisive
1 parent aac1303 commit 7c5a814

11 files changed

Lines changed: 121 additions & 217 deletions

client/__tests__/allTreatments.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -260,29 +260,6 @@ describe('get-all-treatments', () => {
260260
expectOkAllTreatments(response, 200, expected, 2);
261261
});
262262

263-
test('should be 400 if options.properties is invalid (GET)', async () => {
264-
const expected = [
265-
'options.properties must only contain boolean, string, or number values.'
266-
];
267-
const response = await request(app)
268-
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"invalid":[1,2,3]}}')
269-
.set('Authorization', 'test');
270-
expectErrorContaining(response, 400, expected);
271-
});
272-
273-
test('should be 400 if options.properties is invalid (POST)', async () => {
274-
const expected = [
275-
'options.properties must only contain boolean, string, or number values.'
276-
];
277-
const response = await request(app)
278-
.post('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
279-
.send({
280-
options: { properties: { invalid: [1, 2, 3] } },
281-
})
282-
.set('Authorization', 'test');
283-
expectErrorContaining(response, 400, expected);
284-
});
285-
286263
test('should be 200 if options.properties is valid (GET)', async () => {
287264
const response = await request(app)
288265
.get('/client/get-all-treatments?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/allTreatmentsWithConfig.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,6 @@ describe('get-all-treatments-with-config', () => {
268268
expectOkAllTreatments(response, 200, expected, 2);
269269
});
270270

271-
test('should be 400 if options.properties is invalid (GET)', async () => {
272-
const expected = [
273-
'options.properties must only contain boolean, string, or number values.'
274-
];
275-
const response = await request(app)
276-
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"invalid":[1,2,3]}}')
277-
.set('Authorization', 'test');
278-
expectErrorContaining(response, 400, expected);
279-
});
280-
281-
test('should be 400 if options.properties is invalid (POST)', async () => {
282-
const expected = [
283-
'options.properties must only contain boolean, string, or number values.'
284-
];
285-
const response = await request(app)
286-
.post('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]')
287-
.send({
288-
options: { properties: { invalid: [1, 2, 3] } },
289-
})
290-
.set('Authorization', 'test');
291-
expectErrorContaining(response, 400, expected);
292-
});
293-
294271
test('should be 200 if options.properties is valid (GET)', async () => {
295272
const response = await request(app)
296273
.get('/client/get-all-treatments-with-config?keys=[{"matchingKey":"test","trafficType":"localhost"}]&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/track.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('track', () => {
145145

146146
test('should be 400 if properties is invalid', async () => {
147147
const expected = [
148-
'Input must be a plain object.'
148+
'properties must be a plain object.'
149149
];
150150
const response = await request(app)
151151
.get('/client/track?key=my-key&event-type=my-event&traffic-type=my-traffic&value=1&properties=lalala')
@@ -158,7 +158,7 @@ describe('track', () => {
158158
'key too long, key must be 250 characters or less.',
159159
'you passed "@!test", event-type must adhere to the regular expression /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/g. This means an event_type must be alphanumeric, cannot be more than 80 characters long, and can only include a dash, underscore, period, or colon as separators of alphanumeric characters.',
160160
'you passed an empty traffic-type, traffic-type must be a non-empty string.',
161-
'Input must be a plain object.',
161+
'properties must be a plain object.',
162162
'value must be null or number.'
163163
];
164164
const key = getLongKey();

client/__tests__/treatment.test.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -247,30 +247,7 @@ describe('get-treatment', () => {
247247
.set('Authorization', 'test');
248248
expectOk(response, 200, 'control', 'nonexistant-experiment');
249249
});
250-
251-
test('should be 400 if options.properties is invalid (GET)', async () => {
252-
const expected = [
253-
'options.properties must only contain boolean, string, or number values.'
254-
];
255-
const response = await request(app)
256-
.get('/client/get-treatment?key=test&split-name=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
257-
.set('Authorization', 'test');
258-
expectErrorContaining(response, 400, expected);
259-
});
260-
261-
test('should be 400 if options.properties is invalid (POST)', async () => {
262-
const expected = [
263-
'options.properties must only contain boolean, string, or number values.'
264-
];
265-
const response = await request(app)
266-
.post('/client/get-treatment?key=test&split-name=my-experiment')
267-
.send({
268-
options: { properties: { invalid: [1, 2, 3] } },
269-
})
270-
.set('Authorization', 'test');
271-
expectErrorContaining(response, 400, expected);
272-
});
273-
250+
274251
test('should be 200 if options.properties is valid (GET)', async () => {
275252
const response = await request(app)
276253
.get('/client/get-treatment?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/treatmentWithConfig.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,6 @@ describe('get-treatment-with-config', () => {
230230
expectOk(response, 200, 'control', 'nonexistant-experiment', null);
231231
});
232232

233-
test('should be 400 if options.properties is invalid (GET)', async () => {
234-
const expected = [
235-
'options.properties must only contain boolean, string, or number values.'
236-
];
237-
const response = await request(app)
238-
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
239-
.set('Authorization', 'test');
240-
expectErrorContaining(response, 400, expected);
241-
});
242-
243-
test('should be 400 if options.properties is invalid (POST)', async () => {
244-
const expected = [
245-
'options.properties must only contain boolean, string, or number values.'
246-
];
247-
const response = await request(app)
248-
.post('/client/get-treatment-with-config?key=test&split-name=my-experiment')
249-
.send({
250-
options: { properties: { invalid: [1, 2, 3] } },
251-
})
252-
.set('Authorization', 'test');
253-
expectErrorContaining(response, 400, expected);
254-
});
255-
256233
test('should be 200 if options.properties is valid (GET)', async () => {
257234
const response = await request(app)
258235
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/treatments.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,6 @@ describe('get-treatments', () => {
268268
}, 3);
269269
});
270270

271-
test('should be 400 if options.properties is invalid (GET)', async () => {
272-
const expected = [
273-
'options.properties must only contain boolean, string, or number values.'
274-
];
275-
const response = await request(app)
276-
.get('/client/get-treatments?key=test&split-names=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
277-
.set('Authorization', 'test');
278-
expectErrorContaining(response, 400, expected);
279-
});
280-
281-
test('should be 400 if options.properties is invalid (POST)', async () => {
282-
const expected = [
283-
'options.properties must only contain boolean, string, or number values.'
284-
];
285-
const response = await request(app)
286-
.post('/client/get-treatments?key=test&split-names=my-experiment')
287-
.send({
288-
options: { properties: { invalid: [1, 2, 3] } },
289-
})
290-
.set('Authorization', 'test');
291-
expectErrorContaining(response, 400, expected);
292-
});
293-
294271
test('should be 200 if options.properties is valid (GET)', async () => {
295272
const response = await request(app)
296273
.get('/client/get-treatments?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/treatmentsByFlagSets.test.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -273,30 +273,7 @@ describe('get-treatments-by-sets', () => {
273273
.set('Authorization', 'key_pink');
274274
expectOkMultipleResults(response, 200, expectedPinkResults, 5);
275275
});
276-
277-
test('should be 400 if options.properties is invalid (GET)', async () => {
278-
const expected = [
279-
'options.properties must only contain boolean, string, or number values.'
280-
];
281-
const response = await request(app)
282-
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&options={"properties":{"invalid":[1,2,3]}}')
283-
.set('Authorization', 'key_green');
284-
expectErrorContaining(response, 400, expected);
285-
});
286-
287-
test('should be 400 if options.properties is invalid (POST)', async () => {
288-
const expected = [
289-
'options.properties must only contain boolean, string, or number values.'
290-
];
291-
const response = await request(app)
292-
.post('/client/get-treatments-by-sets?key=test&flag-sets=set_green')
293-
.send({
294-
options: { properties: { invalid: [1, 2, 3] } },
295-
})
296-
.set('Authorization', 'key_green');
297-
expectErrorContaining(response, 400, expected);
298-
});
299-
276+
300277
test('should be 200 if options.properties is valid (GET)', async () => {
301278
const response = await request(app)
302279
.get('/client/get-treatments-by-sets?key=test&flag-sets=set_green&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/__tests__/treatmentsWithConfig.test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,6 @@ describe('get-treatments-with-config', () => {
253253
}, 3);
254254
});
255255

256-
test('should be 400 if options.properties is invalid (GET)', async () => {
257-
const expected = [
258-
'options.properties must only contain boolean, string, or number values.'
259-
];
260-
const response = await request(app)
261-
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&options={"properties":{"invalid":[1,2,3]}}')
262-
.set('Authorization', 'test');
263-
expectErrorContaining(response, 400, expected);
264-
});
265-
266-
test('should be 400 if options.properties is invalid (POST)', async () => {
267-
const expected = [
268-
'options.properties must only contain boolean, string, or number values.'
269-
];
270-
const response = await request(app)
271-
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
272-
.send({
273-
options: { properties: { invalid: [1, 2, 3] } },
274-
})
275-
.set('Authorization', 'test');
276-
expectErrorContaining(response, 400, expected);
277-
});
278-
279256
test('should be 200 if options.properties is valid (GET)', async () => {
280257
const response = await request(app)
281258
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&options={"properties":{"package":"premium","admin":true,"discount":50}}')

client/client.router.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const attributesValidator = require('../utils/inputValidation/attributes');
88
const trafficTypeValidator = require('../utils/inputValidation/trafficType');
99
const eventTypeValidator = require('../utils/inputValidation/eventType');
1010
const valueValidator = require('../utils/inputValidation/value');
11-
const propertiesValidator = require('../utils/inputValidation/properties');
11+
const { validateProperties, validateEvaluationOptions } = require('../utils/inputValidation/properties');
1212
const keysValidator = require('../utils/inputValidation/keys');
1313
const clientController = require('./client.controller');
1414
const { parseValidators } = require('../utils/utils');
@@ -24,7 +24,7 @@ const treatmentValidation = (req, res, next) => {
2424
const bucketingKeyValidation = req.query['bucketing-key'] !== undefined ? keyValidator(req.query['bucketing-key'], 'bucketing-key') : null;
2525
const featureFlagNameValidation = splitValidator(req.query['split-name']);
2626
const attributesValidation = attributesValidator(req.query.attributes);
27-
const optionsValidation = propertiesValidator(req.query.options);
27+
const optionsValidation = validateEvaluationOptions(req.query.options);
2828

2929
const error = parseValidators([matchingKeyValidation, bucketingKeyValidation, featureFlagNameValidation, attributesValidation, optionsValidation]);
3030
if (error.length) {
@@ -58,7 +58,7 @@ const treatmentsValidation = (req, res, next) => {
5858
const bucketingKeyValidation = req.query['bucketing-key'] !== undefined ? keyValidator(req.query['bucketing-key'], 'bucketing-key') : null;
5959
const featureFlagsNameValidation = splitsValidator(req.query['split-names']);
6060
const attributesValidation = attributesValidator(req.query.attributes);
61-
const optionsValidation = propertiesValidator(req.query.options);
61+
const optionsValidation = validateEvaluationOptions(req.query.options);
6262

6363
const error = parseValidators([matchingKeyValidation, bucketingKeyValidation, featureFlagsNameValidation, attributesValidation, optionsValidation]);
6464
if (error.length) {
@@ -92,7 +92,7 @@ const flagSetsValidation = (req, res, next) => {
9292
const bucketingKeyValidation = req.query['bucketing-key'] !== undefined ? keyValidator(req.query['bucketing-key'], 'bucketing-key') : null;
9393
const flagSetNameValidation = flagSetsValidator(req.query['flag-sets']);
9494
const attributesValidation = attributesValidator(req.query.attributes);
95-
const optionsValidation = propertiesValidator(req.query.options);
95+
const optionsValidation = validateEvaluationOptions(req.query.options);
9696

9797
const error = parseValidators([matchingKeyValidation, bucketingKeyValidation, flagSetNameValidation, attributesValidation, optionsValidation]);
9898
if (error.length) {
@@ -126,7 +126,7 @@ const trackValidation = (req, res, next) => {
126126
const trafficTypeValidation = trafficTypeValidator(req.query['traffic-type']);
127127
const eventTypeValidation = eventTypeValidator(req.query['event-type']);
128128
const valueValidation = valueValidator(req.query.value);
129-
const propertiesValidation = propertiesValidator(req.query.properties);
129+
const propertiesValidation = validateProperties(req.query.properties);
130130

131131
const error = parseValidators([keyValidation, trafficTypeValidation, eventTypeValidation, valueValidation, propertiesValidation]);
132132
if (error.length) {
@@ -157,7 +157,7 @@ const trackValidation = (req, res, next) => {
157157
const allTreatmentValidation = (req, res, next) => {
158158
const keysValidation = keysValidator(req.query.keys);
159159
const attributesValidation = attributesValidator(req.query.attributes);
160-
const optionsValidation = propertiesValidator(req.query.options);
160+
const optionsValidation = validateEvaluationOptions(req.query.options);
161161

162162
const error = parseValidators([keysValidation, attributesValidation, optionsValidation]);
163163
if (error.length) {

0 commit comments

Comments
 (0)