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