Skip to content

Commit

Permalink
fix test errors in "relax restriction on handle length in PDS" (blues…
Browse files Browse the repository at this point in the history
…ky-social#2410)

* relax restriction on handle length in PDS.

* add test to validate restriction on handle length.

* make fmt

* resolve test issues with too-long handles

* attempt to resolve appview test issues with too-long handles

---------

Co-authored-by: itaru2622 <[email protected]>
  • Loading branch information
bnewbold and itaru2622 authored Apr 16, 2024
1 parent d4d5a6e commit a40b054
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Array [
"avatar": "https://bsky.public.url/img/avatar/plain/user(5)/cids(0)@jpeg",
"did": "user(4)",
"displayName": "Latoya Windler",
"handle": "carolina-mcdermott77.test",
"handle": "carolina-mcderm77.test",
"indexedAt": "1970-01-01T00:00:00.000Z",
"labels": Array [],
"viewer": Object {
Expand Down Expand Up @@ -115,7 +115,7 @@ Array [
"avatar": "https://bsky.public.url/img/avatar/plain/user(5)/cids(0)@jpeg",
"did": "user(4)",
"displayName": "Latoya Windler",
"handle": "carolina-mcdermott77.test",
"handle": "carolina-mcderm77.test",
"viewer": Object {
"blockedBy": false,
"muted": false,
Expand Down
6 changes: 3 additions & 3 deletions packages/bsky/tests/views/actor-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe.skip('pds actor search views', () => {
'shane-torphy52.test', // Sadie Carter
'aliya-hodkiewicz.test', // Carlton Abernathy IV
'carlos6.test',
'carolina-mcdermott77.test',
'carolina-mcderm77.test',
]

shouldContain.forEach((handle) => expect(handles).toContain(handle))
Expand Down Expand Up @@ -150,7 +150,7 @@ describe.skip('pds actor search views', () => {
'shane-torphy52.test', // Sadie Carter
'aliya-hodkiewicz.test', // Carlton Abernathy IV
'carlos6.test',
'carolina-mcdermott77.test',
'carolina-mcderm77.test',
]

shouldContain.forEach((handle) => expect(handles).toContain(handle))
Expand Down Expand Up @@ -246,7 +246,7 @@ describe.skip('pds actor search views', () => {
)
const handles = result.data.actors.map((u) => u.handle)
expect(handles).toContain('carlos6.test')
expect(handles).toContain('carolina-mcdermott77.test')
expect(handles).toContain('carolina-mcderm77.test')
expect(handles).not.toContain('cara-wiegand69.test')
})
})
10 changes: 5 additions & 5 deletions packages/dev-env/src/seed/users-bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ const users = [
{ handle: 'kiana-schmitt39.test', displayName: null },
{ handle: 'rhianna-stamm29.test', displayName: null },
{ handle: 'tiara-mohr.test', displayName: null },
{ handle: 'eleazar-balistreri70.test', displayName: 'Gordon Weissnat' },
{ handle: 'eleazar-balist70.test', displayName: 'Gordon Weissnat' },
{ handle: 'bettie-bogisich96.test', displayName: null },
{ handle: 'lura-jacobi55.test', displayName: null },
{ handle: 'santa-hermann78.test', displayName: 'Melissa Johnson' },
{ handle: 'dylan61.test', displayName: null },
{ handle: 'ryley-kerluke.test', displayName: 'Alexander Purdy' },
{ handle: 'moises-bins8.test', displayName: null },
{ handle: 'angelita-schaefer27.test', displayName: null },
{ handle: 'angelita-schaef27.test', displayName: null },
{ handle: 'natasha83.test', displayName: 'Dean Romaguera' },
{ handle: 'sydni48.test', displayName: null },
{ handle: 'darrion91.test', displayName: 'Jeanette Weimann' },
Expand Down Expand Up @@ -182,10 +182,10 @@ const users = [
{ handle: 'melyna-zboncak.test', displayName: null },
{ handle: 'rowan-parisian.test', displayName: 'Mr. Veronica Feeney' },
{ handle: 'lois-blanda20.test', displayName: 'Todd Rolfson' },
{ handle: 'turner-balistreri76.test', displayName: null },
{ handle: 'turner-bali76.test', displayName: null },
{ handle: 'dee-hoppe65.test', displayName: null },
{ handle: 'nikko-rosenbaum60.test', displayName: 'Joann Gutmann' },
{ handle: 'cornell-romaguera53.test', displayName: null },
{ handle: 'cornell-rom53.test', displayName: null },
{ handle: 'zack3.test', displayName: null },
{ handle: 'fredrick41.test', displayName: 'Julius Kreiger' },
{ handle: 'elwyn62.test', displayName: null },
Expand Down Expand Up @@ -223,6 +223,6 @@ const users = [
{ handle: 'nayeli-koss73.test', displayName: 'Johnny Lang' },
{ handle: 'cara-wiegand69.test', displayName: null },
{ handle: 'gideon-ohara51.test', displayName: null },
{ handle: 'carolina-mcdermott77.test', displayName: 'Latoya Windler' },
{ handle: 'carolina-mcderm77.test', displayName: 'Latoya Windler' },
{ handle: 'danyka90.test', displayName: 'Hope Kub' },
]
2 changes: 1 addition & 1 deletion packages/ozone/tests/repo-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('admin repo search view', () => {
const shouldContain = [
'cara-wiegand69.test', // Present despite repo takedown
'carlos6.test',
'carolina-mcdermott77.test',
'carolina-mcderm77.test',
]

shouldContain.forEach((handle) => expect(handles).toContain(handle))
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/handle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const ensureHandleServiceConstraints = (
if (front.length < 3) {
throw new InvalidRequestError('Handle too short', 'InvalidHandle')
}
if (handle.length > 30) {
if (front.length > 18) {
throw new InvalidRequestError('Handle too long', 'InvalidHandle')
}
if (!allowReserved && reservedSubdomains[front]) {
Expand Down
28 changes: 28 additions & 0 deletions packages/pds/tests/handle-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,32 @@ describe('handle validation', () => {
expect(isValidTld('atproto.onion')).toBe(false)
expect(isValidTld('atproto.internal')).toBe(false)
})

it('validates handle length', () => {
const domains = [
'.loooooooooooooooooong-pds-over18chars.mybsky.mydomain.com',
'.test',
]
const expectThrow = (handle: string, err: string) => {
expect(() => ensureHandleServiceConstraints(handle, domains)).toThrow(err)
}
const expectNotThrow = (handle: string, memo: string) => {
expect(() =>
ensureHandleServiceConstraints(handle, domains),
).not.toThrow()
}
expectThrow('usernamepartover18c.test', 'Handle too long')
expectNotThrow(
'u23456789012345678.test',
'safe up to 18 chars in first segment of the handle',
)
expectThrow(
'usernamepartover18c.loooooooooooooooooong-pds-over18chars.mybsky.mydomain.com',
'Handle too long',
)
expectNotThrow(
'u23456789012345678.loooooooooooooooooong-pds-over18chars.mybsky.mydomain.com',
'safe long domain in the handle',
)
})
})
10 changes: 5 additions & 5 deletions packages/pds/tests/seeds/users-bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ const users = [
{ handle: 'kiana-schmitt39.test', displayName: null },
{ handle: 'rhianna-stamm29.test', displayName: null },
{ handle: 'tiara-mohr.test', displayName: null },
{ handle: 'eleazar-balistreri70.test', displayName: 'Gordon Weissnat' },
{ handle: 'eleazar-balist70.test', displayName: 'Gordon Weissnat' },
{ handle: 'bettie-bogisich96.test', displayName: null },
{ handle: 'lura-jacobi55.test', displayName: null },
{ handle: 'santa-hermann78.test', displayName: 'Melissa Johnson' },
{ handle: 'dylan61.test', displayName: null },
{ handle: 'ryley-kerluke.test', displayName: 'Alexander Purdy' },
{ handle: 'moises-bins8.test', displayName: null },
{ handle: 'angelita-schaefer27.test', displayName: null },
{ handle: 'angelita-schaef27.test', displayName: null },
{ handle: 'natasha83.test', displayName: 'Dean Romaguera' },
{ handle: 'sydni48.test', displayName: null },
{ handle: 'darrion91.test', displayName: 'Jeanette Weimann' },
Expand Down Expand Up @@ -199,10 +199,10 @@ const users = [
{ handle: 'melyna-zboncak.test', displayName: null },
{ handle: 'rowan-parisian.test', displayName: 'Mr. Veronica Feeney' },
{ handle: 'lois-blanda20.test', displayName: 'Todd Rolfson' },
{ handle: 'turner-balistreri76.test', displayName: null },
{ handle: 'turner-bali76.test', displayName: null },
{ handle: 'dee-hoppe65.test', displayName: null },
{ handle: 'nikko-rosenbaum60.test', displayName: 'Joann Gutmann' },
{ handle: 'cornell-romaguera53.test', displayName: null },
{ handle: 'cornell-rom53.test', displayName: null },
{ handle: 'zack3.test', displayName: null },
{ handle: 'fredrick41.test', displayName: 'Julius Kreiger' },
{ handle: 'elwyn62.test', displayName: null },
Expand Down Expand Up @@ -240,6 +240,6 @@ const users = [
{ handle: 'nayeli-koss73.test', displayName: 'Johnny Lang' },
{ handle: 'cara-wiegand69.test', displayName: null },
{ handle: 'gideon-ohara51.test', displayName: null },
{ handle: 'carolina-mcdermott77.test', displayName: 'Latoya Windler' },
{ handle: 'carolina-mcderm77.test', displayName: 'Latoya Windler' },
{ handle: 'danyka90.test', displayName: 'Hope Kub' },
]

0 comments on commit a40b054

Please sign in to comment.