From 90166610d7c6bae5c863cf329a6465640f4e90dd Mon Sep 17 00:00:00 2001 From: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:52:15 -0500 Subject: [PATCH] Fixed review comments Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- attestation/github/github.go | 15 +++++++-------- attestation/github/github_test.go | 20 -------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/attestation/github/github.go b/attestation/github/github.go index cf0298f6..fad1b093 100644 --- a/attestation/github/github.go +++ b/attestation/github/github.go @@ -25,7 +25,6 @@ import ( "os" "strings" - "github.com/davecgh/go-spew/spew" "github.com/testifysec/go-witness/attestation" "github.com/testifysec/go-witness/attestation/jwt" "github.com/testifysec/go-witness/cryptoutil" @@ -117,16 +116,16 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { jwtString, err := fetchToken(a.tokenURL, os.Getenv("ACTIONS_ID_TOKEN_REQUEST_TOKEN"), "witness") if err != nil { - return fmt.Errorf("error on fething token %w", err) + return fmt.Errorf("error on fetching token %w", err) } - spew.Dump(jwtString) + if jwtString == "" { + return fmt.Errorf("empty JWT string") + } - if jwtString != "" { - a.JWT = jwt.New(jwt.WithToken(jwtString), jwt.WithJWKSUrl(a.jwksURL)) - if err := a.JWT.Attest(ctx); err != nil { - return fmt.Errorf("error on attesting jwt %w", err) - } + a.JWT = jwt.New(jwt.WithToken(jwtString), jwt.WithJWKSUrl(a.jwksURL)) + if err := a.JWT.Attest(ctx); err != nil { + return fmt.Errorf("failed to attest github jwt: %w", err) } a.CIServerUrl = os.Getenv("GITHUB_SERVER_URL") diff --git a/attestation/github/github_test.go b/attestation/github/github_test.go index a09ee3c5..5db492a1 100644 --- a/attestation/github/github_test.go +++ b/attestation/github/github_test.go @@ -22,7 +22,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/testifysec/go-witness/attestation" ) func createMockServer() *httptest.Server { @@ -111,25 +110,6 @@ func TestFetchToken(t *testing.T) { } } -func TestAttestorAttest(t *testing.T) { - tokenServer := createTokenServer() - defer tokenServer.Close() - t.Setenv("GITHUB_ACTIONS", "true") - t.Setenv("ACTIONS_ID_TOKEN_REQUEST_URL", tokenServer.URL+"/valid") - t.Setenv("ACTIONS_ID_TOKEN_REQUEST_TOKEN", "validBearer") - - attestor := &Attestor{ - aud: tokenAudience, - jwksURL: tokenServer.URL, - tokenURL: os.Getenv("ACTIONS_ID_TOKEN_REQUEST_URL"), - } - - ctx := &attestation.AttestationContext{} - - err := attestor.Attest(ctx) - assert.NoError(t, err) -} - func TestSubjects(t *testing.T) { tokenServer := createTokenServer() defer tokenServer.Close()