From a8cb6e560ea5fadc0de329794a52b40342919ee1 Mon Sep 17 00:00:00 2001 From: arnauds5 Date: Wed, 26 Jun 2024 09:20:13 +0200 Subject: [PATCH] Add a test --- .../federation/hfederation/federation_test.go | 13 +++++++++++++ be1-go/internal/test/generator/federation.go | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/be1-go/internal/handler/channel/federation/hfederation/federation_test.go b/be1-go/internal/handler/channel/federation/hfederation/federation_test.go index dbd80d1cec..3ecb784900 100644 --- a/be1-go/internal/handler/channel/federation/hfederation/federation_test.go +++ b/be1-go/internal/handler/channel/federation/hfederation/federation_test.go @@ -74,6 +74,9 @@ func Test_handleChannelFederation(t *testing.T) { laoPath := fmt.Sprintf("/root/%s", laoID) channelPath := fmt.Sprintf("/root/%s/federation", laoID) + rollcallId := "fEvAfdtNrykd9NPYl9ReHLX-6IP6SFLKTZJLeGUHZ_U=" + tokens := []string{organizer} + serverAddressA := "ws://localhost:9801/client" value := "82eadde2a4ba832518b90bb93c8480ee1ae16a91d5efe9281e91e2ec11da03e4" validUntil := time.Now().Add(5 * time.Minute).Unix() @@ -318,6 +321,16 @@ func Test_handleChannelFederation(t *testing.T) { contains: "sql: no rows in result set", }) + // Test 19 Error when token exchange sender is not the organizerPk + args = append(args, input{ + name: "Test 19", + channelPath: channelPath, + msg: generator.NewTokensExchange(t, notOrganizer, laoID, rollcallId, + time.Now().Unix(), tokens, notOrganizerSk), + isError: true, + contains: "sender is not the organizer of the channelPath", + }) + for _, arg := range args { t.Run(arg.name, func(t *testing.T) { err = federationHandler.Handle(arg.channelPath, arg.msg, &fakeSocket) diff --git a/be1-go/internal/test/generator/federation.go b/be1-go/internal/test/generator/federation.go index adc546fc6a..9ca14eb78a 100644 --- a/be1-go/internal/test/generator/federation.go +++ b/be1-go/internal/test/generator/federation.go @@ -126,3 +126,22 @@ func NewFailedFederationResult(t *testing.T, sender, reason string, return msg } + +func NewTokensExchange(t *testing.T, sender, laoId, rollcallId string, + timestamp int64, tokens []string, senderSk kyber.Scalar) mmessage.Message { + tokensExchange := mfederation.FederationTokensExchange{ + Object: channel.FederationObject, + Action: channel.FederationActionTokensExchange, + LaoId: laoId, + RollcallId: rollcallId, + Timestamp: timestamp, + Tokens: tokens, + } + + tokensExchangeBuf, err := json.Marshal(tokensExchange) + require.NoError(t, err) + + msg := newMessage(t, sender, senderSk, tokensExchangeBuf) + + return msg +}