From 9f6f4398d6c7b202d329936821528bb3a7cfcc13 Mon Sep 17 00:00:00 2001 From: Alex Babrykovich Date: Tue, 16 Apr 2024 16:29:59 +0200 Subject: [PATCH 1/2] ci: do pod push ofter release created (#148) --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1671647..c1d0f1b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -3,12 +3,12 @@ name: ci on: push: branches: [ master, main ] - tags: [ '[1-9]+.[0-9]+.[0-9]+*' ] paths-ignore: - '**.md' pull_request: paths-ignore: - '**.md' + release: workflow_dispatch: repository_dispatch: @@ -151,7 +151,7 @@ jobs: release: name: Release - if: startsWith(github.ref, 'refs/tags') + if: github.event_name == 'release' needs: samples runs-on: macOS-latest steps: From c5855113b0b05c6d3876bd8e22059b8a846fc225 Mon Sep 17 00:00:00 2001 From: Alex Babrykovich Date: Thu, 18 Apr 2024 13:47:15 +0200 Subject: [PATCH 2/2] fix: sessionTimeout should be retriable only to avoid loop (#150) --- .../Core/HCaptchaWebViewManager__Tests.swift | 4 ++-- .../HCaptchaWebViewManager+Helpers.swift | 2 +- .../RxSwift/HCaptcha+Rx__Tests.swift | 2 +- Example/HCaptcha_Tests/mock.html | 2 +- HCaptcha/Classes/HCaptchaWebViewManager.swift | 18 +++++++----------- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift b/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift index 0e2f21a..1ed9d0b 100644 --- a/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift +++ b/Example/HCaptcha_Tests/Core/HCaptchaWebViewManager__Tests.swift @@ -360,7 +360,7 @@ class HCaptchaWebViewManager__Tests: XCTestCase { exp2.fulfill() } - XCTAssertEqual(result1?.error, .wrongMessageFormat) + XCTAssertEqual(result1?.error, .sessionTimeout) // Resets and tries again let exp3 = expectation(description: "validates after reset") @@ -396,7 +396,7 @@ class HCaptchaWebViewManager__Tests: XCTestCase { manager.onEvent = { (event, error) in XCTAssertEqual(.error, event) - XCTAssertEqual(HCaptchaError.wrongMessageFormat, error as? HCaptchaError) + XCTAssertEqual(HCaptchaError.sessionTimeout, error as? HCaptchaError) exp1.fulfill() } diff --git a/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift b/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift index a1a4b94..0b73451 100644 --- a/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift +++ b/Example/HCaptcha_Tests/Helpers/HCaptchaWebViewManager+Helpers.swift @@ -21,7 +21,7 @@ extension HCaptchaWebViewManager { messageBody: String = "undefined", apiKey: String? = nil, endpoint: URL? = nil, - shouldFail: Bool = false, + shouldFail: Bool = false, // will fail with retriable sessionTimeout size: HCaptchaSize = .invisible, rqdata: String? = nil, theme: String = "\"light\"", diff --git a/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift b/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift index 05d09e1..48bd237 100644 --- a/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift +++ b/Example/HCaptcha_Tests/RxSwift/HCaptcha+Rx__Tests.swift @@ -231,7 +231,7 @@ class HCaptcha_Rx__Tests: XCTestCase { .single() } catch let error { - XCTAssertEqual(error as? HCaptchaError, .wrongMessageFormat) + XCTAssertEqual(error as? HCaptchaError, .sessionTimeout) // Resets after failure _ = Observable.just(()) diff --git a/Example/HCaptcha_Tests/mock.html b/Example/HCaptcha_Tests/mock.html index c951faa..e6ff52f 100644 --- a/Example/HCaptcha_Tests/mock.html +++ b/Example/HCaptcha_Tests/mock.html @@ -29,7 +29,7 @@ var execute = function() { if (shouldFail) { - post("error"); + post({error: 15}); // .sessionTimeout } else { if (rqdata) { post({"log": rqdata}); diff --git a/HCaptcha/Classes/HCaptchaWebViewManager.swift b/HCaptcha/Classes/HCaptchaWebViewManager.swift index 00f7758..5acfc5b 100644 --- a/HCaptcha/Classes/HCaptchaWebViewManager.swift +++ b/HCaptcha/Classes/HCaptchaWebViewManager.swift @@ -1,4 +1,3 @@ -// swiftlint:disable file_length // // HCaptchaWebViewManager.swift // HCaptcha @@ -245,22 +244,19 @@ fileprivate extension HCaptchaWebViewManager { } private func handle(error: HCaptchaError) { - switch error { - case HCaptchaError.challengeClosed: - completion?(HCaptchaResult(error: error)) - case HCaptchaError.networkError: - if let completion = completion { - completion(HCaptchaResult(error: error)) - } else { - lastError = error - } - default: + if error == .sessionTimeout { if shouldResetOnError, let view = webView.superview { reset() validate(on: view) } else { completion?(HCaptchaResult(error: error)) } + } else { + if let completion = completion { + completion(HCaptchaResult(error: error)) + } else { + lastError = error + } } }