OneSignal / OneSignal-iOS-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native iOS app with OneSignal. https://onesignal.com
Other
493 stars 262 forks source link

[Bug] Make null values safe for IAM requests #1457

Closed nan-li closed 2 months ago

nan-li commented 3 months ago

Description

One Line Summary

Make null values safe for IAM payload such as subscription ID (most common) or other data required in the payload is nil.

Details

How could this happen?

Motivation

Fix crashes, reported in #1453 and others. The crash reports all look like they are for player ID.

Scope

Correctly handle and pass along null values.

Testing

Unit testing

Ported over 2 existing IAM-related request tests, and add a few more with null values and check it does not crash

Manual testing

Physical iPhone 13 on iOS 17.4

I was able to recreate this scenario "naturally" with this flow:

  1. SDK has perviously fetched IAMs so there are IAMs in the cache
  2. Kill app and then delete the user via REST API
  3. Manipulate the SDK code so that Create User requests cannot be sent
  4. Open app, and notice that before IAMs are fetched, we actually evaluate IAMs on onApplicationDidBecomeActive, which at this point subscription ID still exists locally so the shouldShowInAppMessage check passes
  5. Then the SDK fetches user to refresh and finds the user is gone, nullifies the local subscription ID, and enqueues a Create User request (that I prevent from being sent).
  6. The IAM displays in a context with null subscription ID.

Affected code checklist

Checklist

Overview

Testing

Final pass


This change is Reviewable