mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 09:04:19 +01:00
unit tests: remove use of onion type V2
We only support tor V3.
This commit is contained in:
@@ -11,12 +11,12 @@ import (
|
|||||||
// onion service exists in the store. If it does, it's compared against what's
|
// onion service exists in the store. If it does, it's compared against what's
|
||||||
// expected.
|
// expected.
|
||||||
func assertPrivateKeyExists(t *testing.T, store *onionStore,
|
func assertPrivateKeyExists(t *testing.T, store *onionStore,
|
||||||
onionType tor.OnionType, expPrivateKey *[]byte) {
|
expPrivateKey *[]byte) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
exists := expPrivateKey != nil
|
exists := expPrivateKey != nil
|
||||||
privateKey, err := store.PrivateKey(onionType)
|
privateKey, err := store.PrivateKey()
|
||||||
switch {
|
switch {
|
||||||
case exists && err != nil:
|
case exists && err != nil:
|
||||||
t.Fatalf("unable to retrieve private key: %v", err)
|
t.Fatalf("unable to retrieve private key: %v", err)
|
||||||
@@ -32,8 +32,8 @@ func assertPrivateKeyExists(t *testing.T, store *onionStore,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestOnionStore ensures the different operations of the onionStore behave as
|
// TestOnionStore ensures the different operations of the onionStore behave
|
||||||
// espected.
|
// as expected.
|
||||||
func TestOnionStore(t *testing.T) {
|
func TestOnionStore(t *testing.T) {
|
||||||
etcdClient, serverCleanup := etcdSetup(t)
|
etcdClient, serverCleanup := etcdSetup(t)
|
||||||
defer etcdClient.Close()
|
defer etcdClient.Close()
|
||||||
@@ -42,40 +42,22 @@ func TestOnionStore(t *testing.T) {
|
|||||||
// Upon a fresh initialization of the store, no private keys should
|
// Upon a fresh initialization of the store, no private keys should
|
||||||
// exist for any onion service type.
|
// exist for any onion service type.
|
||||||
store := newOnionStore(etcdClient)
|
store := newOnionStore(etcdClient)
|
||||||
assertPrivateKeyExists(t, store, tor.V2, nil)
|
assertPrivateKeyExists(t, store, nil)
|
||||||
assertPrivateKeyExists(t, store, tor.V3, nil)
|
|
||||||
|
|
||||||
// Store a private key for a V2 onion service and check it was stored
|
// Store a private key for an onion service and check it was stored
|
||||||
// correctly.
|
// correctly.
|
||||||
privateKeyV2 := []byte("hide_me_plz_v2")
|
privateKey := []byte("hide_me_plz")
|
||||||
if err := store.StorePrivateKey(tor.V2, privateKeyV2); err != nil {
|
if err := store.StorePrivateKey(privateKey); err != nil {
|
||||||
t.Fatalf("unable to store private key for v2 onion service: %v",
|
t.Fatalf("unable to store private key for onion service: %v",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
assertPrivateKeyExists(t, store, tor.V2, &privateKeyV2)
|
assertPrivateKeyExists(t, store, &privateKey)
|
||||||
|
|
||||||
// Store a private key for a V3 onion service and check it was stored
|
// Delete the private key for the onion service and check that it was
|
||||||
// correctly.
|
|
||||||
privateKeyV3 := []byte("hide_me_plz_v3")
|
|
||||||
if err := store.StorePrivateKey(tor.V3, privateKeyV3); err != nil {
|
|
||||||
t.Fatalf("unable to store private key for v3 onion service: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
assertPrivateKeyExists(t, store, tor.V3, &privateKeyV3)
|
|
||||||
|
|
||||||
// Delete the private key for the V2 onion service and check that it was
|
|
||||||
// indeed successful.
|
// indeed successful.
|
||||||
if err := store.DeletePrivateKey(tor.V2); err != nil {
|
if err := store.DeletePrivateKey(); err != nil {
|
||||||
t.Fatalf("unable to remove private key for v2 onion service: %v",
|
t.Fatalf("unable to remove private key for onion service: %v",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
assertPrivateKeyExists(t, store, tor.V2, nil)
|
assertPrivateKeyExists(t, store, nil)
|
||||||
|
|
||||||
// Delete the private key for the V3 onion service and check that it was
|
|
||||||
// indeed successful.
|
|
||||||
if err := store.DeletePrivateKey(tor.V3); err != nil {
|
|
||||||
t.Fatalf("unable to remove private key for v3 onion service: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
assertPrivateKeyExists(t, store, tor.V3, nil)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user