Skip to content

Commit fc4e374

Browse files
Switch to another user than root to run FreeBSD tests
1 parent c094bb9 commit fc4e374

File tree

4 files changed

+63
-56
lines changed

4 files changed

+63
-56
lines changed

.cirrus.yml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,15 @@ task:
55
name: FreeBSD
66
freebsd_instance:
77
image: freebsd-13-0-release-amd64
8-
setup_script:
9-
- pkg install -y git gmake bash
10-
- echo "========="
11-
- echo "Acquire tags for the repo"
12-
- git fetch --no-tags --prune --depth=1 origin +refs/tags/*:refs/tags/*
13-
- echo "========="
14-
- echo "Display the current git status"
15-
- git status
16-
- git describe
17-
- echo "========="
18-
- echo "Prep cargo dirs"
19-
- mkdir -p ~/.cargo/{registry,git}
20-
- echo "========="
21-
- echo "Install Rustup using ./rustup-init.sh"
22-
- sh rustup-init.sh --default-toolchain=stable --profile=minimal -y
23-
# It's the equivalent of `source`
24-
- . $HOME/.cargo/env
25-
- echo "========="
26-
- echo "Ensure we have the components we need"
27-
- rustup component add rustfmt
28-
- rustup component add clippy
29-
- echo "========="
30-
- echo "Run the freebsd check"
31-
- unset SKIP_TESTS
32-
- export LIBZ_SYS_STATIC=1
33-
- export CARGO_BUILD_JOBS=1
34-
- export TARGET="x86_64-unknown-freebsd"
35-
- bash ci/run.bash
8+
setup_script: |
9+
pkg install -y git gmake bash
10+
echo "========="
11+
echo "create non-root user and log into it"
12+
pw group add -n tester
13+
pw user add -n tester -g tester -s `which bash`
14+
pw user mod tester -d `pwd`
15+
chown -R tester .
16+
sudo -u tester bash ci/cirrus-templates/script.bash
3617
upload_to_s3:
3718
only_if: $CIRRUS_BRANCH == "stable"
3819
script:

ci/cirrus-templates/freebsd.yaml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,15 @@ task:
55
name: FreeBSD
66
freebsd_instance:
77
image: freebsd-13-0-release-amd64
8-
setup_script:
9-
- pkg install -y git gmake bash
10-
- echo "========="
11-
- echo "Acquire tags for the repo"
12-
- git fetch --no-tags --prune --depth=1 origin +refs/tags/*:refs/tags/*
13-
- echo "========="
14-
- echo "Display the current git status"
15-
- git status
16-
- git describe
17-
- echo "========="
18-
- echo "Prep cargo dirs"
19-
- mkdir -p ~/.cargo/{registry,git}
20-
- echo "========="
21-
- echo "Install Rustup using ./rustup-init.sh"
22-
- sh rustup-init.sh --default-toolchain=stable --profile=minimal -y
23-
# It's the equivalent of `source`
24-
- . $HOME/.cargo/env
25-
- echo "========="
26-
- echo "Ensure we have the components we need"
27-
- rustup component add rustfmt
28-
- rustup component add clippy
29-
- echo "========="
30-
- echo "Run the freebsd check"
31-
- unset SKIP_TESTS
32-
- export LIBZ_SYS_STATIC=1
33-
- export CARGO_BUILD_JOBS=1
34-
- export TARGET="x86_64-unknown-freebsd"
35-
- bash ci/run.bash
8+
setup_script: |
9+
pkg install -y git gmake bash
10+
echo "========="
11+
echo "create non-root user and log into it"
12+
pw group add -n tester
13+
pw user add -n tester -g tester -s `which bash`
14+
pw user mod tester -d `pwd`
15+
chown -R tester .
16+
sudo -u tester bash ci/cirrus-templates/script.bash
3617
upload_to_s3:
3718
only_if: $CIRRUS_BRANCH == "stable"
3819
script:

ci/cirrus-templates/script.bash

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# First, we check that this script is not run as root because it would fail tests.
6+
if [ "root" == "$(whoami)" ]; then exit 1; fi
7+
8+
echo "========="
9+
echo "Acquire tags for the repo"
10+
11+
git fetch --no-tags --prune --depth=1 origin +refs/tags/*:refs/tags/*
12+
13+
echo "========="
14+
echo "Display the current git status"
15+
16+
git status
17+
git describe
18+
19+
echo "========="
20+
echo "Prep cargo dirs"
21+
22+
mkdir -p ~/.cargo/{registry,git}
23+
24+
echo "========="
25+
echo "Install Rustup using ./rustup-init.sh"
26+
27+
sh rustup-init.sh --default-toolchain=stable --profile=minimal -y
28+
# It's the equivalent of `source`
29+
source "$HOME"/.cargo/env
30+
31+
echo "========="
32+
echo "Ensure we have the components we need"
33+
34+
rustup component add rustfmt
35+
rustup component add clippy
36+
37+
echo "========="
38+
echo "Run the freebsd check"
39+
40+
unset SKIP_TESTS
41+
export LIBZ_SYS_STATIC=1
42+
export CARGO_BUILD_JOBS=1
43+
export TARGET="x86_64-unknown-freebsd"
44+
bash ci/run.bash

tests/cli-paths.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export PATH="$HOME/apple/bin"
109109
});
110110
}
111111

112+
// This test should NOT be run as root!
112113
#[test]
113114
fn install_errors_when_rc_cannot_be_updated() {
114115
clitools::setup(Scenario::Empty, &|config| {

0 commit comments

Comments
 (0)