terraform/internal/releaseauth/all_test.go
Brandon Croft 7acde98806
cloudplugin: change manifest format to match releases API
Changes the release manifest format to more closely match the releases API V1 (example https://api.releases.hashicorp.com/v1/releases/terraform-cloudplugin/0.1.0-prototype)

- The new format doesn't carry the SHASUM for each build, so it made the matching_sums check in releaseauth redundant.
- Added tests for checksum parsing
- Added ID-based selection of signature file
2023-09-06 14:03:24 -06:00

41 lines
1,011 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package releaseauth
import (
"os"
"testing"
)
func TestAll(t *testing.T) {
// `sha256sum testdata/sample_release/sample_0.1.0_darwin_amd64.zip | cut -d' ' -f1`
actualChecksum, err := SHA256FromHex("22db2f0c70b50cff42afd4878fea9f6848a63f1b6532bd8b64b899f574acb35d")
if err != nil {
t.Fatal(err)
}
sums, err := os.ReadFile("testdata/sample_release/sample_0.1.0_SHA256SUMS")
if err != nil {
t.Fatal(err)
}
signature, err := os.ReadFile("testdata/sample_release/sample_0.1.0_SHA256SUMS.sig")
if err != nil {
t.Fatal(err)
}
publicKey, err := os.ReadFile("testdata/sample.public.key")
if err != nil {
t.Fatal(err)
}
sigAuth := NewSignatureAuthentication(signature, sums)
sigAuth.PublicKey = string(publicKey)
all := AllAuthenticators(
NewChecksumAuthentication(actualChecksum, "testdata/sample_release/sample_0.1.0_darwin_amd64.zip"),
sigAuth,
)
if err := all.Authenticate(); err != nil {
t.Fatal(err)
}
}