Skip to content

Commit 2a6af86

Browse files
committed
impr: dont allow taking blocklisted names via update account name
!nuf
1 parent 8e38eae commit 2a6af86

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

backend/__tests__/api/controllers/user.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ describe("user controller test", () => {
783783
});
784784
});
785785
describe("update name", () => {
786+
const blocklistContainsMock = vi.spyOn(BlocklistDal, "contains");
786787
const getPartialUserMock = vi.spyOn(UserDal, "getPartialUser");
787788
const updateNameMock = vi.spyOn(UserDal, "updateName");
788789
const addImportantLogMock = vi.spyOn(LogDal, "addImportantLog");
@@ -791,6 +792,7 @@ describe("user controller test", () => {
791792
getPartialUserMock.mockReset();
792793
updateNameMock.mockReset();
793794
addImportantLogMock.mockReset();
795+
blocklistContainsMock.mockReset();
794796
});
795797

796798
it("should update the username", async () => {
@@ -819,6 +821,23 @@ describe("user controller test", () => {
819821
uid
820822
);
821823
});
824+
825+
it("should fail if username is blocked", async () => {
826+
//GIVEN
827+
blocklistContainsMock.mockResolvedValue(true);
828+
829+
//WHEN
830+
const { body } = await mockApp
831+
.patch("/users/name")
832+
.set("authorization", `Uid ${uid}`)
833+
.send({ name: "newName" })
834+
.expect(409);
835+
836+
//THEN
837+
expect(body.message).toEqual("Username blocked");
838+
expect(updateNameMock).not.toHaveBeenCalled();
839+
});
840+
822841
it("should fail for banned users", async () => {
823842
//GIVEN
824843
getPartialUserMock.mockResolvedValue({ banned: true } as any);

backend/src/api/controllers/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ export async function updateName(
326326
const { uid } = req.ctx.decodedToken;
327327
const { name } = req.body;
328328

329+
const blocklisted = await BlocklistDal.contains({ name });
330+
if (blocklisted) {
331+
throw new MonkeyError(409, "Username blocked");
332+
}
333+
329334
const user = await UserDAL.getPartialUser(uid, "update name", [
330335
"name",
331336
"banned",

0 commit comments

Comments
 (0)