Skip to content

Commit

Permalink
fix(prove): Prove command also sets profile.KeyID
Browse files Browse the repository at this point in the history
Merge pull request #1768 from qri-io/profile-keyid
  • Loading branch information
dustmop authored Apr 22, 2021
2 parents 553a8aa + 9a22104 commit ee0875b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type ProfilePod struct {
ID string `json:"id"`
PrivKey string `json:"privkey,omitempty"`
KeyID string `json:"keyid"`
Peername string `json:"peername"`
// Created timestamp
Created time.Time `json:"created"`
Expand Down Expand Up @@ -210,6 +211,7 @@ func (p ProfilePod) Validate() error {
func (p *ProfilePod) Copy() *ProfilePod {
res := &ProfilePod{
ID: p.ID,
KeyID: p.KeyID,
PrivKey: p.PrivKey,
Peername: p.Peername,
Created: p.Created,
Expand Down
1 change: 1 addition & 0 deletions config/testdata/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Profile:
email: ""
homeurl: ""
id: QmU27VdAEUL5NGM6oB56htTxvHLfcGZgsgxrJTdVr2k4zs
keyid: ""
name: ""
peername: test_peername
photo: ""
Expand Down
2 changes: 2 additions & 0 deletions lib/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (registryImpl) ProveProfileKey(scope scope, p *RegistryProfileParams) error
// Convert the profile to a configuration, assign the registry provided profileID
cfg := configFromProfile(scope, p.Profile)
if profileID, ok := res["profileID"]; ok {
// Store the old profile as the keyID since it came from the original keypair
cfg.Profile.KeyID = cfg.Profile.ID
cfg.Profile.ID = profileID
if pid := profile.IDB58DecodeOrEmpty(profileID); pid != "" {
// Assign to profile struct as well
Expand Down
29 changes: 29 additions & 0 deletions lib/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package lib

import (
"context"
"github.com/ghodss/yaml"
"io/ioutil"
"path/filepath"
"testing"

testkeys "github.com/qri-io/qri/auth/key/test"
"github.com/qri-io/qri/config"
"github.com/qri-io/qri/profile"
"github.com/qri-io/qri/registry/regserver"
repotest "github.com/qri-io/qri/repo/test"
Expand Down Expand Up @@ -42,6 +46,10 @@ func TestProveProfileKey(t *testing.T) {
t.Fatal(err)
}

// Set path for config file so that it will serialize to disk
configPath := filepath.Join(tr.TmpDir, "qri", "config.yaml")
tr.Instance.GetConfig().SetPath(configPath)

// Call the endpoint to prove our account
methods := tr.Instance.Registry()
p := RegistryProfile{
Expand All @@ -58,4 +66,25 @@ func TestProveProfileKey(t *testing.T) {
if pro.ID != expectProfileID {
t.Errorf("bad profileID for peer after prove. expect: %s, got: %s", expectProfileID, pro.ID)
}

// Read config to ensure it contains the expected values
contents, err := ioutil.ReadFile(configPath)
if err != nil {
t.Fatal(err)
}
cfgData := config.Config{}
err = yaml.Unmarshal(contents, &cfgData)
if err != nil {
t.Fatal(err)
}

// Key created by the test runner (this current node's profile) is testKey[0], it stays the
// same after running prove
if cfgData.Profile.KeyID != testkeys.GetKeyData(0).EncodedPeerID {
t.Errorf("profile's keyID should be testKey[0]")
}
// ProfileID given to us by registry, by running prove, is testKey[3]
if cfgData.Profile.ID != testkeys.GetKeyData(3).EncodedPeerID {
t.Errorf("profile's profileID given by prove command should be testKey[3]")
}
}
2 changes: 2 additions & 0 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ func (p *Profile) Decode(sp *config.ProfilePod) error {
}
}

keyID := IDB58DecodeOrEmpty(sp.KeyID)
pro := Profile{
ID: id,
KeyID: key.ID(keyID),
Type: t,
Peername: sp.Peername,
Created: sp.Created,
Expand Down
2 changes: 1 addition & 1 deletion profile/testdata/simple.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"QmU27VdAEUL5NGM6oB56htTxvHLfcGZgsgxrJTdVr2k4zs":{"id":"QmU27VdAEUL5NGM6oB56htTxvHLfcGZgsgxrJTdVr2k4zs","peername":"test_peername","created":"2009-02-13T23:31:30Z","updated":"2009-02-13T23:31:30Z","type":"peer","email":"","name":"","description":"","homeurl":"","color":"","thumb":"","photo":"","poster":"","twitter":"","peerIDs":["/ipfs/Qmb9Gy14GuCjrhRSjGJQpf5JkgdEdbZrV81Tz4x3ZDreY3"]},"QmeL2mdVka1eahKENjehK6tBxkkpk5dNQ1qMcgWi7Hrb4B":{"id":"QmeL2mdVka1eahKENjehK6tBxkkpk5dNQ1qMcgWi7Hrb4B","privkey":"CAASqAkwggSkAgEAAoIBAQChp1HiZxTsLQCaHmW3/cc2ZDZpgLwn5o1/nZPgqT7SyXHP5bn7GQMG3kPEQWcl4nhtLX9hkrBEskHrdIlqp9zXFMwBfat+qfzCylGC/QBDF7wT9umLd7nbq7pAxQXteXgntt2Zhg4gE/kEk7vIyL+P9KpWJZ/yjpykgsDC7NPnrr8qZBo2tL0F4w+33nZhEx7Pp7Rnaq22JM8rF+NHCgSkUh63lp7Vhwm9PQoGtt0XTnEKxrMQnUme/IhGNxs84RphxHc5+nW6jYjgm5bcJonGyPU7bq+v51Mr2Ol4RT3L9ZNJgz0SWTSmAtiBLx2ryLrTjmDPSvN7wLm9sWEdWmRVAgMBAAECggEBAJMumrl+jWgz2TZ5sreBEp6NQ5VvpuDVY8PrnzaQIikdTMizK1BaB417VUwdGGM//dG5+R7HxkHl42sT4gH/8GzL/Krm1vwunXplZy3SWSi9NXsf9qgLTGebxasvOCRt0l6mesFLcxT12ma2c+VuEixp4aUqAKWB/1Ex03wm0RFBcSttPHe5ODW8Eaz+ZU8cpObEcZdCIPVxeWqLVdkAImOmsknL0EAxP8Wo/V6Rh5Cg4PnwnfJiQ45C+m6h7NTIw0H4UOncv7EBABra6LqF6Uoda9vmv8CpwaXwR557DPchQglFjtm48jWGeVKO3Zyutizu420eRrFZ0GmJo5flvkkCgYEA0SLysOZNxDgjYA0ihVYL6UbCvYUSADuDyTWREOUiRfmxAmS1xN9o7fieCJnA4aAAnSugtT2BI7HEqT1lLz0YF8NRDKL07TNbkmNLIHXBbXA5saf10N2juhflfIm5/b/W9lC3QsngMR27J25Ztqof6Ur36bIKJ6Y6XvYdlkkZkc8CgYEAxeCHUWMvtHtBID9ZOtrZRNhNJ/uz+2rzVSPd6ZdhEUWsvv/0p7JXmSAp2eoJDDKHeSnVxcxQMqhq0/edUSSzSvDpWha8UU4N8hRpu+M0XZNke0ijhpK6NIqNHPvZdsyFD0VR1Vaj2Ruy+pzih6PhqSnn2ZwvpQJAwBnqc2VCJJsCgYAkQr33hAbpxZ4EkmJw4elwye8L8x2a4rbH1TzQxBm8Lj3Nn26Qsve7gwbLkPULabWRirXzlrVkXfcuLNH1bc9Wl2vfGAYFdokjCYpGF4SxF+s47VlGnJc9tdT5UdvorjF0RaxwrRXtDi2b+Zsee8LKrU/sugzesQif3GZm30fKqwKBgQCQHwHP+HMFfAQqLZma8UzwBK7loUEsrHAAoff+K8CKKPoxvxD9lzqQD8oLqpbeaGsdh6fowe/jhaERM7dEI3vm6GK9t/N/MF+d4tpD+67nPPQhiv13haTTodo3swNnsHx1a+K3hLwf5DnOqLehXW59nET+zPAyudpZUEbft2+eYwKBgCMS6SitXwa2UjFNgkMAaOeJjkjnUKcr1tO/zPtaYPugKgkMQB890q4dcq5rnG2onhJ7hkoMwcrFugbD2nub9AIkaMc6Y46jyh2mSeA0337MpoMp99Jmp2/B1rouYo4IRS25b7jk22yjV8ARCzsxFVQxEwA1Lg8YpaXaifuI+/2O","peername":"user","created":"0001-01-01T00:00:00Z","updated":"0001-01-01T00:00:00Z","type":"peer","email":"","name":"","description":"","homeurl":"","color":"","thumb":"","photo":"","poster":"","twitter":""}}
{"QmU27VdAEUL5NGM6oB56htTxvHLfcGZgsgxrJTdVr2k4zs":{"id":"QmU27VdAEUL5NGM6oB56htTxvHLfcGZgsgxrJTdVr2k4zs","keyid":"","peername":"test_peername","created":"2009-02-13T23:31:30Z","updated":"2009-02-13T23:31:30Z","type":"peer","email":"","name":"","description":"","homeurl":"","color":"","thumb":"","photo":"","poster":"","twitter":"","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AxeCHUWMvtHtBID9ZOtrZRNhNJ/uz+2rzVSPd6ZdhEUWsvv/0p7JXmSAp2eoJDDKHeSnVxcxQMqhq0/edUSSzSvDpWha8UU4N8hRpu+M0XZNke0ijhpK6NIqNHPvZdsyFD0VR1Vaj2Ruy+pzih6PhqSnn2ZwvpQJAwBnqc2VCJJsCgYAkQr33hAbpxZ4EkmJw4elwye8L8x2a4rbH1TzQxBm8Lj3Nn26Qsve7gwbLkPULabWRirXzlrVkXfcuLNH1bc9Wl2vfGAYFdokjCYpGF4SxF+s47VlGnJc9tdT5UdvorjF0RaxwrRXtDi2b+Zsee8LKrU/sugzesQif3GZm30fKqwKBgQCQHwHP+HMFfAQqLZma8UzwBK7loUEsrHAAoff+K8CKKPoxvxD9lzqQD8oLqpbeaGsdh6fowe/jhaERM7dEI3vm6GK9t/N/MF+d4tpD+67nPPQhiv13haTTodo3swNnsHx1a+K3hLwf5DnOqLehXW59nET+zPAyudpZUEbft2+eYwKBgCMS6SitXwa2UjFNgkMAaOeJjkjnUKcr1tO/zPtaYPugKgkMQB890q4dcq5rnG2onhJ7hkoMwcrFugbD2nub9AIkaMc6Y46jyh2mSeA0337MpoMp99Jmp2/B1rouYo4IRS25b7jk22yjV8ARCzsxFVQxEwA1Lg8YpaXaifuI+/2O","peername":"user","created":"0001-01-01T00:00:00Z","updated":"0001-01-01T00:00:00Z","type":"peer","email":"","name":"","description":"","homeurl":"","color":"","thumb":"","photo":"","poster":"","twitter":""}}

0 comments on commit ee0875b

Please sign in to comment.