|
|
@ -282,78 +282,167 @@ OUTER2: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientListKeysLAN(t *testing.T) { |
|
|
|
func TestRPCClientListKeys(t *testing.T) { |
|
|
|
key1 := "tbLJg26ZJyJ9pK3qhc9jig==" |
|
|
|
key1 := "tbLJg26ZJyJ9pK3qhc9jig==" |
|
|
|
conf := Config{EncryptKey: key1} |
|
|
|
conf := Config{EncryptKey: key1} |
|
|
|
p1 := testRPCClientWithConfig(t, &conf) |
|
|
|
p1 := testRPCClientWithConfig(t, &conf) |
|
|
|
defer p1.Close() |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
keys, numNodes, messages, err := p1.client.ListKeysLAN() |
|
|
|
// Check WAN keys
|
|
|
|
if err != nil { |
|
|
|
keys := listKeys(t, p1.client, false) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
if _, ok := keys[key1]; !ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check LAN keys
|
|
|
|
|
|
|
|
keys = listKeys(t, p1.client, true) |
|
|
|
if _, ok := keys[key1]; !ok { |
|
|
|
if _, ok := keys[key1]; !ok { |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientInstallKey(t *testing.T) { |
|
|
|
|
|
|
|
key1 := "tbLJg26ZJyJ9pK3qhc9jig==" |
|
|
|
|
|
|
|
key2 := "xAEZ3uVHRMZD9GcYMZaRQw==" |
|
|
|
|
|
|
|
conf := Config{EncryptKey: key1} |
|
|
|
|
|
|
|
p1 := testRPCClientWithConfig(t, &conf) |
|
|
|
|
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test WAN keys
|
|
|
|
|
|
|
|
keys := listKeys(t, p1.client, true) |
|
|
|
|
|
|
|
if _, ok := keys[key2]; ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
installKey(t, p1.client, key2, true) |
|
|
|
|
|
|
|
|
|
|
|
if keys[key1] != 1 { |
|
|
|
keys = listKeys(t, p1.client, true) |
|
|
|
|
|
|
|
if _, ok := keys[key2]; !ok { |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if numNodes != 1 { |
|
|
|
// Test LAN keys
|
|
|
|
t.Fatalf("bad: %d", numNodes) |
|
|
|
keys = listKeys(t, p1.client, false) |
|
|
|
|
|
|
|
if _, ok := keys[key2]; ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(messages) != 0 { |
|
|
|
installKey(t, p1.client, key2, false) |
|
|
|
t.Fatalf("bad: %#v", messages) |
|
|
|
|
|
|
|
|
|
|
|
keys = listKeys(t, p1.client, false) |
|
|
|
|
|
|
|
if _, ok := keys[key2]; !ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientListKeysWAN(t *testing.T) { |
|
|
|
func TestRPCClientRotateKey(t *testing.T) { |
|
|
|
key1 := "tbLJg26ZJyJ9pK3qhc9jig==" |
|
|
|
key1 := "tbLJg26ZJyJ9pK3qhc9jig==" |
|
|
|
|
|
|
|
key2 := "xAEZ3uVHRMZD9GcYMZaRQw==" |
|
|
|
conf := Config{EncryptKey: key1} |
|
|
|
conf := Config{EncryptKey: key1} |
|
|
|
p1 := testRPCClientWithConfig(t, &conf) |
|
|
|
p1 := testRPCClientWithConfig(t, &conf) |
|
|
|
defer p1.Close() |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
keys, numNodes, messages, err := p1.client.ListKeysWAN() |
|
|
|
// Test WAN keys
|
|
|
|
if err != nil { |
|
|
|
keys := listKeys(t, p1.client, true) |
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
if _, ok := keys[key2]; ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if _, ok := keys[key1]; !ok { |
|
|
|
installKey(t, p1.client, key2, true) |
|
|
|
|
|
|
|
useKey(t, p1.client, key2, true) |
|
|
|
|
|
|
|
removeKey(t, p1.client, key1, true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keys = listKeys(t, p1.client, true) |
|
|
|
|
|
|
|
if _, ok := keys[key1]; ok { |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := keys[key2]; !ok { |
|
|
|
if keys[key1] != 1 { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if numNodes != 1 { |
|
|
|
// Test LAN keys
|
|
|
|
t.Fatalf("bad: %d", numNodes) |
|
|
|
keys = listKeys(t, p1.client, false) |
|
|
|
|
|
|
|
if _, ok := keys[key2]; ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(messages) != 0 { |
|
|
|
installKey(t, p1.client, key2, false) |
|
|
|
t.Fatalf("bad: %#v", messages) |
|
|
|
useKey(t, p1.client, key2, false) |
|
|
|
|
|
|
|
removeKey(t, p1.client, key1, false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keys = listKeys(t, p1.client, false) |
|
|
|
|
|
|
|
if _, ok := keys[key1]; ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := keys[key2]; !ok { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", keys) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientListKeysLAN_encryptionDisabled(t *testing.T) { |
|
|
|
func TestRPCClientKeyOperation_encryptionDisabled(t *testing.T) { |
|
|
|
p1 := testRPCClient(t) |
|
|
|
p1 := testRPCClient(t) |
|
|
|
defer p1.Close() |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
_, _, _, err := p1.client.ListKeysLAN() |
|
|
|
_, _, failures, err := p1.client.ListKeysLAN() |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
t.Fatalf("no error listing keys with encryption disabled") |
|
|
|
t.Fatalf("no error listing keys with encryption disabled") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(failures) != 1 { |
|
|
|
|
|
|
|
t.Fatalf("bad: %#v", failures) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestRPCClientListKeysWAN_encryptionDisabled(t *testing.T) { |
|
|
|
func listKeys(t *testing.T, c *RPCClient, wan bool) (keys map[string]int) { |
|
|
|
p1 := testRPCClient(t) |
|
|
|
var err error |
|
|
|
defer p1.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, _, _, err := p1.client.ListKeysWAN() |
|
|
|
if wan { |
|
|
|
if err == nil { |
|
|
|
keys, _, _, err = c.ListKeysWAN() |
|
|
|
t.Fatalf("no error listing keys with encryption disabled") |
|
|
|
} else { |
|
|
|
|
|
|
|
keys, _, _, err = c.ListKeysLAN() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func installKey(t *testing.T, c *RPCClient, key string, wan bool) { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if wan { |
|
|
|
|
|
|
|
_, err = c.InstallKeyWAN(key) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_, err = c.InstallKeyLAN(key) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func useKey(t *testing.T, c *RPCClient, key string, wan bool) { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if wan { |
|
|
|
|
|
|
|
_, err = c.UseKeyWAN(key) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_, err = c.UseKeyLAN(key) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func removeKey(t *testing.T, c *RPCClient, key string, wan bool) { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if wan { |
|
|
|
|
|
|
|
_, err = c.RemoveKeyWAN(key) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_, err = c.RemoveKeyLAN(key) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("err: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|