Skip to content

Commit

Permalink
Update unit tests for issuer pool
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Mar 6, 2023
1 parent a11e8a3 commit 0f0c481
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 76 deletions.
45 changes: 16 additions & 29 deletions cmd/app/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
gw "github.com/sigstore/fulcio/pkg/generated/protobuf"
gw_legacy "github.com/sigstore/fulcio/pkg/generated/protobuf/legacy"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/buildkite"
"github.com/sigstore/fulcio/pkg/identity/email"
"github.com/sigstore/fulcio/pkg/identity/github"
"github.com/sigstore/fulcio/pkg/identity/kubernetes"
Expand Down Expand Up @@ -95,48 +96,34 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
func NewIssuerPool(cfg *config.FulcioConfig) identity.IssuerPool {
var ip identity.IssuerPool
for _, i := range cfg.OIDCIssuers {
ip = append(ip, getIssuer(i))
ip = append(ip, getIssuer("", i))
}
for meta, iss := range cfg.MetaIssuers {
re, err := config.MetaRegex(meta)
if err != nil {
continue // Shouldn't happen, we check parsing the config
}
if re.MatchString(iss.IssuerURL) {
// If it matches, then return a concrete OIDCIssuer
// configuration for this issuer URL.
oidcIssuer := config.OIDCIssuer{
IssuerURL: iss.IssuerURL,
ClientID: iss.ClientID,
Type: iss.Type,
IssuerClaim: iss.IssuerClaim,
SubjectDomain: iss.SubjectDomain,
}
ip = append(ip, getIssuer(oidcIssuer))
} else {
fmt.Println("it didn't match")
fmt.Println(meta)
}
for meta, i := range cfg.MetaIssuers {
ip = append(ip, getIssuer(meta, i))
}
return ip
}

func getIssuer(i config.OIDCIssuer) identity.Issuer {
func getIssuer(meta string, i config.OIDCIssuer) identity.Issuer {
issuerURL := i.IssuerURL
if issuerURL == "" {
issuerURL = meta
}
switch i.Type {
case config.IssuerTypeEmail:
return email.Issuer(i.IssuerURL)
return email.Issuer(issuerURL)
case config.IssuerTypeGithubWorkflow:
return github.Issuer(i.IssuerURL)
return github.Issuer(issuerURL)
case config.IssuerTypeBuildkiteJob:
// TODO: priyawadhwa@
return buildkite.Issuer(issuerURL)
case config.IssuerTypeKubernetes:
return kubernetes.Issuer(i.IssuerURL)
return kubernetes.Issuer(issuerURL)
case config.IssuerTypeSpiffe:
return spiffe.Issuer(i.IssuerURL)
return spiffe.Issuer(issuerURL)
case config.IssuerTypeURI:
return uri.Issuer(i.IssuerURL)
return uri.Issuer(issuerURL)
case config.IssuerTypeUsername:
return username.Issuer(i.IssuerURL)
return username.Issuer(issuerURL)
}
return nil
}
Expand Down
14 changes: 4 additions & 10 deletions cmd/app/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/sigstore/fulcio/pkg/config"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
"github.com/sigstore/fulcio/pkg/identity/email"
"github.com/sigstore/fulcio/pkg/identity/github"
"github.com/sigstore/fulcio/pkg/identity/kubernetes"
Expand All @@ -44,7 +45,7 @@ func TestIssuerPool(t *testing.T) {
expected := identity.IssuerPool{
email.Issuer("https://oauth2.sigstore.dev/auth"),
}
ignoreOpts := []cmp.Option{email.CmpOptions, spiffe.CmpOptions, github.CmpOptions}
ignoreOpts := []cmp.Option{base.CmpOptions}
got := NewIssuerPool(cfg)
if d := cmp.Diff(expected, got, ignoreOpts...); d != "" {
t.Fatal(d)
Expand Down Expand Up @@ -119,18 +120,11 @@ func TestGetIssuer(t *testing.T) {
},
}

ignoreOpts := []cmp.Option{
email.CmpOptions,
github.CmpOptions,
spiffe.CmpOptions,
kubernetes.CmpOptions,
uri.CmpOptions,
username.CmpOptions,
}
ignoreOpts := []cmp.Option{base.CmpOptions}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
got := getIssuer(test.issuer)
got := getIssuer("", test.issuer)
if d := cmp.Diff(got, test.expected, ignoreOpts...); d != "" {
t.Fatal(d)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/identity/base/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ import (
"regexp"
"strings"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(baseIssuer{})
)

type baseIssuer struct {
issuerURL string
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/identity/email/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ package email
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(emailIssuer{})
)

type emailIssuer struct {
identity.Issuer
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/identity/github/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ package github
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(githubIssuer{})
)

type githubIssuer struct {
identity.Issuer
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/identity/kubernetes/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ package kubernetes
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(kubernetesIssuer{})
)

type kubernetesIssuer struct {
identity.Issuer
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/identity/spiffe/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ package spiffe
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(spiffeIssuer{})
)

type spiffeIssuer struct {
identity.Issuer
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/identity/uri/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ package uri
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(uriIssuer{})
)

type uriIssuer struct {
identity.Issuer
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/identity/username/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ package username
import (
"context"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/sigstore/fulcio/pkg/identity"
"github.com/sigstore/fulcio/pkg/identity/base"
)

var (
// For testing
CmpOptions = cmpopts.IgnoreUnexported(usernameIssuer{})
)


type usernameIssuer struct {
identity.Issuer
}
Expand Down

0 comments on commit 0f0c481

Please sign in to comment.