Skip to content

Commit

Permalink
Merge pull request #659 from edsantiago/systemtests
Browse files Browse the repository at this point in the history
systemtest - new set of BATS tests for RHEL8 gating
  • Loading branch information
mtrmac authored Jun 4, 2019
2 parents b137741 + 47e7cda commit 6307635
Show file tree
Hide file tree
Showing 11 changed files with 796 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN dnf -y update && dnf install -y make git golang golang-github-cpuguy83-go-md
gnupg \
# OpenShift deps
which tar wget hostname util-linux bsdtar socat ethtool device-mapper iptables tree findutils nmap-ncat e2fsprogs xfsprogs lsof docker iproute \
bats jq podman \
&& dnf clean all

# Install two versions of the registry. The first is an older version that
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,23 @@ install-completions:
shell: build-container
$(CONTAINER_RUN) bash

check: validate test-unit test-integration
check: validate test-unit test-integration test-system

# The tests can run out of entropy and block in containers, so replace /dev/random.
test-integration: build-container
$(CONTAINER_RUN) bash -c 'rm -f /dev/random; ln -sf /dev/urandom /dev/random; SKOPEO_CONTAINER_TESTS=1 BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-integration'

# complicated set of options needed to run podman-in-podman
test-system: build-container
DTEMP=$(shell mktemp -d --tmpdir=/var/tmp podman-tmp.XXXXXX); \
$(CONTAINER_CMD) --privileged --net=host \
-v $$DTEMP:/var/lib/containers:Z \
"$(IMAGE)" \
bash -c 'BUILDTAGS="$(BUILDTAGS)" hack/make.sh test-system'; \
rc=$$?; \
$(RM) -rf $$DTEMP; \
exit $$rc

test-unit: build-container
# Just call (make test unit-local) here instead of worrying about environment differences, e.g. GO15VENDOREXPERIMENT.
$(CONTAINER_RUN) make test-unit-local BUILDTAGS='$(BUILDTAGS)'
Expand Down
18 changes: 18 additions & 0 deletions hack/make/test-system
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

# Before running podman for the first time, make sure
# to set storage to vfs (not overlay): podman-in-podman
# doesn't work with overlay. And, disable mountopt,
# which causes error with vfs.
sed -i \
-e 's/^driver\s*=.*/driver = "vfs"/' \
-e 's/^mountopt/#mountopt/' \
/etc/containers/storage.conf

# Build skopeo, install into /usr/bin
make binary-local ${BUILDTAGS:+BUILDTAGS="$BUILDTAGS"}
make install

# Run tests
SKOPEO_BINARY=/usr/bin/skopeo bats --tap systemtest
19 changes: 19 additions & 0 deletions systemtest/001-basic.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats
#
# Simplest set of skopeo tests. If any of these fail, we have serious problems.
#

load helpers

# Override standard setup! We don't yet trust anything
function setup() {
:
}

@test "skopeo version emits reasonable output" {
run_skopeo --version

expect_output --substring "skopeo version [0-9.]+"
}

# vim: filetype=sh
67 changes: 67 additions & 0 deletions systemtest/010-inspect.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bats
#
# Simplest test for skopeo inspect
#

load helpers

@test "inspect: basic" {
workdir=$TESTDIR/inspect

remote_image=docker://quay.io/libpod/alpine_labels:latest
# Inspect remote source, then pull it. There's a small race condition
# in which the remote image can get updated between the inspect and
# the copy; let's just not worry about it.
run_skopeo inspect $remote_image
inspect_remote=$output

# Now pull it into a directory
run_skopeo copy $remote_image dir:$workdir
expect_output --substring "Getting image source signatures"
expect_output --substring "Writing manifest to image destination"

# Unpacked contents must include a manifest and version
[ -e $workdir/manifest.json ]
[ -e $workdir/version ]

# Now run inspect locally
run_skopeo inspect dir:$workdir
inspect_local=$output

# Each SHA-named file must be listed in the output of 'inspect'
for sha in $(find $workdir -type f | xargs -l1 basename | egrep '^[0-9a-f]{64}$'); do
expect_output --from="$inspect_local" --substring "sha256:$sha" \
"Locally-extracted SHA file is present in 'inspect'"
done

# Simple sanity check on 'inspect' output.
# For each of the given keys (LHS of the table below):
# 1) Get local and remote values
# 2) Sanity-check local value using simple expression
# 3) Confirm that local and remote values match.
#
# The reason for (2) is to make sure that we don't compare bad results
#
# The reason for a hardcoded list, instead of 'jq keys', is that RepoTags
# is always empty locally, but a list remotely.
while read key expect; do
local=$(echo "$inspect_local" | jq -r ".$key")
remote=$(echo "$inspect_remote" | jq -r ".$key")

expect_output --from="$local" --substring "$expect" \
"local $key is sane"

expect_output --from="$remote" "$local" \
"local $key matches remote"
done <<END_EXPECT
Architecture amd64
Created [0-9-]+T[0-9:]+\.[0-9]+Z
Digest sha256:[0-9a-f]{64}
DockerVersion [0-9]+\.[0-9][0-9.-]+
Labels \\\{.*PODMAN.*podman.*\\\}
Layers \\\[.*sha256:.*\\\]
Os linux
END_EXPECT
}

# vim: filetype=sh
79 changes: 79 additions & 0 deletions systemtest/020-copy.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bats
#
# Copy tests
#

load helpers

function setup() {
standard_setup

start_registry reg
}

# From remote, to dir1, to local, to dir2;
# compare dir1 and dir2, expect no changes
@test "copy: dir, round trip" {
local remote_image=docker://busybox:latest
local localimg=docker://localhost:5000/busybox:unsigned

local dir1=$TESTDIR/dir1
local dir2=$TESTDIR/dir2

run_skopeo copy $remote_image dir:$dir1
run_skopeo copy --dest-tls-verify=false dir:$dir1 $localimg
run_skopeo copy --src-tls-verify=false $localimg dir:$dir2

# Both extracted copies must be identical
diff -urN $dir1 $dir2
}

# Same as above, but using 'oci:' instead of 'dir:' and with a :latest tag
@test "copy: oci, round trip" {
local remote_image=docker://busybox:latest
local localimg=docker://localhost:5000/busybox:unsigned

local dir1=$TESTDIR/oci1
local dir2=$TESTDIR/oci2

run_skopeo copy $remote_image oci:$dir1:latest
run_skopeo copy --dest-tls-verify=false oci:$dir1:latest $localimg
run_skopeo copy --src-tls-verify=false $localimg oci:$dir2:latest

# Both extracted copies must be identical
diff -urN $dir1 $dir2
}

# Same image, extracted once with :tag and once without
@test "copy: oci w/ and w/o tags" {
local remote_image=docker://busybox:latest

local dir1=$TESTDIR/dir1
local dir2=$TESTDIR/dir2

run_skopeo copy $remote_image oci:$dir1
run_skopeo copy $remote_image oci:$dir2:withtag

# Both extracted copies must be identical, except for index.json
diff -urN --exclude=index.json $dir1 $dir2

# ...which should differ only in the tag. (But that's too hard to check)
grep '"org.opencontainers.image.ref.name":"withtag"' $dir2/index.json
}

# This one seems unlikely to get fixed
@test "copy: bug 651" {
skip "Enable this once skopeo issue #651 has been fixed"

run_skopeo copy --dest-tls-verify=false \
docker://quay.io/libpod/alpine_labels:latest \
docker://localhost:5000/foo
}

teardown() {
podman rm -f reg

standard_teardown
}

# vim: filetype=sh
32 changes: 32 additions & 0 deletions systemtest/030-local-registry-tls.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats
#
# Confirm that skopeo will push to and pull from a local
# registry with locally-created TLS certificates.
#
load helpers

function setup() {
standard_setup

start_registry --with-cert reg
}

@test "local registry, with cert" {
# Push to local registry...
run_skopeo copy --dest-cert-dir=$TESTDIR/client-auth \
docker://busybox:latest \
docker://localhost:5000/busybox:unsigned

# ...and pull it back out
run_skopeo copy --src-cert-dir=$TESTDIR/client-auth \
docker://localhost:5000/busybox:unsigned \
dir:$TESTDIR/extracted
}

teardown() {
podman rm -f reg

standard_teardown
}

# vim: filetype=sh
78 changes: 78 additions & 0 deletions systemtest/040-local-registry-auth.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bats
#
# Tests with a local registry with auth
#

load helpers

function setup() {
standard_setup

# Remove old/stale cred file
_cred_dir=$TESTDIR/credentials
export XDG_RUNTIME_DIR=$_cred_dir
mkdir -p $_cred_dir/containers
rm -f $_cred_dir/containers/auth.json

# Start authenticated registry with random password
testuser=testuser
testpassword=$(random_string 15)

start_registry --testuser=testuser --testpassword=$testpassword reg
}

@test "auth: credentials on command line" {
# No creds
run_skopeo 1 inspect --tls-verify=false docker://localhost:5000/nonesuch
expect_output --substring "unauthorized: authentication required"

# Wrong user
run_skopeo 1 inspect --tls-verify=false --creds=baduser:badpassword \
docker://localhost:5000/nonesuch
expect_output --substring "unauthorized: authentication required"

# Wrong password
run_skopeo 1 inspect --tls-verify=false --creds=$testuser:badpassword \
docker://localhost:5000/nonesuch
expect_output --substring "unauthorized: authentication required"

# Correct creds, but no such image
run_skopeo 1 inspect --tls-verify=false --creds=$testuser:$testpassword \
docker://localhost:5000/nonesuch
expect_output --substring "manifest unknown: manifest unknown"

# These should pass
run_skopeo copy --dest-tls-verify=false --dcreds=$testuser:$testpassword \
docker://busybox:latest docker://localhost:5000/busybox:mine
run_skopeo inspect --tls-verify=false --creds=$testuser:$testpassword \
docker://localhost:5000/busybox:mine
expect_output --substring "localhost:5000/busybox"
}

@test "auth: credentials via podman login" {
# Logged in: skopeo should work
podman login --tls-verify=false -u $testuser -p $testpassword localhost:5000

run_skopeo copy --dest-tls-verify=false \
docker://busybox:latest docker://localhost:5000/busybox:mine
run_skopeo inspect --tls-verify=false docker://localhost:5000/busybox:mine
expect_output --substring "localhost:5000/busybox"

# Logged out: should fail
podman logout localhost:5000

run_skopeo 1 inspect --tls-verify=false docker://localhost:5000/busybox:mine
expect_output --substring "unauthorized: authentication required"
}

teardown() {
podman rm -f reg

if [[ -n $_cred_dir ]]; then
rm -rf $_cred_dir
fi

standard_teardown
}

# vim: filetype=sh
Loading

0 comments on commit 6307635

Please sign in to comment.