Skip to content

Commit

Permalink
e2e test for consistency check for ct log
Browse files Browse the repository at this point in the history
Signed-off-by: linus-sun <linussun@google.com>
  • Loading branch information
linus-sun committed Nov 15, 2024
1 parent ced634c commit ff7290c
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pkg/test/ct_e2e/ct_e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 The Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build ct_e2e
// +build ct_e2e

package ct_e2e

import (
"os"
"testing"

"net/http"

ctclient "github.com/google/certificate-transparency-go/client"
"github.com/google/certificate-transparency-go/jsonclient"
"github.com/sigstore/rekor-monitor/pkg/ct"
)

const (
rekorURL = "http://127.0.0.1:3000"
subject = "subject@example.com"
issuer = "oidc-issuer@domain.com"
extValueString = "test cert value"
SubmissionCertB64 = "MIIEijCCA3KgAwIBAgICEk0wDQYJKoZIhvcNAQELBQAwKzEpMCcGA1UEAwwgY2Fja2xpbmcgY3J5cHRvZ3JhcGhlciBmYWtlIFJPT1QwHhcNMTUxMDIxMjAxMTUyWhcNMjAxMDE5MjAxMTUyWjAfMR0wGwYDVQQDExRoYXBweSBoYWNrZXIgZmFrZSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIKR3maBcUSsncXYzQT13D5Nr+Z3mLxMMh3TUdt6sACmqbJ0btRlgXfMtNLM2OU1I6a3Ju+tIZSdn2v21JBwvxUzpZQ4zy2cimIiMQDZCQHJwzC9GZn8HaW091iz9H0Go3A7WDXwYNmsdLNRi00o14UjoaVq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v2frNvFBCmO59goz+jnWvfTtj2NjwDZ7vlMBsPm16dbKYC840uvRoZjxqsdc3ChCZjqimFqlNG/xoPA8+dTicZzCXE9ijPIcvW6y1aa3bGw="
)

func TestCTConsistencyCheck(t *testing.T) {
fulcioClient, err := ctclient.New("http://localhost:8080/testlog", http.DefaultClient, jsonclient.Options{})
if err != nil {
t.Errorf("error instantiating ct client: %v", err)
}

tempDir := t.TempDir()
tempLogInfoFile, err := os.CreateTemp(tempDir, "")
if err != nil {
t.Errorf("failed to create temp log file: %v", err)
}
tempLogInfoFileName := tempLogInfoFile.Name()
defer os.Remove(tempLogInfoFileName)

err = ct.RunConsistencyCheck(fulcioClient, tempLogInfoFileName)
if err != nil {
t.Errorf("failed to successfully complete consistency check: %v", err)
}
}
80 changes: 80 additions & 0 deletions pkg/test/ct_e2e/ct_e2e_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Sigstore Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

pushd $HOME

echo "downloading service repos"
for repo in certificate-transparency-go trillian; do
if [[ ! -d $repo ]]; then
git clone https://github.com/sigstore/${repo}.git
fi
done

docker_compose="docker compose"

pushd ./certificate-transparency-go/trillian/examples/deployment/docker/ctfe/
docker compose up -d
until [ $(${docker_compose} ps | grep -c "(healthy)") == 1 ];
do
if [ $count -eq 6 ]; then
echo "! timeout reached"
exit 1
else
echo -n "."
sleep 5
let 'count+=1'
fi
done
popd

docker exec -i ctfe-db mariadb -pzaphod -Dtest < ./trillian/storage/mysql/schema/storage.sql
docker exec -i ctfe-db mariadb -pzaphod -Dtest < ./certificate-transparency-go/trillian/ctfe/storage/mysql/schema.sql

CTFE_CONF_DIR=/tmp/ctfedocker
if [ -d $CTFE_CONF_DIR ]; then
mkdir ${CTFE_CONF_DIR}
fi

TREE_ID=$(go run github.com/google/trillian/cmd/createtree@master --admin_server=localhost:8090)
sed "s/@TREE_ID@/${TREE_ID}/" ./certificate-transparency-go/trillian/examples/deployment/docker/ctfe/ct_server.cfg > ${CTFE_CONF_DIR}/ct_server.cfg
cp ./certificate-transparency-go/trillian/testdata/fake-ca.cert ${CTFE_CONF_DIR}
docker volume create --driver local --opt type=none --opt device=${CTFE_CONF_DIR} --opt o=bind ctfe_config

pushd ./certificate-transparency-go/trillian/examples/deployment/docker/ctfe/
docker compose down
docker compose --profile frontend up -d
until [ $(${docker_compose} ps | grep -c "(healthy)") == 1 ];
do
if [ $count -eq 6 ]; then
echo "! timeout reached"
exit 1
else
echo -n "."
sleep 5
let 'count+=1'
fi
done
popd

popd
go test -tags=ct_e2e -v -race ./pkg/test/ct_e2e/...

pushd $HOME
pushd ./certificate-transparency-go/trillian/examples/deployment/docker/ctfe/
docker compose down
popd

0 comments on commit ff7290c

Please sign in to comment.