Skip to content

Commit 940a54a

Browse files
pierreTkleinloreina
authored andcommitted
feat: fix non-determinism of npm run seed (Bugfix/651) (#652)
* fix: hasOwnProperty vulnerability (see https://eslint.org/docs/rules/no-prototype-builtins) * feat: _id value to all route objects, starting at 100 and moving upwards. Add warning at top of file to maintain naming standard. * feat: update role.constant.js to use the new _id attribute so that ids are deterministic between two runs of npm run seed. * feat: update architecture documentation
1 parent e8a5fc3 commit 940a54a

File tree

3 files changed

+207
-79
lines changed

3 files changed

+207
-79
lines changed

constants/role.constant.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,26 @@ function createAllSingularRoles() {
151151
const allRoutes = Constants.Routes.allRoutes;
152152
let roles = [];
153153

154-
// i is unique integer so that objectId is constant
155-
var i = 1000000;
156154
for (let routeGroupKey in allRoutes) {
157-
if (!allRoutes.hasOwnProperty(routeGroupKey)) {
155+
if (!Object.prototype.hasOwnProperty.call(allRoutes, routeGroupKey)) {
158156
continue;
159157
}
160158

161159
const routeGroup = allRoutes[routeGroupKey];
162160
for (let routeKey in routeGroup) {
163-
if (!routeGroup.hasOwnProperty(routeKey)) {
161+
// Iterating through the attributes in the routeGroup object
162+
if (!Object.prototype.hasOwnProperty.call(routeGroup, routeKey)) {
163+
// Avoid all prototype attributes
164164
continue;
165165
}
166166

167167
let role = {
168-
_id: mongoose.Types.ObjectId(i),
168+
_id: routeGroup[routeKey]._id,
169169
name: routeKey + routeGroupKey,
170170
routes: routeGroup[routeKey]
171171
};
172172
let roleName = role.name;
173173
roles[roleName] = role;
174-
i -= 1;
175174
}
176175
}
177176

@@ -197,7 +196,7 @@ function createAllRoles() {
197196

198197
const singularRoles = createAllSingularRoles();
199198
for (let role in singularRoles) {
200-
if (!singularRoles.hasOwnProperty(role)) {
199+
if (!Object.prototype.hasOwnProperty.call(singularRoles, role)) {
201200
continue;
202201
}
203202
allRolesObject[role] = singularRoles[role];

0 commit comments

Comments
 (0)