Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when empty key packages are found #398

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/docker/env
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
}
2 changes: 1 addition & 1 deletion dev/e2e/docker/env
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
}
4 changes: 4 additions & 0 deletions pkg/mls/api/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 %d", len(ids), len(installations))
}

resPackages := make([]*mlsv1.FetchKeyPackagesResponse_KeyPackage, len(ids))
for _, installation := range installations {

Expand Down
31 changes: 29 additions & 2 deletions pkg/mls/api/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -216,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) {
Expand Down
Loading