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

Add tests for GuardedResources: Workspace, WorkspaceInstance and WorkspaceLog (1/2) #10939

Merged
merged 3 commits into from
Jun 28, 2022

Conversation

geropl
Copy link
Member

@geropl geropl commented Jun 27, 2022

Description

This PR adds tests for workspace-like GuardedResources: Workspace, WorkspaceInstance and WorkspaceLog.
It's a precursor for a follow-up PR.

Related Issue(s)

Context: #10696

How to test

  • cd components/server && yarn test

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview

@geropl geropl requested a review from a team June 27, 2022 15:25
@geropl geropl changed the title Add tests for GuardedResources: Workspace, WorkspaceInstance and WorkspaceLog Add tests for GuardedResources: Workspace, WorkspaceInstance and WorkspaceLog (1/2) Jun 27, 2022
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Jun 27, 2022
@@ -1539,7 +1539,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}
traceWI(ctx, { instanceId: instance.id });
const teamMembers = await this.getTeamMembersByProject(workspace.projectId);
await this.guardAccess({ kind: "workspaceInstance", subject: instance, workspace, teamMembers }, "get");
await this.guardAccess({ kind: "workspaceLog", subject: workspace, teamMembers }, "get");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, because image build logs should be the same access-level as prebuild logs.

@@ -1664,7 +1664,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
const wsiPromise = this.workspaceDb.trace(ctx).findInstanceById(instanceId);
const teamMembers = await this.getTeamMembersByProject(ws.projectId);

await this.guardAccess({ kind: "workspace", subject: ws, teamMembers }, "get");
await this.guardAccess({ kind: "workspaceLog", subject: ws, teamMembers }, "get");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For workspace logs we have a separate resource kind "workspaceLog".

@jankeromnes
Copy link
Contributor

jankeromnes commented Jun 28, 2022

This PR adds tests for workspace-like GuardedResources: Workspace, WorkspaceInstance and WorkspaceLog.
It's a precursor for a follow-up PR.

Hey, that's awesome, many thanks for adding tests @geropl! 🥇 💯

How to test

If the tests already run as part of the build, I guess this could be simply: "1. Should build:"

Release Notes

added tests for GuardedResources Workspace, WorkspaceInstance and WorkspaceLog

FYI, I think this should rather be NONE, because we've decided to make release notes more customer-centric and less technical-detail-oriented. 💡

Source: Slack announcement (internal)

@geropl
Copy link
Member Author

geropl commented Jun 28, 2022

If the tests already run as part of the build, I guess this could be simply: "1. Should build:"

Yes, or (cd components/server && yarn test). 👍

FYI, I think this should rather be NONE, because we've decided to make release notes more customer-centric and less technical-detail-oriented. bulb

Thx, was not aware - adjusted.

workspace = resource.workspace;
break;
default:
// We do not handle resource kinds here!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We do not handle resource kinds here!
// We do not handle other resource kinds here!

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks!

Code looks good to me, especially if it does what we expect it to. 👍

Holding because of two (optional) open questions:

  • Shouldn't we run a new build with-preview to give the new guards a quick sanity check?
  • I see in the build logs that workspaceLikeResourceGuardsCanAcccess ran and did pass ✅ however, out of abundance of caution, did you observe actual failures? (E.g. while developing, or by flipping one random expected boolean to see if the test actually fails)

/hold

@roboquat roboquat merged commit 2ab9b97 into main Jun 28, 2022
@roboquat roboquat deleted the gpl/guarded-prebuild-1 branch June 28, 2022 14:58
@jankeromnes
Copy link
Contributor

jankeromnes commented Jun 28, 2022

Lol, and my hold? 😆

@geropl
Copy link
Member Author

geropl commented Jun 28, 2022

Lol, and my hold? laughing

Wow, never saw that happen 🙈

however, out of abundance of caution, did you observe actual failures? (E.g. while developing, or by flipping one random expected boolean to see if the test actually fails)

Yes, developed against my expectations - which did not always matched reality at first 😉 👍

@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production do-not-merge/hold release-note-none size/XL team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants