-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
292 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// File.swift | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
extension CustomerRequest.AuthFlowTriggers { | ||
// Jitter to account for the requests that are about to expire | ||
private static let expiryJitter: TimeInterval = 10 | ||
|
||
func isExpired(on date: Date = Date()) -> Bool { | ||
refreshesAt <= date.addingTimeInterval(CustomerRequest.AuthFlowTriggers.expiryJitter) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// File.swift | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@testable import PayKit | ||
import XCTest | ||
|
||
final class CustomerRequest_ExtensionsTests: XCTestCase { | ||
private var now: Date! | ||
private var url: URL! | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
now = Date() | ||
url = try XCTUnwrap(URL(string: "https://block.xyz")) | ||
} | ||
|
||
override func tearDown() { | ||
now = nil | ||
url = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_expired() throws { | ||
let authFlowTrigger = CustomerRequest.AuthFlowTriggers( | ||
qrCodeImageURL: url, | ||
qrCodeSVGURL: url, | ||
mobileURL: url, | ||
refreshesAt: Date(timeInterval: -30, since: now) | ||
) | ||
|
||
XCTAssertTrue(authFlowTrigger.isExpired(on: now)) | ||
} | ||
|
||
func test_notExpired() throws { | ||
let authFlowTrigger = CustomerRequest.AuthFlowTriggers( | ||
qrCodeImageURL: url, | ||
qrCodeSVGURL: url, | ||
mobileURL: url, | ||
refreshesAt: Date(timeInterval: 30, since: now) | ||
) | ||
XCTAssertFalse(authFlowTrigger.isExpired(on: now)) | ||
} | ||
|
||
func test_expiredBecauseOfJitter() { | ||
let authFlowTrigger = CustomerRequest.AuthFlowTriggers( | ||
qrCodeImageURL: url, | ||
qrCodeSVGURL: url, | ||
mobileURL: url, | ||
refreshesAt: Date(timeInterval: 10, since: now) | ||
) | ||
XCTAssertTrue(authFlowTrigger.isExpired(on: now)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.