diff --git a/src/nameRecord.js b/src/nameRecord.js index 932f387..c981557 100644 --- a/src/nameRecord.js +++ b/src/nameRecord.js @@ -28,10 +28,17 @@ export function validateName(name) { } if (name.startsWith("-")) { - throw new AppError(422, `Name '${name}' should not start with a hyphen.`); + throw new AppError(422, `Name '${name}' should not start with a hyphen -.`); } if (name.endsWith("-")) { - throw new AppError(422, `Name '${name}' should not start with a hyphen.`); + throw new AppError(422, `Name '${name}' should not start with a hyphen -.`); + } + + if (name.includes("_")) { + throw new AppError( + 422, + `Name '${name}' should not include an underscore _.` + ); } } diff --git a/test/app.test.js b/test/app.test.js index 02ae124..ed6698b 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -144,6 +144,17 @@ describe("Nostr NIP 05 API tests", () => { .expect(422); }); + it("should fail if the name includes an underscore", async () => { + const userData = createUserData({ name: "aa_" }); + + await request(app) + .post("/api/names") + .set("Host", "nos.social") + .set("Authorization", `Nostr ${nip98PostAuthToken}`) + .send(userData) + .expect(422); + }); + it("should fail if the name is not found", async () => { await request(app) .get("/.well-known/nostr.json")