Skip to content

Commit

Permalink
[cli] Fix team validation bug where you are apart of a team (#10092)
Browse files Browse the repository at this point in the history
When consolidating the deployment team validation, a bug was introduced where the command would error if the user was currently using a team. The logic was meant to copy the logic in `getDeploymentByIdOrURL()`: https://github.com/vercel/vercel/blob/main/packages/cli/src/util/deploy/get-deployment-by-id-or-url.ts#L80.
  • Loading branch information
Chris Barber committed Jun 12, 2023
1 parent c438bbb commit d61a1a7
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-carrots-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vercel': patch
---

[cli] Fix team validation bug where you are apart of a team
4 changes: 1 addition & 3 deletions packages/cli/src/util/projects/get-project-by-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export default async function getProjectByDeployment({
err.code = 'ERR_INVALID_TEAM';
throw err;
}
}

if (team) {
} else if (team) {
const err: NodeJS.ErrnoException = new Error(
`Deployment doesn't belong to current team ${chalk.bold(contextName)}`
);
Expand Down
104 changes: 104 additions & 0 deletions packages/cli/test/unit/util/projects/get-project-by-deployment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { client } from '../../../mocks/client';
import getProjectByDeployment from '../../../../src/util/projects/get-project-by-deployment';
import { useTeams } from '../../../mocks/team';
import { useUser } from '../../../mocks/user';
import { useDeployment } from '../../../mocks/deployment';
import { defaultProject, useProject } from '../../../mocks/project';

describe('getProjectByDeployment', () => {
it('should get project and deployment', async () => {
const user = useUser();
const { project: p } = useProject({
...defaultProject,
id: 'foo',
name: 'foo',
});
const d = useDeployment({
creator: user,
createdAt: Date.now(),
project: p,
});

const { deployment, project } = await getProjectByDeployment({
client,
deployId: d.id,
output: client.output,
});

expect(project.id).toBe(p.id);
expect(deployment.id).toBe(d.id);
});

it('should get project and deployment associated to a team', async () => {
const [team] = useTeams('team_dummy');
const user = useUser();
const { project: p } = useProject({
...defaultProject,
id: 'foo',
name: 'foo',
});
const d = useDeployment({
creator: {
id: team.id,
name: team.name,
email: user.email,
username: team.slug,
},
createdAt: Date.now(),
project: p,
});

client.config.currentTeam = team.id;
d.team = team;

const { deployment, project } = await getProjectByDeployment({
client,
deployId: d.id,
output: client.output,
});

expect(project.id).toBe(p.id);
expect(deployment.id).toBe(d.id);
});

it("should error if deployment team doesn't match current user's team", async () => {
const [team] = useTeams('team_dummy');
const user = useUser();
const { project: p } = useProject({
...defaultProject,
id: 'foo',
name: 'foo',
});
const d = useDeployment({
creator: {
id: team.id,
name: team.name,
email: user.email,
username: team.slug,
},
createdAt: Date.now(),
project: p,
});

client.config.currentTeam = team.id;

await expect(
getProjectByDeployment({
client,
deployId: d.id,
output: client.output,
})
).rejects.toThrowError("Deployment doesn't belong to current team");

client.config.currentTeam = undefined;
d.team = team;

await expect(
getProjectByDeployment({
client,
deployId: d.id,
output: client.output,
})
).rejects.toThrowError('Deployment belongs to a different team');
});
});

0 comments on commit d61a1a7

Please sign in to comment.