Skip to content

Commit

Permalink
Merge pull request #9 from boxboat/feature/tests-upstream
Browse files Browse the repository at this point in the history
Add Tests
  • Loading branch information
Peyton Walters authored May 20, 2020
2 parents 6012644 + b3f9330 commit 7c88c0c
Show file tree
Hide file tree
Showing 29 changed files with 1,810 additions and 350 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# go binaries
/tpm_attestor_server
/tpm_attestor_agent
/get_tpm_pubhash

# jetbrains
.idea
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build: cmd/server/tpm_attestor/tpm_attestor.go cmd/agent/tpm_attestor/tpm_attestor.go
build: cmd/server/tpm_attestor/tpm_attestor.go cmd/agent/tpm_attestor/tpm_attestor.go tools/get_tpm_pubhash/get_tpm_pubhash.go
GOOS=linux GOARCH=amd64 go build -o tpm_attestor_server cmd/server/tpm_attestor/tpm_attestor.go
GOOS=linux GOARCH=amd64 go build -o tpm_attestor_agent cmd/agent/tpm_attestor/tpm_attestor.go
GOOS=linux GOARCH=amd64 go build -o get_tpm_pubhash tools/get_tpm_pubhash/get_tpm_pubhash.go
29 changes: 29 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash -e

cd "$(dirname "$0")"

export "FIXUID=$(id -u)"
export "FIXGID=$(id -g)"

function cleanup() {
docker-compose \
-f docker/docker-compose.yaml \
-p spire-tpm-plugin \
stop
}

trap cleanup EXIT

docker-compose \
-f docker/docker-compose.yaml \
-p spire-tpm-plugin \
up \
--build \
-d

docker exec \
-t \
-w "/home/docker/spire-tpm-plugin/" \
spire-tpm-plugin-ci \
fixuid \
make
33 changes: 33 additions & 0 deletions ci/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM golang:latest AS go

FROM ubuntu:20.04

RUN addgroup --gid 1000 docker \
&& adduser --uid 1000 --ingroup docker --home /home/docker --shell /bin/sh --disabled-password --gecos "" docker

RUN apt-get update \
&& apt-get install -y \
curl \
gcc \
libtspi-dev \
make \
pwgen \
tpm2-tools \
xxd

RUN USER=docker \
&& GROUP=docker \
&& curl -SsL https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-amd64.tar.gz | tar -C /usr/local/bin -xzf - \
&& chown root:root /usr/local/bin/fixuid \
&& chmod 4755 /usr/local/bin/fixuid

COPY fixuid.yml /etc/fixuid/config.yml

COPY --from=go /usr/local/go /usr/local/go
ENV PATH=$PATH:/usr/local/go/bin

USER docker:docker
WORKDIR /home/docker/spire-tpm-plugin
CMD ["sh", "-c", "trap : TERM INT; ( while true; do sleep 0.1; done ) & wait"]

RUN mkdir -p /home/docker/go
15 changes: 15 additions & 0 deletions ci/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.4"

services:
go:
build:
context: ./
dockerfile: Dockerfile
container_name: spire-tpm-plugin-ci
user: ${FIXUID:-1000}:${FIXGID:-1000}
volumes:
- gopath:/home/docker/go
- ../../:/home/docker/spire-tpm-plugin

volumes:
gopath:
5 changes: 5 additions & 0 deletions ci/docker/fixuid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
user: docker
group: docker
paths:
- /home/docker
- /home/docker/go
12 changes: 12 additions & 0 deletions ci/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -e

cd "$(dirname "$0")"

export "FIXUID=$(id -u)"
export "FIXGID=$(id -g)"

docker-compose \
-f docker/docker-compose.yaml \
-p spire-tpm-plugin \
down \
-v
48 changes: 48 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash -e

cd "$(dirname "$0")"

export "FIXUID=$(id -u)"
export "FIXGID=$(id -g)"

option="$1"
if [ -z "$1" ]; then
option="all"
fi

test_dirs=()
if [ "$option" = "plugin" ] || [ "$option" = "all" ]; then
test_dirs+=("pkg/agent")
fi
if [ "$option" = "tools" ] || [ "$option" = "all" ]; then
test_dirs+=("tools/get_tpm_pubhash")
fi

if [ "${#test_dirs[@]}" = "0" ]; then
echo "usage: $0 all|plugin|tools" >&2
exit 1
fi

function cleanup() {
docker-compose \
-f docker/docker-compose.yaml \
-p spire-tpm-plugin \
stop
}

trap cleanup EXIT

docker-compose \
-f docker/docker-compose.yaml \
-p spire-tpm-plugin \
start

for i in "${test_dirs[@]}"; do
echo "calling go test on dir: $i"
docker exec \
-t \
-w "/home/docker/spire-tpm-plugin/$i" \
spire-tpm-plugin-ci \
go test
echo ""
done
4 changes: 4 additions & 0 deletions ci/tpm2_ek_cert_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__working_dir
summaries
tpm2_ekc.der.crt
tpm2_ekc.pem.crt
19 changes: 19 additions & 0 deletions ci/tpm2_ek_cert_generator/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2019 Marco De Benedictis - Politecnico di Torino

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions ci/tpm2_ek_cert_generator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target:
bash -e generate_ek_cert.sh
clean:
rm -rf _tpm* public* summaries* tpm2_ekc* __working_dir*
10 changes: 10 additions & 0 deletions ci/tpm2_ek_cert_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TPM 2.0 simulator EK cert generator

Files in this directory have been adapted from [tpm2_ek_cert_generator](https://github.com/mrcdb/tpm2_ek_cert_generator) to generate and load EK certs into the simulator

Packages required:

- `make`
- `pwgen`
- `tpm2-tools`
- `xxd`
Loading

0 comments on commit 7c88c0c

Please sign in to comment.