|
|
@ -315,9 +315,11 @@ func TestRPCClientInstallKey(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// install key2
|
|
|
|
// install key2
|
|
|
|
if _, err := p1.client.InstallKey(key2); err != nil { |
|
|
|
r, err := p1.client.InstallKey(key2) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringSuccess(t, r) |
|
|
|
|
|
|
|
|
|
|
|
// key2 should now be installed
|
|
|
|
// key2 should now be installed
|
|
|
|
keys = listKeys(t, p1.client) |
|
|
|
keys = listKeys(t, p1.client) |
|
|
@ -337,9 +339,11 @@ func TestRPCClientUseKey(t *testing.T) { |
|
|
|
defer p1.Close() |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
// add a second key to the ring
|
|
|
|
// add a second key to the ring
|
|
|
|
if _, err := p1.client.InstallKey(key2); err != nil { |
|
|
|
r, err := p1.client.InstallKey(key2) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringSuccess(t, r) |
|
|
|
|
|
|
|
|
|
|
|
// key2 is installed
|
|
|
|
// key2 is installed
|
|
|
|
keys := listKeys(t, p1.client) |
|
|
|
keys := listKeys(t, p1.client) |
|
|
@ -351,19 +355,25 @@ func TestRPCClientUseKey(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// can't remove key1 yet
|
|
|
|
// can't remove key1 yet
|
|
|
|
if _, err := p1.client.RemoveKey(key1); err == nil { |
|
|
|
r, err = p1.client.RemoveKey(key1) |
|
|
|
t.Fatalf("expected error removing primary key") |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringError(t, r) |
|
|
|
|
|
|
|
|
|
|
|
// change primary key
|
|
|
|
// change primary key
|
|
|
|
if _, err := p1.client.UseKey(key2); err != nil { |
|
|
|
r, err = p1.client.UseKey(key2) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringSuccess(t, r) |
|
|
|
|
|
|
|
|
|
|
|
// can remove key1 now
|
|
|
|
// can remove key1 now
|
|
|
|
if _, err := p1.client.RemoveKey(key1); err != nil { |
|
|
|
r, err = p1.client.RemoveKey(key1) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringSuccess(t, r) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) { |
|
|
|
func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) { |
|
|
@ -371,13 +381,10 @@ func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) { |
|
|
|
defer p1.Close() |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
r, err := p1.client.ListKeys() |
|
|
|
r, err := p1.client.ListKeys() |
|
|
|
if err == nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("no error listing keys with encryption disabled") |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(r.Messages) != 1 { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", r) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
keyringError(t, r) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func listKeys(t *testing.T, c *RPCClient) map[string]map[string]int { |
|
|
|
func listKeys(t *testing.T, c *RPCClient) map[string]map[string]int { |
|
|
@ -395,3 +402,19 @@ func listKeys(t *testing.T, c *RPCClient) map[string]map[string]int { |
|
|
|
} |
|
|
|
} |
|
|
|
return out |
|
|
|
return out |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func keyringError(t *testing.T, r keyResponse) { |
|
|
|
|
|
|
|
for _, i := range r.Info { |
|
|
|
|
|
|
|
if i.Error == "" { |
|
|
|
|
|
|
|
t.Fatalf("no error reported from %s (%s)", i.Datacenter, i.Pool) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func keyringSuccess(t *testing.T, r keyResponse) { |
|
|
|
|
|
|
|
for _, i := range r.Info { |
|
|
|
|
|
|
|
if i.Error != "" { |
|
|
|
|
|
|
|
t.Fatalf("error from %s (%s): %s", i.Datacenter, i.Pool, i.Error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|