-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BWA-82] Add Configurable Timeout Length (#203)
- Loading branch information
1 parent
5fb5449
commit 66cb740
Showing
22 changed files
with
704 additions
and
24 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
116 changes: 116 additions & 0 deletions
116
AuthenticatorShared/Core/Platform/Models/Enum/SessionTimeoutValue.swift
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,116 @@ | ||
// MARK: - SessionTimeoutValue | ||
|
||
/// An enumeration of session timeout values to choose from. | ||
/// | ||
/// Note: This is imported from the PM app, but the `custom` case has been removed. | ||
/// | ||
public enum SessionTimeoutValue: RawRepresentable, CaseIterable, Equatable, Menuable, Sendable { | ||
/// Timeout immediately. | ||
case immediately | ||
|
||
/// Timeout after 1 minute. | ||
case oneMinute | ||
|
||
/// Timeout after 5 minutes. | ||
case fiveMinutes | ||
|
||
/// Timeout after 15 minutes. | ||
case fifteenMinutes | ||
|
||
/// Timeout after 30 minutes. | ||
case thirtyMinutes | ||
|
||
/// Timeout after 1 hour. | ||
case oneHour | ||
|
||
/// Timeout after 4 hours. | ||
case fourHours | ||
|
||
/// Timeout on app restart. | ||
case onAppRestart | ||
|
||
/// Never timeout the session. | ||
case never | ||
|
||
/// All of the cases to show in the menu. | ||
public static let allCases: [Self] = [ | ||
.immediately, | ||
.oneMinute, | ||
.fiveMinutes, | ||
.fifteenMinutes, | ||
.thirtyMinutes, | ||
.oneHour, | ||
.fourHours, | ||
.onAppRestart, | ||
.never, | ||
] | ||
|
||
/// The localized string representation of a `SessionTimeoutValue`. | ||
var localizedName: String { | ||
switch self { | ||
case .immediately: | ||
Localizations.immediately | ||
case .oneMinute: | ||
Localizations.oneMinute | ||
case .fiveMinutes: | ||
Localizations.fiveMinutes | ||
case .fifteenMinutes: | ||
Localizations.fifteenMinutes | ||
case .thirtyMinutes: | ||
Localizations.thirtyMinutes | ||
case .oneHour: | ||
Localizations.oneHour | ||
case .fourHours: | ||
Localizations.fourHours | ||
case .onAppRestart: | ||
Localizations.onRestart | ||
case .never: | ||
Localizations.never | ||
} | ||
} | ||
|
||
/// The session timeout value in seconds. | ||
var seconds: Int { | ||
rawValue * 60 | ||
} | ||
|
||
/// The session timeout value in minutes. | ||
public var rawValue: Int { | ||
switch self { | ||
case .immediately: 0 | ||
case .oneMinute: 1 | ||
case .fiveMinutes: 5 | ||
case .fifteenMinutes: 15 | ||
case .thirtyMinutes: 30 | ||
case .oneHour: 60 | ||
case .fourHours: 240 | ||
case .onAppRestart: -1 | ||
case .never: -2 | ||
} | ||
} | ||
|
||
public init(rawValue: Int) { | ||
switch rawValue { | ||
case 0: | ||
self = .immediately | ||
case 1: | ||
self = .oneMinute | ||
case 5: | ||
self = .fiveMinutes | ||
case 15: | ||
self = .fifteenMinutes | ||
case 30: | ||
self = .thirtyMinutes | ||
case 60: | ||
self = .oneHour | ||
case 240: | ||
self = .fourHours | ||
case -1: | ||
self = .onAppRestart | ||
case -2: | ||
self = .never | ||
default: | ||
self = .never | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
AuthenticatorShared/Core/Platform/Models/Enum/SessionTimeoutValueTests.swift
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,65 @@ | ||
import XCTest | ||
|
||
@testable import AuthenticatorShared | ||
|
||
final class SessionTimeoutValueTests: AuthenticatorTestCase { | ||
// MARK: Tests | ||
|
||
/// `allCases` returns all of the cases in the correct order. | ||
func test_allCases() { | ||
XCTAssertEqual( | ||
SessionTimeoutValue.allCases, | ||
[ | ||
.immediately, | ||
.oneMinute, | ||
.fiveMinutes, | ||
.fifteenMinutes, | ||
.thirtyMinutes, | ||
.oneHour, | ||
.fourHours, | ||
.onAppRestart, | ||
.never, | ||
] | ||
) | ||
} | ||
|
||
/// `init` returns the correct case for the given raw value. | ||
func test_initFromRawValue() { | ||
XCTAssertEqual(SessionTimeoutValue.immediately, SessionTimeoutValue(rawValue: 0)) | ||
XCTAssertEqual(SessionTimeoutValue.oneMinute, SessionTimeoutValue(rawValue: 1)) | ||
XCTAssertEqual(SessionTimeoutValue.fiveMinutes, SessionTimeoutValue(rawValue: 5)) | ||
XCTAssertEqual(SessionTimeoutValue.fifteenMinutes, SessionTimeoutValue(rawValue: 15)) | ||
XCTAssertEqual(SessionTimeoutValue.thirtyMinutes, SessionTimeoutValue(rawValue: 30)) | ||
XCTAssertEqual(SessionTimeoutValue.oneHour, SessionTimeoutValue(rawValue: 60)) | ||
XCTAssertEqual(SessionTimeoutValue.fourHours, SessionTimeoutValue(rawValue: 240)) | ||
XCTAssertEqual(SessionTimeoutValue.onAppRestart, SessionTimeoutValue(rawValue: -1)) | ||
XCTAssertEqual(SessionTimeoutValue.never, SessionTimeoutValue(rawValue: -2)) | ||
XCTAssertEqual(SessionTimeoutValue.never, SessionTimeoutValue(rawValue: 12345)) | ||
} | ||
|
||
/// `localizedName` returns the correct values. | ||
func test_localizedName() { | ||
XCTAssertEqual(SessionTimeoutValue.immediately.localizedName, Localizations.immediately) | ||
XCTAssertEqual(SessionTimeoutValue.oneMinute.localizedName, Localizations.oneMinute) | ||
XCTAssertEqual(SessionTimeoutValue.fiveMinutes.localizedName, Localizations.fiveMinutes) | ||
XCTAssertEqual(SessionTimeoutValue.fifteenMinutes.localizedName, Localizations.fifteenMinutes) | ||
XCTAssertEqual(SessionTimeoutValue.thirtyMinutes.localizedName, Localizations.thirtyMinutes) | ||
XCTAssertEqual(SessionTimeoutValue.oneHour.localizedName, Localizations.oneHour) | ||
XCTAssertEqual(SessionTimeoutValue.fourHours.localizedName, Localizations.fourHours) | ||
XCTAssertEqual(SessionTimeoutValue.onAppRestart.localizedName, Localizations.onRestart) | ||
XCTAssertEqual(SessionTimeoutValue.never.localizedName, Localizations.never) | ||
} | ||
|
||
/// `rawValue` returns the correct values. | ||
func test_rawValues() { | ||
XCTAssertEqual(SessionTimeoutValue.immediately.rawValue, 0) | ||
XCTAssertEqual(SessionTimeoutValue.oneMinute.rawValue, 1) | ||
XCTAssertEqual(SessionTimeoutValue.fiveMinutes.rawValue, 5) | ||
XCTAssertEqual(SessionTimeoutValue.fifteenMinutes.rawValue, 15) | ||
XCTAssertEqual(SessionTimeoutValue.thirtyMinutes.rawValue, 30) | ||
XCTAssertEqual(SessionTimeoutValue.oneHour.rawValue, 60) | ||
XCTAssertEqual(SessionTimeoutValue.fourHours.rawValue, 240) | ||
XCTAssertEqual(SessionTimeoutValue.onAppRestart.rawValue, -1) | ||
XCTAssertEqual(SessionTimeoutValue.never.rawValue, -2) | ||
} | ||
} |
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
Oops, something went wrong.