Mercurial > crates > nonstick
annotate testharness/install-test-harness.sh @ 165:c4b1e280463c
Make test script really work across platforms (?).
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Mon, 14 Jul 2025 18:56:55 -0400 |
parents | d0bba0117456 |
children | 77470e45e397 |
rev | line source |
---|---|
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
1 #!/bin/sh |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
2 |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
3 set -ex |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
4 |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
5 LINUX_BSD_CONF="/etc/pam.d/nonstick-testharness" |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
6 |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
7 patch_pam_conf() { |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
8 SRC="$1" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
9 DST="$2" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
10 LIB="$3" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
11 sed "s#pam_testharness\.so#$LIB#" <"$SRC" >"$DST" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
12 } |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
13 |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
14 setup_pam_conf() { |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
15 SRC="$1" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
16 case "$(uname -s)" in |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
17 "Linux" | *BSD) |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
18 # For Linux-PAM and OpenPAM, PAM is configured with the per-service files |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
19 # in /etc/pam.d/... |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
20 sudo cp "$SRC" "$LINUX_BSD_CONF" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
21 ;; |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
22 "SunOS") |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
23 # On SunOS, PAM has just the one configuration file, |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
24 # with the service prepended to each line. |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
25 sudo cp /etc/pam.conf /etc/pam.conf.bak |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
26 sed 's/^\([^#]\)/nonstick-testharness \1/' <"$SRC" \ |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
27 | sudo tee -a /etc/pam.conf >/dev/null |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
28 ;; |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
29 *) |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
30 echo "UNKNOWN OS!!!" |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
31 return 1 |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
32 ;; |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
33 esac |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
34 } |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
35 |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
36 cleanup_pam_conf() { |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
37 case "$(uname -s)" in |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
38 "Linux" | *BSD) |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
39 sudo rm "$LINUX_BSD_CONF" |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
40 ;; |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
41 "SunOS") |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
42 sudo mv /etc/pam.conf.bak /etc/pam.conf |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
43 ;; |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
44 esac |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
45 } |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
46 |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
47 HERE="$(dirname -- "$0")" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
48 cd "$HERE" |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
49 cargo build --release |
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
50 |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
51 cleanup() { |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
52 rm -r "$MY_TEMP" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
53 sudo rm -r "$ROOT_TEMP" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
54 cleanup_pam_conf |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
55 } |
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
56 |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
57 MY_TEMP="$(mktemp -d -t nonstick-user-XXXXXX)" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
58 ROOT_TEMP="$(sudo mktemp -d -t nonstick-root-XXXXXX)" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
59 sudo chmod a+rx "$ROOT_TEMP" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
60 PAM_LIBRARY="$ROOT_TEMP/pam_nonstick.so" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
61 sudo cp ../target/release/libnonstick_testharness.so "$PAM_LIBRARY" |
165
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
62 patch_pam_conf ./nonstick_testharness.conf "$MY_TEMP/nonstick-testharness" "$PAM_LIBRARY" |
c4b1e280463c
Make test script really work across platforms (?).
Paul Fisher <paul@pfish.zone>
parents:
164
diff
changeset
|
63 setup_pam_conf "$MY_TEMP/nonstick-testharness" |
164
d0bba0117456
make test script more cross platform?
Paul Fisher <paul@pfish.zone>
parents:
163
diff
changeset
|
64 trap cleanup EXIT |
163
a75a66cb4181
Add end-to-end tests; fix issues found by tests.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
65 "$@" && echo "SUCCESS!!!" || echo "FAILURE: $?" |