Skip to content

Commit

Permalink
Retrieve checksum from subfolder/filename (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamoss authored Mar 18, 2020
1 parent 7cc4779 commit 0b1d527
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ func (c *Client) ChecksumFromFile(ctx context.Context, checksumURL, checksummedP
return checksum, nil
}
}
// The checksum filename can contain a sub folder to differ versions.
// e.g. ./netboot/mini.iso and ./hwe-netboot/mini.iso
// In this case we remove root folder characters to compare with the checksummed path
fn := strings.TrimLeft(checksum.Filename, "./")
if strings.Contains(checksummedPath, fn) {
return checksum, nil
}
}
return nil, fmt.Errorf("no checksum found in: %s", checksumURL)
}
Expand Down
23 changes: 23 additions & 0 deletions checksum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package getter

import (
"context"
"testing"
)

func TestClient_ChecksumFromFileWithSubFolder(t *testing.T) {
httpChecksums := httpTestModule("checksum-file")
defer httpChecksums.Close()
ctx := context.TODO()
isoURL := "http://hashicorp.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/mini.iso"

client := Client{}
file, err := client.ChecksumFromFile(ctx, httpChecksums.URL+"/sha256-subfolder.sum", isoURL)

if err != nil {
t.Fatalf("bad: should not have error: %s", err.Error())
}
if file.Filename != "./netboot/mini.iso" {
t.Fatalf("bad: expecting filename ./netboot/mini.iso but was: %s", file.Filename)
}
}
2 changes: 2 additions & 0 deletions testdata/checksum-file/sha256-subfolder.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a264b6b009dfaa16286fdfd046a156a43587333b ./hwe-netboot/mini.iso
27c39bac2cf4640c00cacfc8982b0ba39e7b7f96 ./netboot/mini.iso

0 comments on commit 0b1d527

Please sign in to comment.