From 0822a2245f9e7292681bee87d5cb8bc391a50957 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:45:34 -0700 Subject: [PATCH 1/5] Error when empty key packages are found --- pkg/mls/api/v1/service.go | 4 ++++ pkg/mls/api/v1/service_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkg/mls/api/v1/service.go b/pkg/mls/api/v1/service.go index 56c18c67..4888ca55 100644 --- a/pkg/mls/api/v1/service.go +++ b/pkg/mls/api/v1/service.go @@ -147,6 +147,10 @@ func (s *Service) FetchKeyPackages(ctx context.Context, req *mlsv1.FetchKeyPacka keyPackageMap[string(id)] = idx } + if len(installations) != len(ids) { + return nil, status.Errorf(codes.NotFound, "requested %d key packages but only received %s", len(ids), len(installations)) + } + resPackages := make([]*mlsv1.FetchKeyPackagesResponse_KeyPackage, len(ids)) for _, installation := range installations { diff --git a/pkg/mls/api/v1/service_test.go b/pkg/mls/api/v1/service_test.go index 479bdd78..122a1ac7 100644 --- a/pkg/mls/api/v1/service_test.go +++ b/pkg/mls/api/v1/service_test.go @@ -207,6 +207,33 @@ func TestFetchKeyPackages(t *testing.T) { require.Equal(t, []byte("test"), consumeRes.KeyPackages[1].KeyPackageTlsSerialized) } +func TestMissingKeyPackage(t *testing.T) { + ctx := context.Background() + svc, _, mlsValidationService, cleanup := newTestService(t, ctx) + defer cleanup() + + installationId1 := test.RandomBytes(32) + inboxId := test.RandomInboxId() + + mockValidateInboxIdKeyPackages(mlsValidationService, installationId1, inboxId) + + _, err := svc.RegisterInstallation(ctx, &mlsv1.RegisterInstallationRequest{ + KeyPackage: &mlsv1.KeyPackageUpload{ + KeyPackageTlsSerialized: []byte("test"), + }, + IsInboxIdCredential: false, + }) + require.NoError(t, err) + + // Request a second key package that doesn't exist + results, err := svc.FetchKeyPackages(ctx, &mlsv1.FetchKeyPackagesRequest{ + InstallationKeys: [][]byte{installationId1, test.RandomBytes(32)}, + }) + require.Nil(t, results) + require.Error(t, err) + require.Contains(t, err.Error(), "requested 2 key packages but only received 1") +} + // Trying to fetch key packages that don't exist should return nil func TestFetchKeyPackagesFail(t *testing.T) { ctx := context.Background() From f7ae92c2c62181604b44704c81e3aad8ca64866b Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:53:14 -0700 Subject: [PATCH 2/5] Fix docker compose command --- dev/docker/env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/docker/env b/dev/docker/env index f4b6cead..c3440a8a 100755 --- a/dev/docker/env +++ b/dev/docker/env @@ -2,5 +2,5 @@ set -e function docker_compose() { - docker-compose -f dev/docker/docker-compose.yml -p xmtpd "$@" + docker compose -f dev/docker/docker-compose.yml -p xmtpd "$@" } From 4e218ac51f48ffa690e270697828e331481554fe Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:57:08 -0700 Subject: [PATCH 3/5] Fix error string --- pkg/mls/api/v1/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mls/api/v1/service.go b/pkg/mls/api/v1/service.go index 4888ca55..62a2e3fc 100644 --- a/pkg/mls/api/v1/service.go +++ b/pkg/mls/api/v1/service.go @@ -148,7 +148,7 @@ func (s *Service) FetchKeyPackages(ctx context.Context, req *mlsv1.FetchKeyPacka } if len(installations) != len(ids) { - return nil, status.Errorf(codes.NotFound, "requested %d key packages but only received %s", len(ids), len(installations)) + return nil, status.Errorf(codes.NotFound, "requested %d key packages but only received %d", len(ids), len(installations)) } resPackages := make([]*mlsv1.FetchKeyPackagesResponse_KeyPackage, len(ids)) From 809a90be114fd27f6aeefff33f049e94030201d5 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:58:24 -0700 Subject: [PATCH 4/5] Fix other old syntax docker-compose command --- dev/e2e/docker/env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/e2e/docker/env b/dev/e2e/docker/env index bb308135..5064cdbf 100755 --- a/dev/e2e/docker/env +++ b/dev/e2e/docker/env @@ -2,5 +2,5 @@ set -e function docker_compose() { - docker-compose -f dev/e2e/docker/docker-compose.yml -p xmtpd-e2e "$@" + docker compose -f dev/e2e/docker/docker-compose.yml -p xmtpd-e2e "$@" } From 49c890bc24882904e594e2a423c0e6e67574922d Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 12 Aug 2024 22:05:11 -0700 Subject: [PATCH 5/5] Fix other test --- pkg/mls/api/v1/service_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mls/api/v1/service_test.go b/pkg/mls/api/v1/service_test.go index 122a1ac7..ad063504 100644 --- a/pkg/mls/api/v1/service_test.go +++ b/pkg/mls/api/v1/service_test.go @@ -243,8 +243,8 @@ func TestFetchKeyPackagesFail(t *testing.T) { consumeRes, err := svc.FetchKeyPackages(ctx, &mlsv1.FetchKeyPackagesRequest{ InstallationKeys: [][]byte{test.RandomBytes(32)}, }) - require.Nil(t, err) - require.Equal(t, []*mlsv1.FetchKeyPackagesResponse_KeyPackage{nil}, consumeRes.KeyPackages) + require.Error(t, err) + require.Nil(t, consumeRes) } func TestSendGroupMessages(t *testing.T) {