Skip to content

Commit 144dbb1

Browse files
committed
ios notif: Require realm_uri in payload, present since server 1.9.
This release has been out for nearly three years (since 2018-11-07), so it's long past time for anyone running an older version to upgrade. We decided earlier this year to stop supporting older than 2.1.x; and since the mobile release v27.165 of a couple of months ago, anyone using a server older than 2.0.x has gotten a warning banner about it. As of this commit, our post-parse `Notification` type still sees `realm_uri` as optional. We'll tighten that after making it similarly required in the Android-native parsing code.
1 parent 2bd7794 commit 144dbb1

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/notification/__tests__/notification-test.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import * as eg from '../../__tests__/lib/exampleData';
1111
import { fromAPNsImpl as extractIosNotificationData } from '../extract';
1212
import objectEntries from '../../utils/objectEntries';
1313

14+
const realm_uri = eg.realm.toString();
15+
1416
describe('getNarrowFromNotificationData', () => {
1517
const ownUserId = eg.selfUser.user_id;
1618

@@ -61,9 +63,9 @@ describe('getNarrowFromNotificationData', () => {
6163

6264
describe('extract iOS notification data', () => {
6365
const barebones = deepFreeze({
64-
stream: { recipient_type: 'stream', stream: 'announce', topic: 'New channel' },
65-
'1:1 PM': { recipient_type: 'private', sender_email: '[email protected]' },
66-
'group PM': { recipient_type: 'private', pm_users: '54,321' },
66+
stream: { recipient_type: 'stream', stream: 'announce', topic: 'New channel', realm_uri },
67+
'1:1 PM': { recipient_type: 'private', sender_email: '[email protected]', realm_uri },
68+
'group PM': { recipient_type: 'private', pm_users: '54,321', realm_uri },
6769
});
6870

6971
describe('success', () => {
@@ -72,7 +74,7 @@ describe('extract iOS notification data', () => {
7274

7375
for (const [type, data] of objectEntries(barebones)) {
7476
test(`${type} notification`, () => {
75-
// barebones 1.8.0-style message is accepted
77+
// barebones 1.9.0-style message is accepted
7678
const msg = data;
7779
expect(verify(msg)).toEqual(msg);
7880

@@ -83,10 +85,6 @@ describe('extract iOS notification data', () => {
8385
// unknown fields are ignored and not copied
8486
const msg2a = { ...msg, unknown_data: ['unknown_data'] };
8587
expect(verify(msg2a)).toEqual(msg);
86-
87-
// realm_uri is copied if present
88-
const msg3 = { ...msg, realm_uri: 'https://zulip.example.org' };
89-
expect(verify(msg3)).toEqual(msg3);
9088
});
9189
}
9290
});
@@ -106,24 +104,33 @@ describe('extract iOS notification data', () => {
106104
test('very-old-style messages', () => {
107105
const sender_email = '[email protected]';
108106
// baseline
109-
expect(make({ recipient_type: 'private', sender_email })).toBeTruthy();
107+
expect(make({ realm_uri, recipient_type: 'private', sender_email })).toBeTruthy();
110108
// missing recipient_type
111-
expect(make({ sender_email })).toThrow(/archaic/);
109+
expect(make({ realm_uri, sender_email })).toThrow(/archaic/);
110+
// missing realm_uri
111+
expect(make({ recipient_type: 'private', sender_email })).toThrow(/archaic/);
112112
});
113113

114114
test('broken or partial messages', () => {
115-
expect(make({ recipient_type: 'huddle' })).toThrow(/invalid/);
116-
expect(make({ recipient_type: 'stream' })).toThrow(/invalid/);
117-
expect(make({ recipient_type: 'stream', stream: 'stream name' })).toThrow(/invalid/);
118-
expect(make({ recipient_type: 'stream', subject: 'topic' })).toThrow(/invalid/);
119-
expect(make({ recipient_type: 'private', subject: 'topic' })).toThrow(/invalid/);
115+
expect(make({ realm_uri, recipient_type: 'huddle' })).toThrow(/invalid/);
116+
expect(make({ realm_uri, recipient_type: 'stream' })).toThrow(/invalid/);
117+
expect(make({ realm_uri, recipient_type: 'stream', stream: 'stream name' })).toThrow(
118+
/invalid/,
119+
);
120+
expect(make({ realm_uri, recipient_type: 'stream', subject: 'topic' })).toThrow(/invalid/);
121+
expect(make({ realm_uri, recipient_type: 'private', subject: 'topic' })).toThrow(/invalid/);
120122
});
121123

122124
test('values of incorrect type', () => {
123-
expect(make({ recipient_type: 'private', pm_users: [1, 2, 3] })).toThrow(/invalid/);
124-
expect(make({ recipient_type: 'stream', stream: [], topic: 'yes' })).toThrow(/invalid/);
125+
expect(make({ realm_uri, recipient_type: 'private', pm_users: [1, 2, 3] })).toThrow(
126+
/invalid/,
127+
);
128+
expect(make({ realm_uri, recipient_type: 'stream', stream: [], topic: 'yes' })).toThrow(
129+
/invalid/,
130+
);
125131
expect(
126132
make({
133+
realm_uri,
127134
recipient_type: 'stream',
128135
stream: { name: 'somewhere' },
129136
topic: 'no',
@@ -134,15 +141,15 @@ describe('extract iOS notification data', () => {
134141
test('optional data is typechecked', () => {
135142
expect(
136143
make({
137-
realm_uri: null,
138144
...barebones.stream,
145+
realm_uri: null,
139146
}),
140147
).toThrow(/invalid/);
141148

142149
expect(
143150
make({
144-
realm_uri: ['array', 'of', 'string'],
145151
...barebones['group PM'],
152+
realm_uri: ['array', 'of', 'string'],
146153
}),
147154
).toThrow(/invalid/);
148155
});

src/notification/extract.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ export const fromAPNsImpl = (rawData: ?JSONableDict): Notification | void => {
168168
}
169169

170170
const { realm_uri } = zulip;
171-
if (realm_uri !== undefined && typeof realm_uri !== 'string') {
171+
if (realm_uri === undefined) {
172+
throw err('archaic (pre-1.9.x)');
173+
}
174+
if (typeof realm_uri !== 'string') {
172175
throw err('invalid');
173176
}
174-
const realm_uri_obj = Object.freeze(realm_uri === undefined ? {} : { realm_uri });
175177

176178
if (recipient_type === 'stream') {
177179
const { stream, topic } = zulip;
@@ -182,7 +184,7 @@ export const fromAPNsImpl = (rawData: ?JSONableDict): Notification | void => {
182184
recipient_type: 'stream',
183185
stream,
184186
topic,
185-
...realm_uri_obj,
187+
realm_uri,
186188
};
187189
} else {
188190
/* recipient_type === 'private' */
@@ -199,14 +201,14 @@ export const fromAPNsImpl = (rawData: ?JSONableDict): Notification | void => {
199201
return {
200202
recipient_type: 'private',
201203
pm_users: ids.sort((a, b) => a - b).join(','),
202-
...realm_uri_obj,
204+
realm_uri,
203205
};
204206
}
205207

206208
if (typeof sender_email !== 'string') {
207209
throw err('invalid');
208210
}
209-
return { recipient_type: 'private', sender_email, ...realm_uri_obj };
211+
return { recipient_type: 'private', sender_email, realm_uri };
210212
}
211213

212214
/* unreachable */

0 commit comments

Comments
 (0)