1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
#!/usr/bin/env bats
load helpers
@test "add-flags-order-verification" {
run_buildah 125 add container1 -q /tmp/container1
check_options_flag_err "-q"
run_buildah 125 add container1 --chown /tmp/container1 --quiet
check_options_flag_err "--chown"
run_buildah 125 add container1 /tmp/container1 --quiet
check_options_flag_err "--quiet"
}
@test "add-local-plain" {
createrandom ${TEST_SCRATCH_DIR}/randomfile
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
run_buildah from $WITH_POLICY_JSON scratch
cid=$output
run_buildah mount $cid
root=$output
mkdir $root/subdir $root/other-subdir
# Copy a file to the working directory
run_buildah config --workingdir=/ $cid
run_buildah add --retry 4 --retry-delay 4s $cid ${TEST_SCRATCH_DIR}/randomfile
# Copy a file to a specific subdirectory
run_buildah add $cid ${TEST_SCRATCH_DIR}/randomfile /subdir
# Copy two files to a specific subdirectory
run_buildah add $cid ${TEST_SCRATCH_DIR}/randomfile ${TEST_SCRATCH_DIR}/other-randomfile /other-subdir
# Copy two files to a specific location, which succeeds because we can create it as a directory.
run_buildah add $cid ${TEST_SCRATCH_DIR}/randomfile ${TEST_SCRATCH_DIR}/other-randomfile /notthereyet-subdir
# Copy two files to a specific location, which fails because it's not a directory.
run_buildah 125 add $cid ${TEST_SCRATCH_DIR}/randomfile ${TEST_SCRATCH_DIR}/other-randomfile /randomfile
# Copy a file to a different working directory
run_buildah config --workingdir=/cwd $cid
run_buildah add $cid ${TEST_SCRATCH_DIR}/randomfile
run_buildah unmount $cid
run_buildah commit $WITH_POLICY_JSON $cid containers-storage:new-image
run_buildah rm $cid
run_buildah from $WITH_POLICY_JSON new-image
newcid=$output
run_buildah mount $newcid
newroot=$output
test -s $newroot/randomfile
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/randomfile
test -s $newroot/subdir/randomfile
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/subdir/randomfile
test -s $newroot/other-subdir/randomfile
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/other-subdir/randomfile
test -s $newroot/other-subdir/other-randomfile
cmp ${TEST_SCRATCH_DIR}/other-randomfile $newroot/other-subdir/other-randomfile
test -d $newroot/cwd
test -s $newroot/cwd/randomfile
cmp ${TEST_SCRATCH_DIR}/randomfile $newroot/cwd/randomfile
run_buildah rm $newcid
}
@test "add-local-archive" {
createrandom ${TEST_SCRATCH_DIR}/randomfile
createrandom ${TEST_SCRATCH_DIR}/other-randomfile
run_buildah from $WITH_POLICY_JSON scratch
cid=$output
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/random1
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/random2
tar -c -C ${TEST_SCRATCH_DIR} -f ${TEST_SCRATCH_DIR}/tarball1.tar random1 random2
mkdir ${TEST_SCRATCH_DIR}/tarball2
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball2/tarball2.random1
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball2/tarball2.random2
tar -c -C ${TEST_SCRATCH_DIR} -z -f ${TEST_SCRATCH_DIR}/tarball2.tar.gz tarball2
mkdir ${TEST_SCRATCH_DIR}/tarball3
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball3/tarball3.random1
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball3/tarball3.random2
tar -c -C ${TEST_SCRATCH_DIR} -j -f ${TEST_SCRATCH_DIR}/tarball3.tar.bz2 tarball3
mkdir ${TEST_SCRATCH_DIR}/tarball4
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball4/tarball4.random1
dd if=/dev/urandom bs=1024 count=4 of=${TEST_SCRATCH_DIR}/tarball4/tarball4.random2
tar -c -C ${TEST_SCRATCH_DIR} -j -f ${TEST_SCRATCH_DIR}/tarball4.tar.bz2 tarball4
# Add the files to the working directory, which should extract them all.
run_buildah config --workingdir=/ $cid
run_buildah add $cid ${TEST_SCRATCH_DIR}/tarball1.tar
run_buildah add $cid ${TEST_SCRATCH_DIR}/tarball2.tar.gz
run_buildah add $cid ${TEST_SCRATCH_DIR}/tarball3.tar.bz2
run_buildah add $cid ${TEST_SCRATCH_DIR}/tarball4.tar.bz2
run_buildah commit $WITH_POLICY_JSON $cid containers-storage:new-image
run_buildah rm $cid
run_buildah from $WITH_POLICY_JSON new-image
newcid=$output
run_buildah mount $newcid
newroot=$output
test -s $newroot/random1
cmp ${TEST_SCRATCH_DIR}/random1 $newroot/random1
test -s $newroot/random2
cmp ${TEST_SCRATCH_DIR}/random2 $newroot/random2
test -s $newroot/tarball2/tarball2.random1
cmp ${TEST_SCRATCH_DIR}/tarball2/tarball2.random1 $newroot/tarball2/tarball2.random1
test -s $newroot/tarball2/tarball2.random2
cmp ${TEST_SCRATCH_DIR}/tarball2/tarball2.random2 $newroot/tarball2/tarball2.random2
test -s $newroot/tarball3/tarball3.random1
cmp ${TEST_SCRATCH_DIR}/tarball3/tarball3.random1 $newroot/tarball3/tarball3.random1
test -s $newroot/tarball3/tarball3.random2
cmp ${TEST_SCRATCH_DIR}/tarball3/tarball3.random2 $newroot/tarball3/tarball3.random2
test -s $newroot/tarball4/tarball4.random1
cmp ${TEST_SCRATCH_DIR}/tarball4/tarball4.random1 $newroot/tarball4/tarball4.random1
test -s $newroot/tarball4/tarball4.random2
cmp ${TEST_SCRATCH_DIR}/tarball4/tarball4.random2 $newroot/tarball4/tarball4.random2
}
@test "add single file creates absolute path with correct permissions" {
_prefetch ubuntu
imgName=ubuntu-image
createrandom ${TEST_SCRATCH_DIR}/distutils.cfg
permission=$(stat -c "%a" ${TEST_SCRATCH_DIR}/distutils.cfg)
run_buildah from --quiet $WITH_POLICY_JSON ubuntu
cid=$output
run_buildah add $cid ${TEST_SCRATCH_DIR}/distutils.cfg /usr/lib/python3.7/distutils
run_buildah run $cid stat -c "%a" /usr/lib/python3.7/distutils
expect_output $permission
run_buildah commit $WITH_POLICY_JSON $cid containers-storage:${imgName}
run_buildah rm $cid
run_buildah from --quiet $WITH_POLICY_JSON ${imgName}
newcid=$output
run_buildah run $newcid stat -c "%a" /usr/lib/python3.7/distutils
expect_output $permission
}
@test "add single file creates relative path with correct permissions" {
_prefetch ubuntu
imgName=ubuntu-image
createrandom ${TEST_SCRATCH_DIR}/distutils.cfg
permission=$(stat -c "%a" ${TEST_SCRATCH_DIR}/distutils.cfg)
run_buildah from --quiet $WITH_POLICY_JSON ubuntu
cid=$output
run_buildah add $cid ${TEST_SCRATCH_DIR}/distutils.cfg lib/custom
run_buildah run $cid stat -c "%a" lib/custom
expect_output $permission
run_buildah commit $WITH_POLICY_JSON $cid containers-storage:${imgName}
run_buildah rm $cid
run_buildah from --quiet $WITH_POLICY_JSON ${imgName}
newcid=$output
run_buildah run $newcid stat -c "%a" lib/custom
expect_output $permission
}
@test "add with chown" {
_prefetch busybox
createrandom ${TEST_SCRATCH_DIR}/randomfile
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --chown bin:bin $cid ${TEST_SCRATCH_DIR}/randomfile /tmp/random
run_buildah run $cid ls -l /tmp/random
expect_output --substring bin.*bin
}
@test "add with chmod" {
_prefetch busybox
createrandom ${TEST_SCRATCH_DIR}/randomfile
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --chmod 777 $cid ${TEST_SCRATCH_DIR}/randomfile /tmp/random
run_buildah run $cid ls -l /tmp/random
expect_output --substring rwxrwxrwx
}
@test "add url" {
_prefetch busybox
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add $cid https://github.com/containers/buildah/raw/main/README.md
run_buildah run $cid ls /README.md
run_buildah add $cid https://github.com/containers/buildah/raw/main/README.md /home
run_buildah run $cid ls /home/README.md
}
@test "add relative" {
# make sure we don't get thrown by relative source locations
_prefetch busybox
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add $cid deny.json /
run_buildah run $cid ls /deny.json
run_buildah add $cid ./docker.json /
run_buildah run $cid ls /docker.json
run_buildah add $cid tools/Makefile /
run_buildah run $cid ls /Makefile
}
@test "add --ignorefile" {
mytest=${TEST_SCRATCH_DIR}/mytest
mkdir -p ${mytest}
touch ${mytest}/mystuff
touch ${mytest}/source.go
mkdir -p ${mytest}/notmystuff
touch ${mytest}/notmystuff/notmystuff
cat > ${mytest}/.ignore << _EOF
*.go
.ignore
notmystuff
_EOF
expect="
stuff
stuff/mystuff"
run_buildah from $WITH_POLICY_JSON scratch
cid=$output
run_buildah 125 copy --ignorefile ${mytest}/.ignore $cid ${mytest} /stuff
expect_output -- "Error: --ignorefile option requires that you specify a context dir using --contextdir" "container file list"
run_buildah add --contextdir=${mytest} --ignorefile ${mytest}/.ignore $cid ${mytest} /stuff
run_buildah mount $cid
mnt=$output
run find $mnt -printf "%P\n"
filelist=$(LC_ALL=C sort <<<"$output")
run_buildah umount $cid
expect_output --from="$filelist" "$expect" "container file list"
}
@test "add quietly" {
_prefetch busybox
createrandom ${TEST_SCRATCH_DIR}/randomfile
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --quiet $cid ${TEST_SCRATCH_DIR}/randomfile /tmp/random
expect_output ""
run_buildah mount $cid
croot=$output
cmp ${TEST_SCRATCH_DIR}/randomfile ${croot}/tmp/random
}
@test "add from container" {
_prefetch busybox
createrandom ${TEST_SCRATCH_DIR}/randomfile
run_buildah from --quiet $WITH_POLICY_JSON busybox
from=$output
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --quiet $from ${TEST_SCRATCH_DIR}/randomfile /tmp/random
expect_output ""
run_buildah add --quiet $WITH_POLICY_JSON --from $from $cid /tmp/random /tmp/random # absolute path
expect_output ""
run_buildah add --quiet $WITH_POLICY_JSON --from $from $cid tmp/random /tmp/random2 # relative path
expect_output ""
run_buildah mount $cid
croot=$output
cmp ${TEST_SCRATCH_DIR}/randomfile ${croot}/tmp/random
cmp ${TEST_SCRATCH_DIR}/randomfile ${croot}/tmp/random2
}
@test "add from image" {
_prefetch busybox ubuntu
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --quiet $WITH_POLICY_JSON --from ubuntu $cid /etc/passwd /tmp/passwd # should pull the image, absolute path
expect_output ""
run_buildah add --quiet $WITH_POLICY_JSON --from ubuntu $cid etc/passwd /tmp/passwd2 # relative path
expect_output ""
run_buildah from --quiet $WITH_POLICY_JSON ubuntu
ubuntu=$output
run_buildah mount $cid
croot=$output
run_buildah mount $ubuntu
ubuntu=$output
cmp $ubuntu/etc/passwd ${croot}/tmp/passwd
cmp $ubuntu/etc/passwd ${croot}/tmp/passwd2
}
@test "add url with checksum flag" {
_prefetch busybox
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah add --checksum=sha256:4fd3aed66b5488b45fe83dd11842c2324fadcc38e1217bb45fbd28d660afdd39 $cid https://raw.githubusercontent.com/containers/buildah/bf3b55ba74102cc2503eccbaeffe011728d46b20/README.md /
run_buildah run $cid ls /README.md
}
@test "add url with bad checksum" {
_prefetch busybox
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah 125 add --checksum=sha256:0000000000000000000000000000000000000000000000000000000000000000 $cid https://raw.githubusercontent.com/containers/buildah/bf3b55ba74102cc2503eccbaeffe011728d46b20/README.md /
expect_output --substring "unexpected response digest for \"https://raw.githubusercontent.com/containers/buildah/bf3b55ba74102cc2503eccbaeffe011728d46b20/README.md\": sha256:4fd3aed66b5488b45fe83dd11842c2324fadcc38e1217bb45fbd28d660afdd39, want sha256:0000000000000000000000000000000000000000000000000000000000000000"
}
@test "add path with checksum flag" {
_prefetch busybox
createrandom ${TEST_SCRATCH_DIR}/randomfile
run_buildah from --quiet $WITH_POLICY_JSON busybox
cid=$output
run_buildah 125 add --checksum=sha256:0000000000000000000000000000000000000000000000000000000000000000 $cid ${TEST_SCRATCH_DIR}/randomfile /
expect_output --substring "checksum flag is not supported for local sources"
}
@test "add https retry ca" {
createrandom ${TEST_SCRATCH_DIR}/randomfile
mkdir -p ${TEST_SCRATCH_DIR}/private
starthttpd ${TEST_SCRATCH_DIR} "" ${TEST_SCRATCH_DIR}/localhost.crt ${TEST_SCRATCH_DIR}/private/localhost.key
run_buildah from --quiet scratch
cid=$output
run_buildah add --retry-delay=0.142857s --retry=14 --cert-dir ${TEST_SCRATCH_DIR} $cid https://localhost:${HTTP_SERVER_PORT}/randomfile
run_buildah add --retry-delay=0.142857s --retry=14 --tls-verify=false $cid https://localhost:${HTTP_SERVER_PORT}/randomfile
run_buildah 125 add --retry-delay=0.142857s --retry=14 $cid https://localhost:${HTTP_SERVER_PORT}/randomfile
assert "$output" =~ "x509: certificate signed by unknown authority"
stophttpd
run_buildah 125 add --retry-delay=0.142857s --retry=14 --cert-dir ${TEST_SCRATCH_DIR} $cid https://localhost:${HTTP_SERVER_PORT}/randomfile
assert "$output" =~ "retrying in 142.*ms .*14/14.*"
}
@test "add file with IMA xattr" {
if ! getfattr -d -n 'security.ima' /usr/libexec/catatonit/catatonit | grep -q ima; then
skip "catatonit does not have IMA xattr, cannot perform test"
fi
run_buildah from --quiet scratch
cid=$output
# We do not care if the attribute was actually added, as rootless is allowed to discard it.
# Only that the add was actually successful.
run_buildah add $cid /usr/libexec/catatonit/catatonit /catatonit
}
|