-
Notifications
You must be signed in to change notification settings - Fork 239
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(dal,sdf): when finding change sets, ensure it belongs to the relevant workspace #5245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ impl SnapshotGraphMigrator { | |
info!("Migrating {} snapshot(s)", open_change_sets.len(),); | ||
|
||
for change_set in open_change_sets { | ||
let mut change_set = ChangeSet::find(ctx, change_set.id) | ||
let mut change_set = ChangeSet::find_across_workspaces(ctx, change_set.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is correct - @zacharyhamm could use a check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's hard to imagine this isn't correct, given the fact that these change set IDs came from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is what we want, yes. The migrator will set up the dal context for the right visibility and tenancy but only after it finds the workspace, so this is definitely necessary |
||
.await? | ||
.ok_or(ChangeSetError::ChangeSetNotFound(change_set.id))?; | ||
if change_set.workspace_id.is_none() || change_set.status == ChangeSetStatus::Failed { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use dal::{ | |
context::TransactionsErrorDiscriminants, DalContext, DalContextBuilder, HistoryActor, | ||
RequestContext, Workspace, WorkspacePk, | ||
}; | ||
use dal::{ChangeSet, ChangeSetStatus, Component}; | ||
use dal::{AccessBuilder, ChangeSet, ChangeSetStatus, Component}; | ||
use dal_test::helpers::{ | ||
create_component_for_default_schema_name_in_default_view, create_user, ChangeSetTestHelpers, | ||
}; | ||
|
@@ -255,6 +255,78 @@ async fn build_from_request_context_limits_to_change_sets_of_current_workspace( | |
.is_err_and(|e| TransactionsErrorDiscriminants::BadWorkspaceAndChangeSet == e.into())); | ||
} | ||
|
||
#[test] | ||
async fn cannot_find_change_set_across_workspaces( | ||
ctx: &mut DalContext, | ||
ctx_builder: DalContextBuilder, | ||
) { | ||
let user_1 = create_user(ctx).await.expect("Unable to create user"); | ||
let user_2 = create_user(ctx).await.expect("Unable to create user"); | ||
let user_1_workspace = | ||
Workspace::new_from_builtin(ctx, WorkspacePk::generate(), "user_1 workspace", "token") | ||
.await | ||
.expect("Unable to create workspace"); | ||
let user_2_workspace = | ||
Workspace::new_from_builtin(ctx, WorkspacePk::generate(), "user_2 workspace", "token") | ||
.await | ||
.expect("Unable to create workspace"); | ||
user_1 | ||
.associate_workspace(ctx, *user_1_workspace.pk()) | ||
.await | ||
.expect("Unable to associate user with workspace"); | ||
user_2 | ||
.associate_workspace(ctx, *user_2_workspace.pk()) | ||
.await | ||
.expect("Unable to associate user with workspace"); | ||
ChangeSetTestHelpers::commit_and_update_snapshot_to_visibility(ctx) | ||
.await | ||
.expect("Unable to set up test data"); | ||
|
||
let request_context = RequestContext { | ||
tenancy: dal::Tenancy::new(*user_2_workspace.pk()), | ||
visibility: dal::Visibility { | ||
change_set_id: user_2_workspace.default_change_set_id(), | ||
}, | ||
history_actor: HistoryActor::User(user_2.pk()), | ||
request_ulid: None, | ||
}; | ||
|
||
let mut user_2_dal_ctx = ctx_builder | ||
.build(request_context) | ||
.await | ||
.expect("built dal ctx for user 2"); | ||
|
||
//create a new change set for user 2 | ||
let user_2_change_set = ChangeSet::fork_head(&user_2_dal_ctx, "user 2") | ||
.await | ||
.expect("could not create change set"); | ||
ChangeSetTestHelpers::commit_and_update_snapshot_to_visibility(&mut user_2_dal_ctx) | ||
.await | ||
.expect("Unable to set up test data"); | ||
|
||
let user_1_tenancy = dal::Tenancy::new(*user_1_workspace.pk()); | ||
let access_builder = AccessBuilder::new(user_1_tenancy, HistoryActor::User(user_1.pk()), None); | ||
|
||
let user_1_dal_context = ctx_builder | ||
.build_head(access_builder) | ||
.await | ||
.expect("could not build dal context"); | ||
|
||
//first, let's ensure we can't find it when using the user 1 dal ctx | ||
let user_2_change_set_unfound = ChangeSet::find(&user_1_dal_context, user_2_change_set.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this change, we would User-1-Workspace-1 would successfully find (and be able to abandon) the change set in User-2's Workspace. |
||
.await | ||
.expect("could not find change set"); | ||
assert!(user_2_change_set_unfound.is_none()); | ||
|
||
// But if we search for the change set across all workspaces, we find it | ||
let user_2_change_set_found_harshly = | ||
ChangeSet::find_across_workspaces(&user_1_dal_context, user_2_change_set.id) | ||
.await | ||
.expect("could not find change set"); | ||
|
||
assert!(user_2_change_set_found_harshly.is_some()); | ||
} | ||
|
||
#[test] | ||
async fn build_from_request_context_allows_change_set_from_workspace_with_access( | ||
ctx: &mut DalContext, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do a similar move here to have a tenancy-scoped version of this method, but not in this PR. Note that scoping this to the workspace breaks all of our integration tests at the moment.