Skip to content

Commit f262ddf

Browse files
NikaHsnNika Hassani
authored andcommitted
fix(notifications): allow configuration when auth token is expired (#5117)
Co-authored-by: Nika Hassani <[email protected]>
1 parent 280e5f2 commit f262ddf

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

packages/notifications/push/amplify_push_notifications_pinpoint/lib/src/pinpoint_provider.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ class PinpointProvider implements ServiceProviderClient {
190190
// `AnalyticsException` converts `AWSHttpException` to `NetworkException`.
191191
} on NetworkException catch (e) {
192192
_logger.error('Network problem when registering device: ', e);
193+
// This is to allow configuration if `EndpointClient.updateEndpoint()`
194+
// throws UnknownException due to expired token.
195+
// the underlying exception is `NotAuthorizedException` with
196+
// `Invalid login token. Token expired` message.
197+
} on UnknownException catch (e) {
198+
_logger.error(
199+
'Could not update Pinpoint endpoint to register the device: ',
200+
e,
201+
);
193202
}
194203
}
195204

packages/notifications/push/amplify_push_notifications_pinpoint/test/pinpoint_provider_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,48 @@ void main() {
319319
verify(mockEndpointClient.updateEndpoint);
320320
});
321321

322+
test('registerDevice should run successfully when token is expired',
323+
() async {
324+
when(
325+
() => mockAmplifyAuthProviderRepository.getAuthProvider(
326+
APIAuthorizationType.iam.authProviderToken,
327+
),
328+
).thenReturn(awsIamAmplifyAuthProvider);
329+
when(
330+
() => mockAnalyticsClient.init(
331+
pinpointAppId: any(named: 'pinpointAppId'),
332+
region: any(named: 'region'),
333+
authProvider: any(named: 'authProvider'),
334+
),
335+
).thenAnswer((realInvocation) async {});
336+
337+
final mockEndpointClient = MockEndpointClient();
338+
339+
when(mockEndpointClient.updateEndpoint)
340+
.thenThrow(const UnknownException('message'));
341+
342+
when(
343+
() => mockAnalyticsClient.endpointClient,
344+
).thenReturn(mockEndpointClient);
345+
346+
await expectLater(
347+
pinpointProvider.init(
348+
config: notificationsPinpointConfig,
349+
authProviderRepo: mockAmplifyAuthProviderRepository,
350+
analyticsClient: mockAnalyticsClient,
351+
),
352+
completes,
353+
);
354+
355+
expect(
356+
pinpointProvider.registerDevice(
357+
'',
358+
),
359+
completes,
360+
);
361+
verify(mockEndpointClient.updateEndpoint);
362+
});
363+
322364
test('recordEvent should run successfully', () async {
323365
when(
324366
() => mockAmplifyAuthProviderRepository.getAuthProvider(

0 commit comments

Comments
 (0)