github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/vault/helper/pgpkeys/keybase_test.go (about) 1 package pgpkeys 2 3 import ( 4 "bytes" 5 "encoding/base64" 6 "encoding/hex" 7 "reflect" 8 "testing" 9 10 "github.com/keybase/go-crypto/openpgp" 11 "github.com/keybase/go-crypto/openpgp/packet" 12 ) 13 14 func TestFetchKeybasePubkeys(t *testing.T) { 15 testset := []string{"keybase:jefferai", "keybase:hashicorp"} 16 ret, err := FetchKeybasePubkeys(testset) 17 if err != nil { 18 t.Fatalf("bad: %v", err) 19 } 20 21 fingerprints := []string{} 22 for _, user := range testset { 23 data, err := base64.StdEncoding.DecodeString(ret[user]) 24 if err != nil { 25 t.Fatalf("error decoding key for user %s: %v", user, err) 26 } 27 entity, err := openpgp.ReadEntity(packet.NewReader(bytes.NewBuffer(data))) 28 if err != nil { 29 t.Fatalf("error parsing key for user %s: %v", user, err) 30 } 31 fingerprints = append(fingerprints, hex.EncodeToString(entity.PrimaryKey.Fingerprint[:])) 32 } 33 34 exp := []string{ 35 "0f801f518ec853daff611e836528efcac6caa3db", 36 "c874011f0ab405110d02105534365d9472d7468f", 37 } 38 39 if !reflect.DeepEqual(fingerprints, exp) { 40 t.Fatalf("fingerprints do not match; expected \n%#v\ngot\n%#v\n", exp, fingerprints) 41 } 42 }