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

Ignore comments in checksum files #350

Merged
merged 3 commits into from
Feb 1, 2022
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Dockerfile to create a go-getter container with smbclient dependency that is used by the get_smb.go tests
FROM golang:latest
FROM golang:1.15

COPY . /go-getter
WORKDIR /go-getter

RUN go mod download
RUN apt-get update
RUN apt-get -y install smbclient
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install smbclient
5 changes: 5 additions & 0 deletions checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func (c *Client) checksumFromFile(ctx context.Context, checksumURL string, check
// for BSD type sums parseChecksumLine guesses the hashing algorithm
// by checking the length of the checksum.
func parseChecksumLine(line string) (*FileChecksum, error) {
switch line[0] {
case '#', '/', '-':
return nil, nil // skip
}
//TODO: this function will fail if we pass a checksum for a path with spaces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understood this one 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.Fields splits on spacing characters, so if a file being checksummed is "my file.iso" or "my\ file.iso", then the count of the switch will be all messed up

parts := strings.Fields(line)

switch len(parts) {
Expand Down
9 changes: 9 additions & 0 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
WantTransfer bool
WantErr bool
}{

{
"",
true,
Expand Down Expand Up @@ -548,6 +549,13 @@ func TestGetFile_checksum_from_file(t *testing.T) {
true,
false,
},

// sha512
{
"?checksum=file:" + checksums + "/CHECKSUM_sha256_gpg",
true,
false,
},
}

for _, tc := range cases {
Expand All @@ -572,6 +580,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
testing_helper.AssertContents(t, dst, "I am a file with some content\n")
}
})
return
}
}

Expand Down
4 changes: 4 additions & 0 deletions testdata/checksum-file/CHECKSUM_sha256_gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---- something something

# noisey verbose duplicate noise
SHA256 (content.txt) = 47afcdfff05a6e5d9db5f6c6df2140f04a6e7422d7ad7f6a7006a4f5a78570e4