projects/guix·blob java-team · refs

127 lines · 4.1 KiB

1# GNU Guix --- Functional package management for GNU
2# Copyright © 2023 Maxim Cournoyer <[email protected]>
3# Copyright © 2023-2024, 2026 Ludovic Courtès <[email protected]>
4#
5# This file is part of GNU Guix.
6#
7# GNU Guix is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or (at
10# your option) any later version.
11#
12# GNU Guix is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20#
21# Test the 'guix time-machine' command-line utility.
22#
23
24channels_file="channels-test-$$.scm"
25log_file="log-test-$$.log"
26trap "rm -f $channels_file $log_file" EXIT
27
28cat > "$channels_file" <<EOF
29(system "echo rm -rf /")
30%default-channels
31EOF
32
33# This must fail: 'system' is not among the available bindings in the
34# evaluation sandbox.
35guix time-machine -C "$channels_file" && false
36
37cat > "$channels_file" <<EOF
38(use-modules (system foreign))
39%default-channels
40EOF
41
42# Likewise, 'use-modules' is not available.
43guix time-machine -C "$channels_file" && false
44
45# Get 'time-machine' to download a channel file with an untrusted channel.
46# Check that this fails with a "'guix' is not trusted" message.
47cat > "$channels_file" <<EOF
48(use-modules (guix tests http)
49 (guix diagnostics)
50 (guix scripts time-machine))
51
52(define channels
53 '(list (channel
54 (name 'guix)
55 (url "https://example.org/evil/guix.git")
56 (branch "devel")
57 (commit "cabba9e900d2350aef42e65643de78500b2aad06")
58 (introduction
59 (make-channel-introduction
60 "badcafef1d5c170db68aa4bbfb77024fdc468ed3"
61 (openpgp-fingerprint
62 "CABB A9EE 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5"))))))
63
64(with-http-server (list (list 200 (object->string channels)))
65 (let ((error (open-output-string)))
66 (catch 'quit
67 (lambda ()
68 (parameterize ((guix-warning-port error))
69 (guix-time-machine "-C" (%local-url) "--" "describe")
70 (primitive-exit 1)))
71 (lambda _
72 (exit (->bool (string-contains (get-output-string error)
73 "'guix' is not trusted")))))))
74EOF
75guix repl -- "$channels_file"
76
77cat > "$channels_file" <<EOF
78%default-channels
79EOF
80
81# Ensure there are zero trusted channels
82mkdir -p "$XDG_CACHE_HOME/dot-config/guix"
83cat > "$XDG_CACHE_HOME/dot-config/guix/trusted-channels.scm" <<EOF
84(list)
85EOF
86
87# Ignore the user's ~/.config/guix/trusted-channels.scm and ensure this
88# command fails.
89XDG_CONFIG_HOME="$XDG_CACHE_HOME/dot-config" \
90guix time-machine -C "$channels_file" --allow-untrusted-channels=no 2> "$log_file" && false
91grep "'guix' is not trusted" "$log_file"
92
93if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
94then
95 # Ignore the user's ~/.config/guix/trusted-channels.scm. We've ensured
96 # there are no trusted channels so the following command must fail.
97 XDG_CONFIG_HOME="$XDG_CACHE_HOME/dot-config" \
98 guix time-machine \
99 -C swh:1:cnt:003e1e0c1b9b358082201332c926ae54e9549002 \
100 2> "$log_file" \
101 && false
102 grep "'guix' is not trusted" "$log_file"
103fi
104
105if [ -d "$abs_top_srcdir/.git" ] \
106 || guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
107then
108 guix time-machine --version
109else
110 echo "This test requires networking or a local Git checkout; skipping." >&2
111 exit 77
112fi
113
114if [ -d "$abs_top_srcdir/.git" ]
115then
116 # Note: No "file://" prefix because that makes cloning much more expensive
117 # for some reason.
118 EXTRA_OPTIONS="--url=$abs_top_srcdir"
119else
120 EXTRA_OPTIONS=""
121fi
122
123# Visiting a commit older than v0.16.0 must fail (this test is expensive
124# because it clones the whole repository).
125guix time-machine -q --commit=v0.15.0 $EXTRA_OPTIONS -- describe && false
126
127true