From 989c7df1cc632f29384390445040700f68b7cb98 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sat, 11 May 2024 17:48:59 +0400 Subject: [PATCH 1/5] Update `IAuthenticator` --- .../Core/Authentification/AuthenticationInterceptor.swift | 2 +- .../Classes/Core/Authenticator/IAuthenticator.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/NetworkLayer/Classes/Core/Authentification/AuthenticationInterceptor.swift b/Sources/NetworkLayer/Classes/Core/Authentification/AuthenticationInterceptor.swift index b017286..8a09425 100644 --- a/Sources/NetworkLayer/Classes/Core/Authentification/AuthenticationInterceptor.swift +++ b/Sources/NetworkLayer/Classes/Core/Authentification/AuthenticationInterceptor.swift @@ -46,7 +46,7 @@ public final class AuthenticationInterceptor: IAu if credential.requiresRefresh { try await refresh(credential, for: session) } else { - try await authenticator.apply(credential, to: request) + try await authenticator.apply(credential, to: &request) } } diff --git a/Sources/NetworkLayerInterfaces/Classes/Core/Authenticator/IAuthenticator.swift b/Sources/NetworkLayerInterfaces/Classes/Core/Authenticator/IAuthenticator.swift index a67cd64..2f791c5 100644 --- a/Sources/NetworkLayerInterfaces/Classes/Core/Authenticator/IAuthenticator.swift +++ b/Sources/NetworkLayerInterfaces/Classes/Core/Authenticator/IAuthenticator.swift @@ -14,7 +14,7 @@ public protocol IAuthenticator { /// - Parameters: /// - credential: The `Credential`. /// - urlRequest: The `URLRequest`. - func apply(_ credential: Credential, to urlRequest: URLRequest) async throws + func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws /// Refreshes the `Credential`. /// From 3fc79c933f0e3d9cf520be8bb74980770c1680e6 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sat, 11 May 2024 17:53:16 +0400 Subject: [PATCH 2/5] Update `CHANGELOG` --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c4648..80138b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +## [Unreleased] + +## Fixed +- Fix the `inout` parameter in the `IAuthenticator` protocol + - Fixed in Pull Request [#2](https://github.com/space-code/network-layer/pull/2). + #### 1.x Releases - `1.0.x` Releases - [1.0.0](#100) From 549aa42008a87a83a5f2dd7e36f65a0c5900be2d Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sat, 11 May 2024 17:53:56 +0400 Subject: [PATCH 3/5] Update docs --- .../NetworkLayer/NetworkLayer.docc/Articles/Authentication.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/NetworkLayer/NetworkLayer.docc/Articles/Authentication.md b/Sources/NetworkLayer/NetworkLayer.docc/Articles/Authentication.md index c44f16c..ce2dc46 100644 --- a/Sources/NetworkLayer/NetworkLayer.docc/Articles/Authentication.md +++ b/Sources/NetworkLayer/NetworkLayer.docc/Articles/Authentication.md @@ -34,8 +34,8 @@ struct Authenticator: IAuthenticator { /// - Parameters: /// - credential: The `Credential`. /// - urlRequest: The `URLRequest`. - func apply(_ credential: Credential, to urlRequest: URLRequest) async throws { - request.addValue("Bearer ", forHTTPHeaderField: "Authorization") + func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws { + urlRequest.addValue("Bearer ", forHTTPHeaderField: "Authorization") } /// Refreshes the `Credential`. From 1ba39f78fad16c4aadba5fe89e0c3a07319b2736 Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sat, 11 May 2024 17:56:32 +0400 Subject: [PATCH 4/5] Update `danger.yml` --- .github/workflows/danger.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index e6c6e9a..3ba7736 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -15,7 +15,7 @@ jobs: - name: ruby setup uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.1.4 bundler-cache: true - name: Checkout code uses: actions/checkout@v2 @@ -28,4 +28,4 @@ jobs: DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} - run: bundle exec danger --verbose \ No newline at end of file + run: bundle exec danger --verbose From a59d78795d0bd4d27b746821cf9c3f75164a744f Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Sat, 11 May 2024 18:07:56 +0400 Subject: [PATCH 5/5] Update Unit Tests --- .../Classes/Helpers/Mocks/AuthenticatorMock.swift | 2 +- .../Tests/UnitTests/RequestParametersEncoderTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/NetworkLayerTests/Classes/Helpers/Mocks/AuthenticatorMock.swift b/Tests/NetworkLayerTests/Classes/Helpers/Mocks/AuthenticatorMock.swift index 4b1d42b..492469f 100644 --- a/Tests/NetworkLayerTests/Classes/Helpers/Mocks/AuthenticatorMock.swift +++ b/Tests/NetworkLayerTests/Classes/Helpers/Mocks/AuthenticatorMock.swift @@ -14,7 +14,7 @@ final class AuthenticatorMock: IAuthenticator { var invokedApplyParameters: (credential: Credential, urlRequest: URLRequest)? var invokedApplyParametersList = [(credential: Credential, urlRequest: URLRequest)]() - func apply(_ credential: Credential, to urlRequest: URLRequest) async throws { + func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws { invokedApply = true invokedApplyCount += 1 invokedApplyParameters = (credential, urlRequest) diff --git a/Tests/NetworkLayerTests/Classes/Tests/UnitTests/RequestParametersEncoderTests.swift b/Tests/NetworkLayerTests/Classes/Tests/UnitTests/RequestParametersEncoderTests.swift index 9cb4a31..32995e8 100644 --- a/Tests/NetworkLayerTests/Classes/Tests/UnitTests/RequestParametersEncoderTests.swift +++ b/Tests/NetworkLayerTests/Classes/Tests/UnitTests/RequestParametersEncoderTests.swift @@ -41,7 +41,8 @@ final class RequestParametersEncoderTests: XCTestCase { func test_thatRequestParametersEncoderThrowsAnError_whenURLIsNotValid() { // given - var requestMock = URLRequest.fake(string: .wrongURL) + var requestMock = URLRequest.fake(string: .domainName) + requestMock.url = nil // when var receivedError: NSError? @@ -60,7 +61,6 @@ final class RequestParametersEncoderTests: XCTestCase { private extension String { static let domainName = "https://google.com" - static let wrongURL = "http://example.com:-80" } private extension Dictionary where Self.Key == String, Self.Value == String {