Skip to content

Commit

Permalink
Merge pull request #99 from splitio/development
Browse files Browse the repository at this point in the history
Development into master - Release 2.1.0
  • Loading branch information
NicoZelaya authored Jul 15, 2022
2 parents 6ea1bc1 + 40a0412 commit 86fea48
Show file tree
Hide file tree
Showing 19 changed files with 1,439 additions and 2,364 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16.14.0
node-version: 16.16.0

- run: npm ci
- run: npm run lint
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.14.0
v16.16
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2.1.0 (Jul 15, 2022)
- Added support for attribute values to be sent as JSON in a POST version of the get treatment endpoints, to avoid query param limitations.
- Updated the SDK version to 10.20.0 which is the latest to the date.
- Updated npm dependencies for vulnerability fixes.
- Updated base image to node:16.16.0-alpine3.16

2.0.7 (Mar 28, 2022)
- Updated alpine image for vulnerabilities.

2.0.6 (Feb 24, 2022)
- Updated SDK version to v10.17.2 which is the latest stable to the date and includes vulnerability fixes and improvements. See more here https://github.com/splitio/javascript-client/blob/development/CHANGES.txt
- Updated many dependencies and fixing vulnerabilities.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder stage
FROM node:16.14.0-alpine3.15 AS builder
FROM node:16.16.0-alpine3.16 AS builder

WORKDIR /usr/src/split-evaluator

Expand All @@ -8,7 +8,7 @@ COPY package.json package-lock.json ./
RUN npm install --only=production

# Runner stage
FROM node:16.14.0-alpine3.15 AS runner
FROM node:16.16.0-alpine3.16 AS runner

WORKDIR /usr/src/split-evaluator

Expand Down
2 changes: 1 addition & 1 deletion admin/__tests__/machine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ process.env.SPLIT_EVALUATOR_AUTH_TOKEN = 'test';
process.env.SPLIT_EVALUATOR_API_KEY = 'localhost';

const os = require('os');
const ip = require('ip');
const ip = require('@splitsoftware/splitio/lib/utils/ip');
const request = require('supertest');
const app = require('../../app');
const { expectError } = require('../../utils/testWrapper/index');
Expand Down
2 changes: 1 addition & 1 deletion admin/admin.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require('os');
const ip = require('ip');
const ip = require('@splitsoftware/splitio/lib/utils/ip');

const utils = require('../utils/utils');
const sdkModule = require('../sdk');
Expand Down
49 changes: 47 additions & 2 deletions client/__tests__/treatment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,67 @@ describe('get-treatment', () => {
done();
});

test('should be 200 if is valid attributes', async (done) => {
test('should be 400 if attributes is an invalid json (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.set('Content-Type', 'application/json')
// eslint-disable-next-line no-useless-escape
.send('\|\\\"/regex/i') // Syntax error parsing the JSON.
.set('Authorization', 'test');
expectError(response, 400);
expect(response.body.error.type).toBe('entity.parse.failed'); // validate the error
done();
});

test('should be 200 if is valid attributes (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatment?key=test&split-name=my-experiment&attributes={"test":"test"}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
done();
});

test('should be 200 if attributes is null', async (done) => {
test('should be 200 if attributes is null (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatment?key=test&split-name=my-experiment')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
done();
});

test('should be 200 if is valid attributes (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.send({
attributes: {test:'test'},
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
done();
});

test('should be 200 if is valid attributes as string (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.send(JSON.stringify({
attributes: {test:'test'},
}))
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
done();
});

test('should be 200 if attributes is null (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatment?key=test&split-name=my-experiment')
.send({
attributes: null,
})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment');
done();
});

// Testing Multiple Experiments Regarding YAML
test('should be 200 with multiple experiments', async (done) => {
// Checking multiple experiments regarding yml passed
Expand Down
30 changes: 28 additions & 2 deletions client/__tests__/treatmentWithConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,41 @@ describe('get-treatment-with-config', () => {
done();
});

test('should be 200 if is valid attributes', async (done) => {
test('should be 200 if is valid attributes (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment&attributes={"test":"test"}')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
done();
});

test('should be 200 when attributes is null', async (done) => {
test('should be 200 when attributes is null (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
done();
});

test('should be 200 if is valid attributes (POST)', async (done) => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.send({attributes: { test:'test' }})
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
done();
});

test('should be 200 if is valid stringified attributes (POST)', async (done) => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.send(JSON.stringify({attributes: { test:'test' }}))
.set('Authorization', 'test');
expectOk(response, 200, 'on', 'my-experiment', '{"desc" : "this applies only to ON treatment"}');
done();
});

test('should be 200 when attributes is null (POST)', async (done) => {
const response = await request(app)
.get('/client/get-treatment-with-config?key=test&split-name=my-experiment')
.set('Authorization', 'test');
Expand Down
61 changes: 59 additions & 2 deletions client/__tests__/treatments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,19 @@ describe('get-treatments', () => {
done();
});

test('should be 200 if is valid attributes', async (done) => {
test('should be 400 if attributes is an invalid json (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-name=my-experiment')
.set('Content-Type', 'application/json')
// eslint-disable-next-line no-useless-escape
.send('\|\\\"/regex/i') // Syntax error parsing the JSON.
.set('Authorization', 'test');
expectError(response, 400);
expect(response.body.error.type).toBe('entity.parse.failed'); // validate the error
done();
});

test('should be 200 if is valid attributes (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatments?key=test&split-names=my-experiment&attributes={"test":"test"}')
.set('Authorization', 'test');
Expand All @@ -205,7 +217,7 @@ describe('get-treatments', () => {
done();
});

test('should be 200 when attributes is null', async (done) => {
test('should be 200 when attributes is null (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatments?key=test&split-names=my-experiment,my-experiment')
.set('Authorization', 'test');
Expand All @@ -217,6 +229,51 @@ describe('get-treatments', () => {
done();
});

test('should be 200 if is valid attributes (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-names=my-experiment')
.set('Authorization', 'test')
.send({
attributes: {test:'test'},
});
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
},
}, 1);
done();
});

test('should be 200 if is valid attributes as string (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-names=my-experiment')
.send(JSON.stringify({
attributes: {test:'test'},
}))
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
},
}, 1);
done();
});

test('should be 200 if attributes is null (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatments?key=test&split-names=my-experiment,my-experiment')
.send({
attributes: null,
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
},
}, 1);
done();
});

// Testing Multiple Experiments Regarding YAML
test('should be 200 with multiple evaluation', async (done) => {
// Checking multiple experiments regarding yml passed
Expand Down
48 changes: 46 additions & 2 deletions client/__tests__/treatmentsWithConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('get-treatments-with-config', () => {
done();
});

test('should be 200 if is valid attributes', async (done) => {
test('should be 200 if is valid attributes (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&attributes={"test":"test"}')
.set('Authorization', 'test');
Expand All @@ -199,7 +199,7 @@ describe('get-treatments-with-config', () => {
done();
});

test('should be 200 when attributes is null', async (done) => {
test('should be 200 when attributes is null (GET)', async (done) => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment,my-experiment')
.set('Authorization', 'test');
Expand All @@ -212,6 +212,50 @@ describe('get-treatments-with-config', () => {
done();
});

test('should be 200 if is valid attributes (POST)', async (done) => {
const response = await request(app)
.post('/client/get-treatments-with-config?key=test&split-names=my-experiment')
.send({attributes: { test:'test' }})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
config: '{"desc" : "this applies only to ON treatment"}',
},
}, 1);
done();
});

test('should be 200 if is valid attributes stringified (POST)', async (done) => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment&attributes={"test":"test"}')
.send(JSON.stringify({attributes: { test:'test' }}))
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
config: '{"desc" : "this applies only to ON treatment"}',
},
}, 1);
done();
});

test('should be 200 when attributes is null (POST)', async (done) => {
const response = await request(app)
.get('/client/get-treatments-with-config?key=test&split-names=my-experiment,my-experiment')
.send({
attributes: null,
})
.set('Authorization', 'test');
expectOkMultipleResults(response, 200, {
'my-experiment': {
treatment: 'on',
config: '{"desc" : "this applies only to ON treatment"}',
},
}, 1);
done();
});

// Testing Multiple Experiments Regarding YAML
test('should be 200 with multiple evaluation', async (done) => {
let response = await request(app)
Expand Down
34 changes: 33 additions & 1 deletion client/client.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,44 @@ const allTreatmentValidation = (req, res, next) => {
next();
};

// Simple method to reuse the full logic of the GET version of get treatment operations,
// by just connecting the json payload parsed on the right spot.
const fwdAttributesFromPost = function parseAttributesMiddleware(req, res, next) {
req.query.attributes = req.body.attributes;

next();
};

const handleBodyParserErr = function handleBodyParserErr(error, req, res, next) {
if (error) {
return res
.status(400)
.send({
error,
});
}

next();
};

// Getting treatments regularly
router.get('/get-treatment', treatmentValidation, clientController.getTreatment);
router.get('/get-treatment-with-config', treatmentValidation, clientController.getTreatmentWithConfig);
router.get('/get-treatments', treatmentsValidation, clientController.getTreatments);
router.get('/get-treatments-with-config', treatmentsValidation, clientController.getTreatmentsWithConfig);
router.get('/track', trackValidation, clientController.track);
router.get('/get-all-treatments', allTreatmentValidation, clientController.getAllTreatments);
router.get('/get-all-treatments-with-config', allTreatmentValidation, clientController.getAllTreatmentsWithConfig);

// Getting treatments as POST's for big attribute sets
const JSON_PARSE_OPTS = { limit: '300kb' };
router.post('/get-treatment',express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentValidation, clientController.getTreatment);
router.post('/get-treatment-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentValidation, clientController.getTreatmentWithConfig);
router.post('/get-treatments', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentsValidation, clientController.getTreatments);
router.post('/get-treatments-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, treatmentsValidation, clientController.getTreatmentsWithConfig);
router.post('/get-all-treatments', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, allTreatmentValidation, clientController.getAllTreatments);
router.post('/get-all-treatments-with-config', express.json(JSON_PARSE_OPTS), fwdAttributesFromPost, handleBodyParserErr, allTreatmentValidation, clientController.getAllTreatmentsWithConfig);

// Other methods
router.get('/track', trackValidation, clientController.track);

module.exports = router;
4 changes: 2 additions & 2 deletions listener/__tests__/ip-addresses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ip addresses', () => {
process.env.SPLIT_EVALUATOR_IMPRESSION_LISTENER_ENDPOINT = 'http://localhost:7546';
const app = require('../../app');
const os = require('os');
const localIp = require('ip');
const localIp = require('@splitsoftware/splitio/lib/utils/ip');

const sdkModule = require('../../sdk');
sdkModule.factory.settings.impressionListener.logImpression = log;
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('ip addresses', () => {
process.env.SPLIT_EVALUATOR_IP_ADDRESSES_ENABLED = 'true';
const app = require('../../app');
const os = require('os');
const localIp = require('ip');
const localIp = require('@splitsoftware/splitio/lib/utils/ip');

const sdkModule = require('../../sdk');
sdkModule.factory.settings.impressionListener.logImpression = log;
Expand Down
Loading

0 comments on commit 86fea48

Please sign in to comment.