Skip to content

Commit

Permalink
use a fake CA for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <[email protected]>
  • Loading branch information
vaikas committed Feb 17, 2022
1 parent 5c066fe commit d5e192b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -35,8 +36,9 @@ import (
"testing"
"time"

"github.com/sigstore/fulcio/pkg/ca"
"github.com/sigstore/fulcio/pkg/ca/ephemeralca"
v1 "github.com/sigstore/fulcio/pkg/ca/googleca/v1"
"github.com/sigstore/fulcio/pkg/challenges"
"github.com/sigstore/fulcio/pkg/config"
"github.com/sigstore/fulcio/pkg/ctl"
"gopkg.in/square/go-jose.v2"
Expand All @@ -49,14 +51,8 @@ const (
expectedNoRootMessage = "{\"code\":500,\"message\":\"error communicating with CA backend\"}\n"
)

// TestMissingRootFails creates a bad Google CA and tests that the client
// gets an error returned to it.
func TestMissingRootFails(t *testing.T) {
caClient, err := v1.NewCertAuthorityService(context.Background(), "non-existent")
if err != nil {
t.Fatalf("Failed to create Google CA: %v", err)
}
h := New(nil, caClient)
h := New(nil, &FailingCertificateAuthority{})
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
h.ServeHTTP(rw, r)
}))
Expand Down Expand Up @@ -297,3 +293,13 @@ func fakeCTLogServer(t *testing.T) *httptest.Server {
fmt.Fprint(w, string(responseBytes))
}))
}

type FailingCertificateAuthority struct {
}

func (fca *FailingCertificateAuthority) CreateCertificate(ctx context.Context, challenge *challenges.ChallengeResult) (*ca.CodeSigningCertificate, error) {
return nil, errors.New("CreateCertificate always fails for testing")
}
func (fca *FailingCertificateAuthority) Root(ctx context.Context) ([]byte, error) {
return nil, errors.New("Root always fails for testing")
}

0 comments on commit d5e192b

Please sign in to comment.