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

fix: Enforce repository name length limit in dialogs #171

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/app/components/dialog/CreateMirrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const CreateMirrorDialog = ({
onChange={(e) => setRepoName(e.target.value)}
block
placeholder="e.g. repository-name"
maxLength={100}
/>
<FormControl.Caption>
This is a private mirror of{' '}
Expand Down
1 change: 1 addition & 0 deletions src/app/components/dialog/EditMirrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const EditMirrorDialog = ({
onChange={(e) => setNewMirrorName(e.target.value)}
block
placeholder="e.g. repository-name"
maxLength={100}
/>
<FormControl.Caption>
This is a private mirror of{' '}
Expand Down
4 changes: 2 additions & 2 deletions src/server/repos/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const CreateMirrorSchema = z.object({
forkRepoOwner: z.string(),
forkRepoName: z.string(),
forkId: z.string(),
newRepoName: z.string(),
newRepoName: z.string().max(100),
newBranchName: z.string(),
})

Expand All @@ -17,7 +17,7 @@ export const ListMirrorsSchema = z.object({
export const EditMirrorSchema = z.object({
orgId: z.string(),
mirrorName: z.string(),
newMirrorName: z.string(),
newMirrorName: z.string().max(100),
})

export const DeleteMirrorSchema = z.object({
Expand Down
31 changes: 31 additions & 0 deletions test/server/repos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,35 @@ describe('Repos router', () => {
})
expect(stubbedGit.clone).toHaveBeenCalledTimes(1)
})

it('reject repository names over the character limit', async () => {
const caller = reposRouter.createCaller(createTestContext())

await caller
.createMirror({
forkId: 'test',
orgId: 'test',
forkRepoName: 'fork-test',
forkRepoOwner: 'github',
newBranchName: 'test',
newRepoName: 'a'.repeat(101),
})
.catch((error) => {
expect(error.message).toEqual(
'[\n\
{\n\
"code": "too_big",\n\
"maximum": 100,\n\
"type": "string",\n\
"inclusive": true,\n\
"exact": false,\n\
"message": "String must contain at most 100 character(s)",\n\
"path": [\n\
"newRepoName"\n\
]\n\
}\n\
]',
)
})
})
})
Loading