@@ -565,25 +565,81 @@ final class EnforcedSignatureVerificationHTTPClientTests: BaseSignatureVerificat
565565 expect ( response) . to ( beSuccess ( ) )
566566 }
567567
568- }
568+ func testFakeSignatureFailuresInEnforcedMode( ) throws {
569+ self . mockResponse ( signature: Self . sampleSignature, requestDate: Self . date1)
570+ MockSigning . stubbedVerificationResult = true
569571
570- // MARK: - Private
572+ try self . changeClientToEnforced ( forceSignatureFailures : true )
571573
572- @available ( iOS 13 . 0 , macOS 10 . 15 , tvOS 13 . 0 , watchOS 6 . 2 , * )
573- private extension BaseSignatureVerificationHTTPClientTests {
574+ let response : HTTPResponse < HTTPEmptyResponseBody > . Result ? = waitUntilValue { completion in
575+ self . client. perform ( . init( method: . get, path: Self . path) , completionHandler: completion)
576+ }
574577
575- final func changeClient ( _ verificationMode : Configuration . EntitlementVerificationMode ) throws {
576- try self . createClient ( Signing . verificationMode ( with : verificationMode ) )
578+ expect ( response ) . to ( beFailure ( ) )
579+ expect ( response ? . error ) == NetworkError . signatureVerificationFailed ( path : Self . path )
577580 }
578581
579- final func changeClientToEnforced( ) throws {
580- try self . createClient ( Signing . enforcedVerificationMode ( ) )
582+ func testFakeSignatureFailuresInInformationalMode( ) throws {
583+ self . mockResponse ( signature: Self . sampleSignature, requestDate: Self . date1)
584+ MockSigning . stubbedVerificationResult = true
585+
586+ try self . changeClient ( . informational, forceSignatureFailures: true )
587+
588+ let response : HTTPResponse < HTTPEmptyResponseBody > . Result ? = waitUntilValue { completion in
589+ self . client. perform ( . init( method: . get, path: Self . path) , completionHandler: completion)
590+ }
591+
592+ expect ( response) . to ( beSuccess ( ) )
593+ expect ( response? . value? . verificationResult) == . failed
581594 }
582595
583- private final func createClient( _ mode: Signing . ResponseVerificationMode ) throws {
584- self . systemInfo = try MockSystemInfo ( platformInfo: nil ,
585- finishTransactions: false ,
586- responseVerificationMode: mode)
596+ func testFakeSignatureFailuresWithDisabledVerification( ) throws {
597+ self . mockResponse ( signature: Self . sampleSignature, requestDate: Self . date1)
598+ MockSigning . stubbedVerificationResult = true
599+
600+ try self . changeClient ( . disabled, forceSignatureFailures: true )
601+
602+ let response : HTTPResponse < HTTPEmptyResponseBody > . Result ? = waitUntilValue { completion in
603+ self . client. perform ( . init( method: . get, path: Self . path) , completionHandler: completion)
604+ }
605+
606+ expect ( response) . to ( beSuccess ( ) )
607+ expect ( response? . value? . verificationResult) == . notRequested
608+ }
609+
610+ }
611+
612+ // MARK: - Private
613+
614+ @available ( iOS 13 . 0 , macOS 10 . 15 , tvOS 13 . 0 , watchOS 6 . 2 , * )
615+ private extension BaseSignatureVerificationHTTPClientTests {
616+
617+ final func changeClient(
618+ _ verificationMode: Configuration . EntitlementVerificationMode ,
619+ forceSignatureFailures: Bool = false
620+ ) throws {
621+ try self . createClient ( Signing . verificationMode ( with: verificationMode) ,
622+ forceSignatureFailures: forceSignatureFailures)
623+ }
624+
625+ final func changeClientToEnforced( forceSignatureFailures: Bool = false ) throws {
626+ try self . createClient ( Signing . enforcedVerificationMode ( ) ,
627+ forceSignatureFailures: forceSignatureFailures)
628+ }
629+
630+ private final func createClient(
631+ _ mode: Signing . ResponseVerificationMode ,
632+ forceSignatureFailures: Bool = false
633+ ) throws {
634+ self . systemInfo = try MockSystemInfo (
635+ platformInfo: nil ,
636+ finishTransactions: false ,
637+ responseVerificationMode: mode,
638+ dangerousSettings: . init(
639+ autoSyncPurchases: true ,
640+ internalSettings: DangerousSettings . Internal ( forceSignatureFailures: forceSignatureFailures)
641+ )
642+ )
587643 self . client = self . createClient ( )
588644 }
589645
0 commit comments