Skip to content

Commit 8ff5d3e

Browse files
fix(home): address review nitpicks on team projection and deps
1 parent 2906ed1 commit 8ff5d3e

4 files changed

Lines changed: 9 additions & 88 deletions

File tree

modules/home/services/home.service.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ const page = async (name) => {
3636

3737
/**
3838
* @desc Function to get all admin users in db, returning only public-safe fields.
39-
* @returns {Promise<Array>} Public user profiles (firstName, lastName, bio, position, avatar)
39+
* Uses a lean projection so no Mongoose virtuals (e.g. `id`) can re-introduce hidden fields.
40+
* @returns {Promise<Array<{firstName: string, lastName: string, bio: string, position: string, avatar: string}>>} Public user profiles
4041
*/
41-
const team = async () => {
42-
const result = await HomeRepository.team();
43-
return result.map((user) => (typeof user.toJSON === 'function' ? user.toJSON() : user));
44-
};
42+
const team = async () => HomeRepository.team();
4543

4644
/**
4745
* @desc Build health status including database connectivity.

modules/home/tests/home.integration.tests.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ describe('Home integration tests:', () => {
7474
expect(result.body.type).toBe('success');
7575
expect(result.body.message).toBe('team list');
7676
expect(result.body.data).toBeInstanceOf(Array);
77-
// Verify no sensitive fields are exposed
77+
// Assert the strict public-field allowlist: every key must be one of these,
78+
// so no unexpected field (incl. _id / id / sensitive data) can ever leak.
79+
const ALLOWED_FIELDS = new Set(['firstName', 'lastName', 'bio', 'position', 'avatar']);
7880
result.body.data.forEach((member) => {
79-
expect(member).not.toHaveProperty('email');
80-
expect(member).not.toHaveProperty('emailVerified');
81-
expect(member).not.toHaveProperty('lastLoginAt');
82-
expect(member).not.toHaveProperty('roles');
83-
expect(member).not.toHaveProperty('password');
84-
expect(member).not.toHaveProperty('providerData');
81+
Object.keys(member).forEach((key) => {
82+
expect(ALLOWED_FIELDS.has(key)).toBe(true);
83+
});
8584
});
8685
} catch (err) {
8786
expect(err).toBeFalsy();

package-lock.json

Lines changed: 0 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"dependencies": {
5252
"@casl/ability": "^7.0.0",
5353
"@jest/globals": "^30.4.1",
54-
"axios": "^1.16.1",
5554
"bcrypt": "^6.0.0",
5655
"bson": "^7.2.0",
5756
"chalk": "^5.6.2",
@@ -68,7 +67,6 @@
6867
"helmet": "~8.2.0",
6968
"inquirer": "^13.4.3",
7069
"jest-environment-jsdom": "^30.4.1",
71-
"js-base64": "^3.7.8",
7270
"js-yaml": "^4.1.1",
7371
"jsonwebtoken": "^9.0.3",
7472
"lodash": "^4.18.1",

0 commit comments

Comments
 (0)