Skip to content

Commit c661d65

Browse files
authored
Merge branch 'next' into SER-1555-deepscan-hooks-fix-insufficient-null-checks
2 parents 37ca9e9 + 58bb718 commit c661d65

File tree

6 files changed

+105
-23
lines changed

6 files changed

+105
-23
lines changed

api/parts/data/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ class StreamedCollection {
971971
let [col, last] = await createCollection(this.db, this.name, 1e7);
972972

973973
this.col = col;
974-
this.stream = col.find({_id: {$gt: last}}, {tailable: true, awaitData: true, noCursorTimeout: true, numberOfRetries: -1}).stream();
974+
this.stream = col.find({_id: {$gt: last}}, {tailable: true, awaitData: true, numberOfRetries: -1}).stream();
975975

976976
this.stream.on('data', doc => {
977977
if (this.inserts.indexOf(doc._id.toString()) !== -1) {

api/parts/mgmt/cms.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,21 @@ function syncCMSDataToDB(params) {
157157
}
158158

159159
cmsApi.saveEntries = function(params) {
160+
161+
var entries = [];
162+
try {
163+
entries = JSON.parse(params.qstring.entries);
164+
}
165+
catch (ex) {
166+
log.e(params.qstring.entries);
167+
common.returnMessage(params, 400, 'Invalid entries parameter');
168+
return;
169+
}
170+
160171
transformAndStoreData(
161172
Object.assign({dataTransformed: true}, params),
162173
null,
163-
JSON.parse(params.qstring.entries),
174+
entries,
164175
function(err1) {
165176
if (err1) {
166177
log.e('An error occured while storing entries in DB: ' + err1);

frontend/express/public/localization/dashboard/dashboard.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ common.in-last-weeks-plural = in the last {0} weeks
293293
common.in-last-weeks = in the last week
294294
common.in-last-months-plural = in the last {0} months
295295
common.in-last-months = in the last month
296+
common.in-last-years-plural = in the last {0} years
297+
common.in-last-years = in the last year
296298
common.time-period-select.custom-range = Custom range
297299
common.time-period-select.presets = Presets
298300
common.time-period-select.last-n = In the last

frontend/express/views/dashboard.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
ignoreURLs: ["action=refresh", "method=live", "stats.count.ly", "method=get_events", "display_loader=false"]
3030
}
3131
};
32+
window.loadPlugin = function(plugin, callback, args){
33+
if (typeof plugin !== "string") {
34+
console.log("when loading plugin, provided plugin was not a string, but a", plugin);
35+
}
36+
if (typeof callback !== "function") {
37+
console.log("when loading plugin", plugin, "provided callback was not a function, but a", callback);
38+
}
39+
if (countlyGlobal.plugins.indexOf(plugin) !== -1) {
40+
if (Array.isArray(args)){
41+
callback.apply(window, args);
42+
}
43+
else {
44+
callback(args);
45+
}
46+
}
47+
};
3248
</script>
3349
<link rel="stylesheet" href="<%- cdn %>stylesheets/font-awesome/css/font-awesome.min.css?<%= countlyVersion %>" />
3450
<link rel="stylesheet" href="<%- cdn %>stylesheets/countly-icons/style.css?<%= countlyVersion %>" />

plugins/populator/api/api.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,36 @@ const FEATURE_NAME = 'populator';
210210

211211
const saveEnvironment = function(ob) {
212212
const obParams = ob.params;
213-
const users = JSON.parse(ob.params.qstring.users);
214-
const setEnviromentInformationOnce = ob.params.qstring.setEnviromentInformationOnce;
215-
if (!users || !users.length) {
216-
common.returnMessage(obParams, 400, "Missing params: " + users);
217-
return false;
218-
}
219-
220-
const environmentId = common.crypto.createHash('sha1').update(users[0].appId + users[0].environmentName).digest('hex');
221-
const insertedInformations = [];
222-
const createdAt = new Date().getTime();
223-
for (let i = 0; i < users.length; i++) {
224-
insertedInformations.push({
225-
_id: users[i].appId + "_" + users[i].templateId + "_" + environmentId + "_" + users[i].deviceId,
226-
userName: users[i].userName,
227-
platform: users[i].platform,
228-
device: users[i].device,
229-
appVersion: users[i].appVersion,
230-
custom: users[i].custom,
231-
createdAt: createdAt
232-
});
233-
}
234213
validateCreate(obParams, FEATURE_NAME, function(params) {
214+
var users = [];
215+
try {
216+
users = JSON.parse(ob.params?.qstring?.users);
217+
}
218+
catch (e) {
219+
log.e(e);
220+
users = [];
221+
}
222+
const setEnviromentInformationOnce = ob.params?.qstring?.setEnviromentInformationOnce ;
223+
if (!users || !users.length) {
224+
common.returnMessage(obParams, 400, "Missing params: users");
225+
return false;
226+
}
227+
228+
const environmentId = common.crypto.createHash('sha1').update(users[0].appId + users[0].environmentName).digest('hex');
229+
const insertedInformations = [];
230+
const createdAt = new Date().getTime();
231+
for (let i = 0; i < users.length; i++) {
232+
insertedInformations.push({
233+
_id: users[i].appId + "_" + users[i].templateId + "_" + environmentId + "_" + users[i].deviceId,
234+
userName: users[i].userName,
235+
platform: users[i].platform,
236+
device: users[i].device,
237+
appVersion: users[i].appVersion,
238+
custom: users[i].custom,
239+
createdAt: createdAt
240+
});
241+
}
242+
235243
if (setEnviromentInformationOnce) {
236244
common.db.collection('populator_environments').insertOne({
237245
_id: environmentId,

plugins/populator/tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var request = require('supertest');
2+
var should = require('should');
3+
var testUtils = require("../../test/testUtils");
4+
request = request(testUtils.url);
5+
6+
var APP_KEY = "";
7+
var API_KEY_ADMIN = "";
8+
var APP_ID = "";
9+
var DEVICE_ID = "1234567890";
10+
11+
describe('Testing Populator plugin', function() {
12+
describe('Testing enviroment endpoint ', function() {
13+
it('Set params', function(done) {
14+
API_KEY_ADMIN = testUtils.get("API_KEY_ADMIN");
15+
APP_ID = testUtils.get("APP_ID");
16+
APP_KEY = testUtils.get("APP_KEY");
17+
done();
18+
});
19+
20+
it('Try without any params', function(done) {
21+
request
22+
.get('/i/populator/environment/save')
23+
.expect(400)
24+
.end(function(err, res) {
25+
var ob = JSON.parse(res.text);
26+
ob.result.should.eql("Missing parameter \"api_key\" or \"auth_token\"");
27+
done();
28+
});
29+
30+
});
31+
32+
it('Try without "users"', function(done) {
33+
request
34+
.get('/i/populator/environment/save?api_key=' + API_KEY_ADMIN)
35+
.expect(400)
36+
.end(function(err, res) {
37+
var ob = JSON.parse(res.text);
38+
ob.result.should.eql("Missing params: users");
39+
done();
40+
});
41+
});
42+
});
43+
44+
45+
});

0 commit comments

Comments
 (0)