-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend: add error variant for access denied, handle when diffing
Some backends, like the one we have at Google, can restrict access to certain files. For such files, if they return a regular `BackendError::ReadObject`, then that will terminate iteration in many cases (e.g. when diffing or listing files). This patch adds a new error variant for them to return instead, plus handling of such errors in diff output. In order to test the feature, I added a new commit backend that returns the new `ReadAccessDenied` error when the caller tries to read certain objects.
- Loading branch information
1 parent
3090adf
commit 9741dcc
Showing
10 changed files
with
339 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2024 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::path::Path; | ||
|
||
use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment}; | ||
|
||
fn switch_to_secret_backend(repo_path: &Path) { | ||
std::fs::write( | ||
repo_path | ||
.join(".jj") | ||
.join("repo") | ||
.join("store") | ||
.join("type"), | ||
"secret", | ||
) | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn test_diff() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
std::fs::create_dir(repo_path.join("dir")).unwrap(); | ||
std::fs::write(repo_path.join("a-first"), "foo\n").unwrap(); | ||
std::fs::write(repo_path.join("deleted-secret"), "foo\n").unwrap(); | ||
std::fs::write(repo_path.join("dir").join("secret"), "foo\n").unwrap(); | ||
std::fs::write(repo_path.join("modified-secret"), "foo\n").unwrap(); | ||
std::fs::write(repo_path.join("z-last"), "foo\n").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["new"]); | ||
std::fs::write(repo_path.join("a-first"), "bar\n").unwrap(); | ||
std::fs::remove_file(repo_path.join("deleted-secret")).unwrap(); | ||
std::fs::write(repo_path.join("added-secret"), "bar\n").unwrap(); | ||
std::fs::write(repo_path.join("dir").join("secret"), "bar\n").unwrap(); | ||
std::fs::write(repo_path.join("modified-secret"), "bar\n").unwrap(); | ||
std::fs::write(repo_path.join("z-last"), "bar\n").unwrap(); | ||
|
||
switch_to_secret_backend(&repo_path); | ||
|
||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--color-words"]); | ||
insta::assert_snapshot!(stdout.replace('\\', "/"), @r###" | ||
Modified regular file a-first: | ||
1 1: foobar | ||
Access denied to added-secret: No access | ||
Access denied to deleted-secret: No access | ||
Access denied to dir/secret: No access | ||
Access denied to modified-secret: No access | ||
Modified regular file z-last: | ||
1 1: foobar | ||
"###); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--summary"]); | ||
insta::assert_snapshot!(stdout.replace('\\', "/"), @r###" | ||
M a-first | ||
A added-secret | ||
D deleted-secret | ||
M dir/secret | ||
M modified-secret | ||
M z-last | ||
"###); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--types"]); | ||
insta::assert_snapshot!(stdout.replace('\\', "/"), @r###" | ||
FF a-first | ||
-F added-secret | ||
F- deleted-secret | ||
FF dir/secret | ||
FF modified-secret | ||
FF z-last | ||
"###); | ||
let assert = test_env | ||
.jj_cmd(&repo_path, &["diff", "--stat"]) | ||
.assert() | ||
.failure(); | ||
insta::assert_snapshot!(get_stdout_string(&assert).replace('\\', "/"), @""); | ||
insta::assert_snapshot!(get_stderr_string(&assert), @r###" | ||
Error: Access denied to read object 5716ca5987cbf97d6bb54920bea6adde242d87e6 of type file | ||
Caused by: No access | ||
Hint: The `--color-words` format supports access-restricted paths. | ||
"###); | ||
let assert = test_env | ||
.jj_cmd(&repo_path, &["diff", "--git"]) | ||
.assert() | ||
.failure(); | ||
insta::assert_snapshot!(get_stdout_string(&assert).replace('\\', "/"), @r###" | ||
diff --git a/a-first b/a-first | ||
index 257cc5642c...5716ca5987 100644 | ||
--- a/a-first | ||
+++ b/a-first | ||
@@ -1,1 +1,1 @@ | ||
-foo | ||
+bar | ||
"###); | ||
insta::assert_snapshot!(get_stderr_string(&assert), @r###" | ||
Error: Access denied to read object 5716ca5987cbf97d6bb54920bea6adde242d87e6 of type file | ||
Caused by: No access | ||
Hint: The `--color-words` format supports access-restricted paths. | ||
"###); | ||
|
||
// TODO: Test external tool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.