Repository navigation
Fix broadcast error handling and URLSession session injection - #263
Merged
Merged
Conversation
- APNSURLSessionClient.sendBroadcast used URLSession.shared instead of the injected session, and omitted the user-agent header the device-push path sets. - APNSClient.sendBroadcast threw a raw decoding error on empty or non-JSON error bodies instead of a typed APNSError, unlike send. - JWT kid and iss are now JSON-escaped so a stray quote in configuration cannot produce a malformed token. - URLSession request URLs are guarded instead of force-unwrapped. - APNSTestServer response overrides now apply to the broadcast send endpoint. Adds regression tests for each, plus the previously untested controls send path.
Apple team and key identifiers are alphanumeric, so the escaping had no real-world effect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fixes surfaced by a codebase review, each with a regression test.
Fixes
APNSURLSessionClient.sendBroadcastignored the injected session. It calledURLSession.sharedwhilesendusedself.session, so a proxy, delegate, or mock session applied to device pushes but not broadcasts. It also omitted theuser-agentheader the device-push path sets.APNSClient.sendBroadcastlost the status code on undecodable error bodies. It used a stricttryon body collection and decoding, so a 503 with an HTML body surfaced as aDecodingErrorinstead ofAPNSError(responseStatus: 503, reason: nil).sendwas already lenient here; broadcast now matches.APNSUrlSessionClientError.invalidURLinstead of force-unwrapped. Modern Foundation percent-encodes most bad input rather than returning nil, so this is defensive only and has no test.Tests
testSendControlsNotification: the controls send path had zero coverage.testSendBroadcast_forced503NonJSONBody…and…forced500EmptyBody…for the NIO broadcast error path.testSendAlert_forced500EmptyBody…and…forced503NonJSONBody…for the URLSession client, which had no error-body tests.testSendBroadcast_usesInjectedSessionuses aURLProtocolmock that only the injected session sees.APNSTestServer.setResponseOverridenow also applies toPOST /4/broadcasts/apps/{bundleID}to support the broadcast tests.Full suite: 160 tests, 0 failures.