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

e2ee extension: ensure null is not sent when we mean [] #440

Merged
merged 2 commits into from
May 20, 2024
Merged
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
6 changes: 6 additions & 0 deletions sync3/extensions/e2ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions tests-integration/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading