diff --git a/go.mod b/go.mod index 8bb0e7aab1344727b5e648182f84b74b65e2fee3..e366f452f1c7705955523108d05267ba9c5dac63 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/spf13/cobra v1.5.0 github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/viper v1.12.0 + github.com/stretchr/testify v1.8.0 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f gitlab.com/elixxir/comms v0.0.4-0.20220822222744-66e73546e3b8 gitlab.com/elixxir/crypto v0.0.7-0.20220822200404-0be5ac9167ba @@ -30,6 +31,7 @@ require ( github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect github.com/badoux/checkmail v1.2.1 // indirect github.com/cenkalti/backoff/v4 v4.1.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/elliotchance/orderedmap v1.4.0 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect @@ -43,6 +45,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/soheilhy/cmux v0.1.5 // indirect diff --git a/go.sum b/go.sum index 81b64b0363adf348a40bfa48d15619721815d258..b5dc860148bcf1f09b96a21c92aaaaf161d70efb 100644 --- a/go.sum +++ b/go.sum @@ -571,6 +571,7 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3 github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -580,6 +581,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs= github.com/subosito/gotenv v1.4.0 h1:yAzM1+SmVcz5R4tXGsNMu1jUl2aOJXoiWUCEwwnGrvs= github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo= diff --git a/ud/channelIDTracking_test.go b/ud/channelIDTracking_test.go new file mode 100644 index 0000000000000000000000000000000000000000..6b2ecbe4096a4064573a60a994759fe9285057fe --- /dev/null +++ b/ud/channelIDTracking_test.go @@ -0,0 +1,78 @@ +package ud + +import ( + "crypto/ed25519" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "gitlab.com/xx_network/comms/connect" + "gitlab.com/xx_network/crypto/csprng" + "gitlab.com/xx_network/crypto/signature/rsa" + "gitlab.com/xx_network/primitives/id" + + "gitlab.com/elixxir/client/event" + "gitlab.com/elixxir/client/storage/versioned" + store "gitlab.com/elixxir/client/ud/store" + "gitlab.com/elixxir/crypto/fastRNG" + "gitlab.com/elixxir/ekv" +) + +func TestChannelIDTracking(t *testing.T) { + + rngGen := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) + + // AddHost + stream := rngGen.GetStream() + privKey, err := rsa.GenerateKey(stream, 1024) + require.NoError(t, err) + + tnm := newTestNetworkManager(t) + managerkv := versioned.NewKV(ekv.MakeMemstore()) + udStore, err := store.NewOrLoadStore(managerkv) + m := &Manager{ + user: mockE2e{ + grp: getGroup(), + events: event.NewEventManager(), + rng: rngGen, + kv: managerkv, + network: tnm, + t: t, + key: privKey, + }, + store: udStore, + comms: &mockComms{}, + } + + netDef := m.getCmix().GetInstance().GetPartialNdf().Get() + udID, err := id.Unmarshal(netDef.UDB.ID) + require.NoError(t, err) + + params := connect.GetDefaultHostParams() + params.AuthEnabled = false + params.SendTimeout = 20 * time.Second + + host, err := m.comms.AddHost(udID, netDef.UDB.Address, + []byte(netDef.UDB.Cert), params) + require.NoError(t, err) + + // + + kv := versioned.NewKV(ekv.MakeMemstore()) + comms := new(mockComms) + username := "Alice" + // doesn't work: + //username, err := m.store.GetUsername() + //require.NoError(t, err) + + udPubKeyBytes := m.user.GetCmix().GetInstance().GetPartialNdf().Get().UDB.DhPubKey + + myTestClientIDTracker := newclientIDTracker(comms, host, username, kv, m.user.GetReceptionIdentity(), ed25519.PublicKey(udPubKeyBytes), rngGen) + + stopper, err := myTestClientIDTracker.Start() + require.NoError(t, err) + + err = stopper.Close() + require.NoError(t, err) +}