Skip to content

Test overwrite_existing apparent symlink dereferencing #2008

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
70 changes: 70 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ jobs:
- macos-latest
- ubuntu-latest
- ubuntu-24.04-arm
fail-fast: false

runs-on: ${{ matrix.os }}

Expand All @@ -184,6 +185,74 @@ jobs:
- name: Check that tracked archives are up to date
run: git diff --exit-code # If this fails, the fix is usually to commit a regenerated archive.

# TODO(integration): Remove all or at least most test-ext4-casefold jobs prior to merging #2008.
test-ext4-casefold:
strategy:
matrix:
# `--test-threads` operand
parallel-tests:
- 1 # Never fails.
- 2 # Usually fails.
- 3 # Almost never fails, somehow!
- 4 # Usually fails.
# Duplicate jobs
rep: [A, B, C, D, E, F, G]
fail-fast: false

runs-on: ubuntu-latest

steps:
- name: Warn if we could use tmpfs mounted with `-o casefold` instead
run: |
case "$(cat </sys/fs/tmpfs/features/casefold || :)" in
supported)
echo '::warning:: The runner OS supports case-folding tmpfs, which may be preferable.'
;;
esac
- name: Set up casefold directory
run: |
set -ux
dd if=/dev/zero of=~/ext4-casefold.img bs=100M count=150
mkfs.ext4 -O casefold -- ~/ext4-casefold.img
mkdir -- ~/ext4-casefold
sudo mount -- ~/ext4-casefold.img ~/ext4-casefold
sudo chown -- "$USER" ~/ext4-casefold
mkdir -- ~/ext4-casefold/icase
chattr +F -- ~/ext4-casefold/icase
- name: Arrange to map workspace and TMPDIR in all subsequent steps
run: |
set -ux
mkdir -- ~/ext4-casefold/icase/{workspace,tmp}
sudo mount --rbind -- ~/ext4-casefold/icase/workspace .
printf 'TMPDIR=%s\n' ~/ext4-casefold/icase/tmp >> "$GITHUB_ENV"
- name: Verify case folding in workspace and TMPDIR
run: |
set -ux
shopt -s nullglob
verify() {
touch a A
files=(?)
test "${#files[@]}" -eq 1
rm a
}
verify
(cd -- "$TMPDIR"; verify)
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@v2
with:
tool: nextest
- name: More writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed reps
run: |
# Prepend leading digits "24" to the upper bound of the label range.
sed -Ei 's/^(#\[test_matrix\(0\.\.=)([[:digit:]]+\)])$/\124\2/' \
gix-worktree-state/tests/state/checkout.rs
- name: Test writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed (nextest)
run: |
cargo nextest run -p gix-worktree-state-tests \
writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed \
--status-level=fail --test-threads=${{ matrix.parallel-tests }}

test-fixtures-windows:
runs-on: windows-latest

Expand Down Expand Up @@ -496,6 +565,7 @@ jobs:
- test
- test-journey
- test-fast
- test-ext4-casefold
- test-fixtures-windows
- test-32bit
- test-32bit-windows-size-doc
Expand Down
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gix-worktree-state/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ symlink = "0.1.0"
once_cell = "1.21.3"

walkdir = "2.3.2"
test-case = "3.3.1"
5 changes: 3 additions & 2 deletions gix-worktree-state/tests/state/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use gix_object::{bstr::ByteSlice, Data};
use gix_testtools::tempfile::TempDir;
use gix_worktree_state::checkout::Collision;
use once_cell::sync::Lazy;
use test_case::test_matrix;

use crate::fixture_path;

Expand Down Expand Up @@ -103,8 +104,8 @@ fn accidental_writes_through_symlinks_are_prevented_if_overwriting_is_forbidden(
}
}

#[test]
fn writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed() {
#[test_matrix(0..=999)]
fn writes_through_symlinks_are_prevented_even_if_overwriting_is_allowed(_i: i32) {
let mut opts = opts_from_probe();
// with overwrite mode
opts.overwrite_existing = true;
Expand Down
Loading