Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds TSA URI for customMetadata. #1646

Merged
merged 2 commits into from Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/tuf/client.go
Expand Up @@ -116,6 +116,7 @@ type TargetFile struct {
type customMetadata struct {
Usage UsageKind `json:"usage"`
Status StatusKind `json:"status"`
URI string `json:"uri"`
}

type sigstoreCustomMetadata struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/tuf/usage_type.go
Expand Up @@ -26,13 +26,15 @@ const (
Fulcio
Rekor
CTFE
TSA
)

var toUsageString = map[UsageKind]string{
UnknownUsage: "Unknown",
Fulcio: "Fulcio",
Rekor: "Rekor",
CTFE: "CTFE",
TSA: "TSA",
}

func (u UsageKind) String() string {
Expand All @@ -57,6 +59,8 @@ func (u *UsageKind) UnmarshalText(text []byte) error {
*u = Rekor
case "ctfe":
*u = CTFE
case "tsa":
*u = TSA
default:
return fmt.Errorf("error while unmarshalling, UsageKind=%v not valid", string(text))
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/tuf/usage_type_test.go
Expand Up @@ -23,12 +23,12 @@ import (
)

func TestMarshalUsageType(t *testing.T) {
usages := []UsageKind{UnknownUsage, Fulcio, Rekor, CTFE}
usages := []UsageKind{UnknownUsage, Fulcio, Rekor, CTFE, TSA}
bytes, err := json.Marshal(usages)
if err != nil {
t.Fatalf("expected no error marshalling struct, got: %v", err)
}
expected := `["Unknown","Fulcio","Rekor","CTFE"]`
expected := `["Unknown","Fulcio","Rekor","CTFE","TSA"]`
if string(bytes) != expected {
t.Fatalf("error while marshalling, expected: %s, got: %s", expected, bytes)
}
Expand All @@ -49,26 +49,26 @@ func TestMarshalInvalidUsageType(t *testing.T) {

func TestUnmarshalUsageType(t *testing.T) {
var usages []UsageKind
j := json.RawMessage(`["fulcio", "rekor", "ctfe", "unknown"]`)
j := json.RawMessage(`["fulcio", "rekor", "ctfe", "tsa", "unknown"]`)
err := json.Unmarshal(j, &usages)
if err != nil {
t.Fatalf("expected no error unmarshalling struct, got: %v", err)
}
if !reflect.DeepEqual(usages, []UsageKind{Fulcio, Rekor, CTFE, UnknownUsage}) {
t.Fatalf("expected [Fulcio, Rekor, CTFE, UnknownUsage], got: %v", usages)
if !reflect.DeepEqual(usages, []UsageKind{Fulcio, Rekor, CTFE, TSA, UnknownUsage}) {
t.Fatalf("expected [Fulcio, Rekor, CTFE, ,TSA, UnknownUsage], got: %v", usages)
}
}

func TestUnmarshalUsageTypeCapitalization(t *testing.T) {
// Any capitalization is allowed.
var usages []UsageKind
j := json.RawMessage(`["fUlCiO", "rEkOr", "cTfE", "uNkNoWn"]`)
j := json.RawMessage(`["fUlCiO", "rEkOr", "cTfE", "tSa", "uNkNoWn"]`)
err := json.Unmarshal(j, &usages)
if err != nil {
t.Fatalf("expected no error unmarshalling struct, got: %v", err)
}
if !reflect.DeepEqual(usages, []UsageKind{Fulcio, Rekor, CTFE, UnknownUsage}) {
t.Fatalf("expected [Fulcio, Rekor, CTFE, UnknownUsage], got: %v", usages)
if !reflect.DeepEqual(usages, []UsageKind{Fulcio, Rekor, CTFE, TSA, UnknownUsage}) {
t.Fatalf("expected [Fulcio, Rekor, CTFE, TSA, UnknownUsage], got: %v", usages)
}
}

Expand Down