Skip to content

Commit

Permalink
chore: relax username validation to include common special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Feb 24, 2024
1 parent 6830e0e commit 3af2e35
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
10 changes: 2 additions & 8 deletions mods/common/src/connect/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ export const hasUsername = (username: string) =>
username ? true : new BadRequestError("the username is required")

export const isValidUsername = (username: string) => {
if (
username &&
(!Validator.default.isAlphanumeric(username) ||
!Validator.default.isLowercase(username))
) {
return new BadRequestError(
"the username must be a lowercase, alphanumeric, and without spaces"
)
if (username?.includes(" ")) {
return new BadRequestError("the username must not contain spaces")
}
return true
}
Expand Down
4 changes: 1 addition & 3 deletions mods/pgdata/test/agent.mapper.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,7 @@ describe("@routr/pgdata/mappers/agent", () => {
const result = () => new AgentManager(agent).validOrThrowCreate()

// Assert
expect(result).to.throw(
"the username must be a lowercase, alphanumeric, and without spaces"
)
expect(result).to.throw("the username must not contain spaces")
})
})
})
8 changes: 2 additions & 6 deletions mods/pgdata/test/credentials.mapper.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,8 @@ describe("@routr/pgdata/mappers/credentials", () => {
new CredentialsManager(credentials).validOrThrowUpdate()

// Assert
expect(createResult).to.throw(
"the username must be a lowercase, alphanumeric, and without spaces"
)
expect(updateResult).to.throw(
"the username must be a lowercase, alphanumeric, and without spaces"
)
expect(createResult).to.throw("the username must not contain spaces")
expect(updateResult).to.throw("the username must not contain spaces")
})

it("when request is missing the password", () => {
Expand Down
4 changes: 1 addition & 3 deletions mods/pgdata/test/peer.mapper.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ describe("@routr/pgdata/mappers/peer", () => {
const result = () => new PeerManager(peer).validOrThrowCreate()

// Assert
expect(result).to.throw(
"the username must be a lowercase, alphanumeric, and without spaces"
)
expect(result).to.throw("the username must not contain spaces")
})

it("when the request is missing the aor", () => {
Expand Down

0 comments on commit 3af2e35

Please sign in to comment.