...

Text file src/github.com/sigstore/cosign/v2/test/e2e_test.sh

Documentation: github.com/sigstore/cosign/v2/test

     1#!/usr/bin/env bash
     2#
     3# Copyright 2021 The Sigstore Authors.
     4#
     5# Licensed under the Apache License, Version 2.0 (the "License");
     6# you may not use this file except in compliance with the License.
     7# You may obtain a copy of the License at
     8#
     9#     http://www.apache.org/licenses/LICENSE-2.0
    10#
    11# Unless required by applicable law or agreed to in writing, software
    12# distributed under the License is distributed on an "AS IS" BASIS,
    13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14# See the License for the specific language governing permissions and
    15# limitations under the License.
    16
    17set -ex
    18
    19echo "setting up OIDC provider"
    20pushd ./test/fakeoidc
    21oidcimg=$(ko build main.go --local)
    22docker network ls | grep fulcio_default || docker network create fulcio_default
    23docker run -d --rm -p 8080:8080 --network fulcio_default --name fakeoidc $oidcimg
    24cleanup_oidc() {
    25    echo "cleaning up oidc"
    26    docker stop fakeoidc
    27}
    28trap cleanup_oidc EXIT
    29oidc_ip=$(docker inspect fakeoidc | jq -r '.[0].NetworkSettings.Networks.fulcio_default.IPAddress')
    30export OIDC_URL="http://${oidc_ip}:8080"
    31cat <<EOF > /tmp/fulcio-config.json
    32{
    33  "OIDCIssuers": {
    34    "$OIDC_URL": {
    35      "IssuerURL": "$OIDC_URL",
    36      "ClientID": "sigstore",
    37      "Type": "email"
    38    }
    39  }
    40}
    41EOF
    42popd
    43
    44pushd $HOME
    45
    46echo "downloading service repos"
    47for repo in rekor fulcio; do
    48    if [[ ! -d $repo ]]; then
    49        git clone https://github.com/sigstore/${repo}.git
    50    else
    51        pushd $repo
    52        git pull
    53        popd
    54    fi
    55done
    56
    57echo "starting services"
    58export FULCIO_METRICS_PORT=2113
    59export FULCIO_CONFIG=/tmp/fulcio-config.json
    60for repo in rekor fulcio; do
    61    pushd $repo
    62    docker-compose up -d
    63    echo -n "waiting up to 60 sec for system to start"
    64    count=0
    65    until [ $(docker-compose ps | grep -c "(healthy)") == 3 ];
    66    do
    67        if [ $count -eq 6 ]; then
    68           echo "! timeout reached"
    69           exit 1
    70        else
    71           echo -n "."
    72           sleep 10
    73           let 'count+=1'
    74        fi
    75    done
    76    popd
    77done
    78cleanup_services() {
    79    echo "cleaning up"
    80    cleanup_oidc
    81    for repo in rekor fulcio; do
    82        pushd $HOME/$repo
    83        docker-compose down
    84        popd
    85    done
    86}
    87trap cleanup_services EXIT
    88
    89echo
    90echo "running tests"
    91
    92popd
    93go test -tags=e2e -v -race ./test/...
    94
    95# Test on a private registry
    96echo "testing sign/verify/clean on private registry"
    97cleanup() {
    98    cleanup_services
    99    docker rm -f registry
   100}
   101trap cleanup EXIT
   102docker run -d -p 5000:5000 --restart always -e REGISTRY_STORAGE_DELETE_ENABLED=true --name registry registry:latest
   103export COSIGN_TEST_REPO=localhost:5000
   104go test -tags=e2e -v ./test/... -run TestSignVerifyClean
   105
   106# Run the built container to make sure it doesn't crash
   107make ko-local
   108img="ko.local/cosign:$(git rev-parse HEAD)"
   109docker run $img version

View as plain text