Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecating users self #2043

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,21 @@
const getSelfDetails = async (req, res) => {
try {
if (req.userData) {
const id = req.params.id;
const params = req.query.params;
const user = await dataAccess.retrieveUsers({
userdata: req.userData,
});
return res.send(user);
if (params === undefined) {
if (id === user.id) {
return res.send(user);
}
}
const paramsArray = params.split(",");
const commonKeysObject = Object.fromEntries(paramsArray.map((key) => [key, user[key]]));

Check warning on line 386 in controllers/users.js

View workflow job for this annotation

GitHub Actions / build (20.11.x)

Generic Object Injection Sink
if (id === user.id) {
return res.send(commonKeysObject);
}
}
return res.boom.notFound("User doesn't exist");
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.post("/verify", authenticate, users.verifyUser);
router.get("/userId/:userId", users.getUserById);
router.patch("/self", authenticate, userValidator.updateUser, users.updateSelf);
router.get("/", userValidator.getUsers, users.getUsers);
router.get("/self", authenticate, users.getSelfDetails);
router.get("/:id", authenticate, users.getSelfDetails);
Dismissed Show dismissed Hide dismissed
router.get("/isDeveloper", authenticate, users.isDeveloper);
router.get("/isUsernameAvailable/:username", authenticate, users.getUsernameAvailabilty);
router.get("/username", authenticate, userValidator.validateGenerateUsernameQuery, users.generateUsername);
Expand Down
7 changes: 4 additions & 3 deletions test/integration/external-accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,10 @@ describe("External Accounts", function () {

describe("PATCH /external-accounts/link/:token", function () {
let newUserJWT;
let userId;

beforeEach(async function () {
const userId = await addUser(userData[3]);
userId = await addUser(userData[3]);
newUserJWT = authService.generateAuthToken({ userId });
await externalAccountsModel.addExternalAccountData(externalAccountData[2]);
await externalAccountsModel.addExternalAccountData(externalAccountData[3]);
Expand Down Expand Up @@ -529,7 +530,7 @@ describe("External Accounts", function () {
await externalAccountsModel.addExternalAccountData(externalAccountData[2]);
const getUserResponseBeforeUpdate = await chai
.request(app)
.get("/users/self")
.get(`/users/${userId}`)
.set("cookie", `${cookieName}=${newUserJWT}`);

expect(getUserResponseBeforeUpdate).to.have.status(200);
Expand All @@ -547,7 +548,7 @@ describe("External Accounts", function () {

const updatedUserDetails = await chai
.request(app)
.get("/users/self")
.get(`/users/${userId}`)
.set("cookie", `${cookieName}=${newUserJWT}`);

expect(updatedUserDetails.body.roles.in_discord).to.equal(true);
Expand Down
5 changes: 3 additions & 2 deletions test/integration/restricted.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ describe("checkRestrictedUser", function () {
let restrictedJwt;
let unrestrictedJwt;
let fetchStub;
let restrictedUserId;

before(async function () {
const restrictedUserId = await addUser(restrictedUser);
restrictedUserId = await addUser(restrictedUser);
const unrestrictedUserId = await addUser(unrestrictedUser);
restrictedJwt = authService.generateAuthToken({ userId: restrictedUserId });
unrestrictedJwt = authService.generateAuthToken({ userId: unrestrictedUserId });
Expand All @@ -44,7 +45,7 @@ describe("checkRestrictedUser", function () {
it("should allow GET request coming from restricted user", function (done) {
chai
.request(app)
.get("/users/self")
.get(`/users/${restrictedUserId}`)
.set("cookie", `${cookieName}=${restrictedJwt}`)
.end((err, res) => {
if (err) {
Expand Down
9 changes: 6 additions & 3 deletions test/integration/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ describe("Users", function () {
});

describe("PATCH /users/self", function () {
beforeEach(function () {
let userId;

beforeEach(async function () {
fetchStub = Sinon.stub(global, "fetch");
fetchStub.returns(
Promise.resolve({
status: 200,
json: () => Promise.resolve(getDiscordMembers),
})
);
userId = await addUser(newUser);
});

afterEach(function () {
Expand Down Expand Up @@ -166,7 +169,7 @@ describe("Users", function () {

const getUserResponseBeforeUpdate = await chai
.request(app)
.get("/users/self")
.get(`/users/${userId}`)
.set("cookie", `${cookieName}=${newUserJwt}`);

expect(getUserResponseBeforeUpdate).to.have.status(200);
Expand All @@ -187,7 +190,7 @@ describe("Users", function () {

const getUserResponseAfterUpdate = await chai
.request(app)
.get("/users/self")
.get(`/users/${userId}`)
.set("cookie", `${cookieName}=${newUserJwt}`);

expect(getUserResponseAfterUpdate).to.have.status(200);
Expand Down
Loading