Skip to content

Commit

Permalink
Fix remoteFromMirror with GCS bucket (#734)
Browse files Browse the repository at this point in the history
* Fix remoteFromMirror with GCS bucket

The mirror was reconfigured, but the URL was never reparsed, so when
checking the scheme, there was a nil pointer exception. This fix simply
returns early for GCS buckets.

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
  • Loading branch information
haydentherapper committed Oct 10, 2022
1 parent 5fdf035 commit 8cd960f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/tuf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func remoteFromMirror(mirror string) (client.RemoteStore, error) {
// This is for compatibility with specifying a GCS bucket remote.
u, parseErr := url.ParseRequestURI(mirror)
if parseErr != nil {
mirror = fmt.Sprintf("https://%s.storage.googleapis.com", mirror)
return client.HTTPRemoteStore(fmt.Sprintf("https://%s.storage.googleapis.com", mirror), nil, nil)
}
if u.Scheme != "file" {
return client.HTTPRemoteStore(mirror, nil, nil)
Expand Down
25 changes: 25 additions & 0 deletions pkg/tuf/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,28 @@ func TestTargetsSubfolder(t *testing.T) {
}
checkTargetsAndMeta(t, tuf, []string{newTarget})
}

func Test_remoteFromMirror(t *testing.T) {
// test GCS mirror
mirror := "test-bucket"
_, err := remoteFromMirror(mirror)
if err != nil {
t.Fatalf("unexpected error with GCS mirror: %v", err)
}

// test HTTP mirror
mirror = "https://tuf-root-staging.storage.googleapis.com"
_, err = remoteFromMirror(mirror)
if err != nil {
t.Fatalf("unexpected error with GCS mirror: %v", err)
}

// test local mirror
tufRoot := t.TempDir()
os.Mkdir(fmt.Sprintf("%s/targets", tufRoot), 0o0750)
mirror = fmt.Sprintf("file://%s", tufRoot)
_, err = remoteFromMirror(mirror)
if err != nil {
t.Fatalf("unexpected error with GCS mirror: %v", err)
}
}

0 comments on commit 8cd960f

Please sign in to comment.