@@ -508,6 +508,35 @@ struct WebPushManagerTests {
508508 }
509509 }
510510
511+ @Test func sendExtraLargeMessageFails( ) async throws {
512+ await confirmation { requestWasMade in
513+ let vapidConfiguration = VAPID . Configuration. makeTesting ( )
514+
515+ let subscriberPrivateKey = P256 . KeyAgreement. PrivateKey ( compactRepresentable: false )
516+ var authenticationSecret : [ UInt8 ] = Array ( repeating: 0 , count: 16 )
517+ for index in authenticationSecret. indices { authenticationSecret [ index] = . random( in: . min ... . max) }
518+
519+ let subscriber = Subscriber (
520+ endpoint: URL ( string: " https://example.com/subscriber " ) !,
521+ userAgentKeyMaterial: UserAgentKeyMaterial ( publicKey: subscriberPrivateKey. publicKey, authenticationSecret: Data ( authenticationSecret) ) ,
522+ vapidKeyID: vapidConfiguration. primaryKey!. id
523+ )
524+
525+ let manager = WebPushManager (
526+ vapidConfiguration: vapidConfiguration,
527+ backgroundActivityLogger: Logger ( label: " WebPushManagerTests " , factory: { PrintLogHandler ( label: $0, metadataProvider: $1) } ) ,
528+ executor: . httpClient( MockHTTPClient ( { request in
529+ requestWasMade ( )
530+ return HTTPClientResponse ( status: . payloadTooLarge)
531+ } ) )
532+ )
533+
534+ await #expect( throws: MessageTooLargeError ( ) ) {
535+ try await manager. send ( data: Array ( repeating: 0 , count: 3994 ) , to: subscriber)
536+ }
537+ }
538+ }
539+
511540 @Test func sendMessageToNotFoundPushServerError( ) async throws {
512541 await confirmation { requestWasMade in
513542 let vapidConfiguration = VAPID . Configuration. mockedConfiguration
0 commit comments