open-vault/helper/pgpkeys/keybase_test.go
Yoan Blanc fa8f7c793f
fix: PGP subkeys support (#16224)
* fix: PGP subkeys support

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>

* fix: bump ProtonMail/go-crypto

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>

* fix: bump ProtonMail/go-crypto

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
2022-09-22 09:12:41 -04:00

43 lines
1.1 KiB
Go

package pgpkeys
import (
"bytes"
"encoding/base64"
"encoding/hex"
"reflect"
"testing"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet"
)
func TestFetchKeybasePubkeys(t *testing.T) {
testset := []string{"keybase:jefferai", "keybase:hashicorp"}
ret, err := FetchKeybasePubkeys(testset)
if err != nil {
t.Fatalf("bad: %v", err)
}
fingerprints := []string{}
for _, user := range testset {
data, err := base64.StdEncoding.DecodeString(ret[user])
if err != nil {
t.Fatalf("error decoding key for user %s: %v", user, err)
}
entity, err := openpgp.ReadEntity(packet.NewReader(bytes.NewBuffer(data)))
if err != nil {
t.Fatalf("error parsing key for user %s: %v", user, err)
}
fingerprints = append(fingerprints, hex.EncodeToString(entity.PrimaryKey.Fingerprint[:]))
}
exp := []string{
"0f801f518ec853daff611e836528efcac6caa3db",
"c874011f0ab405110d02105534365d9472d7468f",
}
if !reflect.DeepEqual(fingerprints, exp) {
t.Fatalf("fingerprints do not match; expected \n%#v\ngot\n%#v\n", exp, fingerprints)
}
}