Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IAuthenticator #2

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,4 +28,4 @@ jobs:

DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}

run: bundle exec danger --verbose
run: bundle exec danger --verbose
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class AuthenticationInterceptor<Authenticator: IAuthenticator>: 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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <token>", forHTTPHeaderField: "Authorization")
func apply(_ credential: Credential, to urlRequest: inout URLRequest) async throws {
urlRequest.addValue("Bearer <token>", forHTTPHeaderField: "Authorization")
}

/// Refreshes the `Credential`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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 {
Expand Down
Loading