Skip to content

Commit

Permalink
Validate Attestation URL
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Apr 24, 2024
1 parent 0a25d56 commit 4219d28
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion circle/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ func CheckAttestation(attestationURL string, logger log.Logger, irisLookupID str
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, attestationURL+"0x"+irisLookupID, nil)
// append ending / if not present
if attestationURL[len(attestationURL)-1:] != "/" {
attestationURL += "/"
}

// add 0x prefix if not present
if len(irisLookupID) > 2 && irisLookupID[:2] != "0x" {
irisLookupID = "0x" + irisLookupID
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, attestationURL+irisLookupID, nil)
if err != nil {
logger.Debug("error creating request: " + err.Error())
return nil
Expand Down
17 changes: 17 additions & 0 deletions circle/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ func TestAttestationNotFound(t *testing.T) {
resp := circle.CheckAttestation(cfg.Circle.AttestationBaseURL, logger, "not an attestation", "", 0, 4)
require.Nil(t, resp)
}

func TestAttestationWithoutEndingSlash(t *testing.T) {
startUrl := cfg.Circle.AttestationBaseURL

Check failure on line 36 in circle/attestation_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1003: var startUrl should be startURL (stylecheck)
cfg.Circle.AttestationBaseURL = startUrl[:len(startUrl)-1]

resp := circle.CheckAttestation(cfg.Circle.AttestationBaseURL, logger, "85bbf7e65a5992e6317a61f005e06d9972a033d71b514be183b179e1b47723fe", "", 0, 4)
require.NotNil(t, resp)
require.Equal(t, "complete", resp.Status)

cfg.Circle.AttestationBaseURL = startUrl
}

func TestAttestationWithLeading0x(t *testing.T) {
resp := circle.CheckAttestation(cfg.Circle.AttestationBaseURL, logger, "0x85bbf7e65a5992e6317a61f005e06d9972a033d71b514be183b179e1b47723fe", "", 0, 4)
require.NotNil(t, resp)
require.Equal(t, "complete", resp.Status)
}

0 comments on commit 4219d28

Please sign in to comment.