Skip to content

Commit

Permalink
update client to remove stable parameter from get log info
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 Oct 8, 2024
1 parent a0d4288 commit ccf7588
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 52 deletions.
67 changes: 18 additions & 49 deletions cmd/verifier/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@ import (
"testing"
"time"

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/sigstore/rekor-monitor/pkg/identity"
"github.com/sigstore/rekor-monitor/pkg/rekor"
"github.com/sigstore/rekor-monitor/pkg/test"
"github.com/sigstore/rekor/pkg/client"
"github.com/sigstore/rekor/pkg/generated/client/entries"
"github.com/sigstore/rekor/pkg/generated/models"
"github.com/sigstore/rekor/pkg/types"
"github.com/sigstore/rekor/pkg/util"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"
"sigs.k8s.io/release-utils/version"

hashedrekord_v001 "github.com/sigstore/rekor/pkg/types/hashedrekord/v0.0.1"
rekord "github.com/sigstore/rekor/pkg/types/rekord/v0.0.1"
)

const (
rekorURL = "http://127.0.0.1:3000"
subject = "subject@example.com"
issuer = "oidc-issuer@domain.com"
)

// Test RunConsistencyCheck:
Expand All @@ -65,9 +63,6 @@ func TestRunConsistencyCheck(t *testing.T) {
t.Errorf("error getting log verifier: %v", err)
}

subject := "subject@example.com"
issuer := "oidc-issuer@domain.com"

rootCert, rootKey, _ := test.GenerateRootCA()
leafCert, leafKey, _ := test.GenerateLeafCert(subject, issuer, rootCert, rootKey)

Expand All @@ -83,21 +78,6 @@ func TestRunConsistencyCheck(t *testing.T) {
t.Fatalf("error signing message: %v", err)
}

rekordEntry := rekord.V001Entry{
RekordObj: models.RekordV001Schema{
Data: &models.RekordV001SchemaData{
Content: strfmt.Base64(payload),
},
Signature: &models.RekordV001SchemaSignature{
Content: (*strfmt.Base64)(&sig),
Format: swag.String(models.RekordV001SchemaSignatureFormatX509),
PublicKey: &models.RekordV001SchemaSignaturePublicKey{
Content: (*strfmt.Base64)(&pemCert),
},
},
},
}

hashedrekord := &hashedrekord_v001.V001Entry{}
hash := sha256.Sum256(payload)
pe, err := hashedrekord.CreateFromArtifactProperties(context.Background(), types.ArtifactProperties{
Expand All @@ -117,17 +97,6 @@ func TestRunConsistencyCheck(t *testing.T) {
t.Errorf("error creating log entry: %v", err)
}

params = entries.NewCreateLogEntryParams()
rekordModel := models.Rekord{
APIVersion: swag.String(rekordEntry.APIVersion()),
Spec: rekordEntry.RekordObj,
}
params.SetProposedEntry(&rekordModel)
resp, err = rekorClient.Entries.CreateLogEntry(params)
if !resp.IsSuccess() || err != nil {
t.Errorf("error creating log entry: %v", err)
}

logInfo, err := rekor.GetLogInfo(context.Background(), rekorClient)
if err != nil {
t.Errorf("error getting log info: %v", err)
Expand All @@ -136,21 +105,8 @@ func TestRunConsistencyCheck(t *testing.T) {
if err := checkpoint.UnmarshalText([]byte(*logInfo.SignedTreeHead)); err != nil {
t.Errorf("%v", err)
}
iterator := 0
for checkpoint.Size <= 0 {
logInfo, err = rekor.GetLogInfo(context.Background(), rekorClient)
if err != nil {
t.Errorf("error getting log info: %v", err)
}
checkpoint := &util.SignedCheckpoint{}
if err := checkpoint.UnmarshalText([]byte(*logInfo.SignedTreeHead)); err != nil {
t.Errorf("error unmarshalling checkpoint: %v", err)
}
iterator++
if iterator >= 5 {
t.Errorf("log info checkpoint failed to update in time")
}
time.Sleep(2 * time.Second)
if checkpoint.Size != 1 {
t.Errorf("expected checkpoint size of 1, received size %d", checkpoint.Size)
}

tempDir := t.TempDir()
Expand Down Expand Up @@ -201,6 +157,19 @@ func TestRunConsistencyCheck(t *testing.T) {
if !resp.IsSuccess() || err != nil {
t.Errorf("error creating log entry: %v", err)
}

logInfo, err = rekor.GetLogInfo(context.Background(), rekorClient)
if err != nil {
t.Errorf("error getting log info: %v", err)
}
checkpoint = &util.SignedCheckpoint{}
if err := checkpoint.UnmarshalText([]byte(*logInfo.SignedTreeHead)); err != nil {
t.Errorf("%v", err)
}
if checkpoint.Size != 2 {
t.Errorf("expected checkpoint size of 2, received size %d", checkpoint.Size)
}

err = RunConsistencyCheck(&interval, rekorClient, verifier, &tempLogInfoFileName, monitoredVals, &tempOutputIdentitiesFileName, &once)
if err != nil {
t.Errorf("second consistency check failed: %v", err)
Expand All @@ -212,6 +181,6 @@ func TestRunConsistencyCheck(t *testing.T) {
}
tempOutputIdentitiesString := string(tempOutputIdentities)
if !strings.Contains(tempOutputIdentitiesString, subject) {
t.Errorf("expected to find subject@example.com, did not")
t.Errorf("expected to find %s, did not", subject)
}
}
3 changes: 2 additions & 1 deletion cmd/verifier/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ for repo in rekor ; do
done
popd
done
cleanup_services() {

function cleanup_services() {
echo "cleaning up"
for repo in rekor; do
pushd $HOME/$repo
Expand Down
2 changes: 0 additions & 2 deletions pkg/rekor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func GetPublicKey(ctx context.Context, rekorClient *client.Rekor) ([]byte, error
// GetLogInfo fetches a stable checkpoint for each log shard
func GetLogInfo(ctx context.Context, rekorClient *client.Rekor) (*models.LogInfo, error) {
p := tlog.NewGetLogInfoParamsWithContext(ctx)
stable := true
p.Stable = &stable

logInfoResp, err := rekorClient.Tlog.GetLogInfo(p)
if err != nil {
Expand Down

0 comments on commit ccf7588

Please sign in to comment.