mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 11:13:09 -06:00
495826444b
When verifying the signature of the SHA256SUMS file, we have been hardcoding HashiCorp's public GPG key and using it as the keyring. Going forward, Terraform will get a list of valid public keys for a provider from the Terraform Registry (registry.terraform.io), and use them as the keyring for the openpgp verification func.
53 lines
959 B
Go
53 lines
959 B
Go
package response
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
var (
|
|
testGPGKeyOne = &GPGKey{
|
|
ASCIIArmor: "---\none\n---",
|
|
}
|
|
testGPGKeyTwo = &GPGKey{
|
|
ASCIIArmor: "---\ntwo\n---",
|
|
}
|
|
)
|
|
|
|
func TestSigningKeyList_GPGASCIIArmor(t *testing.T) {
|
|
var tests = []struct {
|
|
name string
|
|
gpgKeys []*GPGKey
|
|
expected string
|
|
}{
|
|
{
|
|
name: "no keys",
|
|
gpgKeys: []*GPGKey{},
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "one key",
|
|
gpgKeys: []*GPGKey{testGPGKeyOne},
|
|
expected: testGPGKeyOne.ASCIIArmor,
|
|
},
|
|
{
|
|
name: "two keys",
|
|
gpgKeys: []*GPGKey{testGPGKeyOne, testGPGKeyTwo},
|
|
expected: fmt.Sprintf("%s\n%s",
|
|
testGPGKeyOne.ASCIIArmor, testGPGKeyTwo.ASCIIArmor),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
signingKeys := &SigningKeyList{
|
|
GPGKeys: tt.gpgKeys,
|
|
}
|
|
actual := signingKeys.GPGASCIIArmor()
|
|
|
|
if actual != tt.expected {
|
|
t.Errorf("expected %s, got %s", tt.expected, actual)
|
|
}
|
|
})
|
|
}
|
|
}
|