Skip to content

Commit 3d055b0

Browse files
authored
Update IAuthenticator (#2)
* Update `IAuthenticator` * Update `CHANGELOG` * Update docs * Update `danger.yml` * Update Unit Tests
1 parent f4d9370 commit 3d055b0

7 files changed

Lines changed: 15 additions & 9 deletions

File tree

.github/workflows/danger.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: ruby setup
1616
uses: ruby/setup-ruby@v1
1717
with:
18-
ruby-version: 2.7
18+
ruby-version: 3.1.4
1919
bundler-cache: true
2020
- name: Checkout code
2121
uses: actions/checkout@v2
@@ -28,4 +28,4 @@ jobs:
2828

2929
DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
3030

31-
run: bundle exec danger --verbose
31+
run: bundle exec danger --verbose

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [Unreleased]
5+
6+
## Fixed
7+
- Fix the `inout` parameter in the `IAuthenticator` protocol
8+
- Fixed in Pull Request [#2](https://github.com/space-code/network-layer/pull/2).
9+
410
#### 1.x Releases
511
- `1.0.x` Releases - [1.0.0](#100)
612

Sources/NetworkLayer/Classes/Core/Authentification/AuthenticationInterceptor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class AuthenticationInterceptor<Authenticator: IAuthenticator>: IAu
4646
if credential.requiresRefresh {
4747
try await refresh(credential, for: session)
4848
} else {
49-
try await authenticator.apply(credential, to: request)
49+
try await authenticator.apply(credential, to: &request)
5050
}
5151
}
5252

Sources/NetworkLayer/NetworkLayer.docc/Articles/Authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ struct Authenticator: IAuthenticator {
3434
/// - Parameters:
3535
/// - credential: The `Credential`.
3636
/// - urlRequest: The `URLRequest`.
37-
func apply(_ credential: Credential, to urlRequest: URLRequest) async throws {
38-
request.addValue("Bearer <token>", forHTTPHeaderField: "Authorization")
37+
func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws {
38+
urlRequest.addValue("Bearer <token>", forHTTPHeaderField: "Authorization")
3939
}
4040

4141
/// Refreshes the `Credential`.

Sources/NetworkLayerInterfaces/Classes/Core/Authenticator/IAuthenticator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public protocol IAuthenticator {
1414
/// - Parameters:
1515
/// - credential: The `Credential`.
1616
/// - urlRequest: The `URLRequest`.
17-
func apply(_ credential: Credential, to urlRequest: URLRequest) async throws
17+
func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws
1818

1919
/// Refreshes the `Credential`.
2020
///

Tests/NetworkLayerTests/Classes/Helpers/Mocks/AuthenticatorMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class AuthenticatorMock: IAuthenticator {
1414
var invokedApplyParameters: (credential: Credential, urlRequest: URLRequest)?
1515
var invokedApplyParametersList = [(credential: Credential, urlRequest: URLRequest)]()
1616

17-
func apply(_ credential: Credential, to urlRequest: URLRequest) async throws {
17+
func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws {
1818
invokedApply = true
1919
invokedApplyCount += 1
2020
invokedApplyParameters = (credential, urlRequest)

Tests/NetworkLayerTests/Classes/Tests/UnitTests/RequestParametersEncoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ final class RequestParametersEncoderTests: XCTestCase {
4141

4242
func test_thatRequestParametersEncoderThrowsAnError_whenURLIsNotValid() {
4343
// given
44-
var requestMock = URLRequest.fake(string: .wrongURL)
44+
var requestMock = URLRequest.fake(string: .domainName)
45+
requestMock.url = nil
4546

4647
// when
4748
var receivedError: NSError?
@@ -60,7 +61,6 @@ final class RequestParametersEncoderTests: XCTestCase {
6061

6162
private extension String {
6263
static let domainName = "https://google.com"
63-
static let wrongURL = "http://example.com:-80"
6464
}
6565

6666
private extension Dictionary where Self.Key == String, Self.Value == String {

0 commit comments

Comments
 (0)