From e295c31ab722325945192645db28f5182359e0f3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Mon, 20 May 2024 13:57:24 +0100 Subject: [PATCH 1/2] Ensure null is not sent when we mean [] --- sync3/extensions/e2ee.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sync3/extensions/e2ee.go b/sync3/extensions/e2ee.go index 01711d6a..1dbcad45 100644 --- a/sync3/extensions/e2ee.go +++ b/sync3/extensions/e2ee.go @@ -70,6 +70,12 @@ func (r *E2EERequest) ProcessInitial(ctx context.Context, res *Response, extCtx extRes.OTKCounts = dd.OTKCounts hasUpdates = true } + if dd.DeviceListChanged == nil { + dd.DeviceListChanged = make([]string, 0) + } + if dd.DeviceListLeft == nil { + dd.DeviceListLeft = make([]string, 0) + } if len(dd.DeviceListChanged) > 0 || len(dd.DeviceListLeft) > 0 { extRes.DeviceLists = &E2EEDeviceList{ Changed: dd.DeviceListChanged, From 451f6fb9c877af0b79fa18b6640438c594448b3f Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Mon, 20 May 2024 14:02:29 +0100 Subject: [PATCH 2/2] Add regression test --- tests-integration/extensions_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests-integration/extensions_test.go b/tests-integration/extensions_test.go index b2f271f7..ed25a074 100644 --- a/tests-integration/extensions_test.go +++ b/tests-integration/extensions_test.go @@ -235,6 +235,32 @@ func TestExtensionE2EE(t *testing.T) { }) m.MatchResponse(t, res, m.MatchDeviceLists(wantChanged, wantLeft)) + // check that empty lists aren't serialised as null + v2.queueResponse(alice, sync2.SyncResponse{ + DeviceLists: struct { + Changed []string `json:"changed,omitempty"` + Left []string `json:"left,omitempty"` + }{ + Changed: wantChanged, + }, + }) + v2.waitUntilEmpty(t, alice) + res = v3.mustDoV3RequestWithPos(t, aliceToken, res.Pos, sync3.Request{ + Lists: map[string]sync3.RequestList{"a": { + Ranges: sync3.SliceRanges{ + [2]int64{0, 10}, // doesn't matter + }, + }}, + // enable the E2EE extension + Extensions: extensions.Request{ + E2EE: &extensions.E2EERequest{ + Core: extensions.Core{Enabled: &boolTrue}, + }, + }, + }) + if res.Extensions.E2EE.DeviceLists.Left == nil { + t.Errorf("left array should be [] not null") + } } // Checks that to-device messages are passed from v2 to v3