generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 82
[PM-19305] Enforce session timeout policy #2127
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
Open
LRNcardozoWDF
wants to merge
12
commits into
main
Choose a base branch
from
cmcg/pm-19305-vault-timeout-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e65850f
Merge branch 'main' into cmcg/pm-19305-vault-timeout-policy
LRNcardozoWDF f8268e6
pm-19305 Add support for timeout policy type
LRNcardozoWDF b69af43
pm-19305 Fix tests
LRNcardozoWDF 1937e2d
Merge branch 'main' into cmcg/pm-19305-vault-timeout-policy
LRNcardozoWDF 9a80efe
pm-19305 Applied plurals
LRNcardozoWDF b81b871
Merge branch 'main' into cmcg/pm-19305-vault-timeout-policy
LRNcardozoWDF b2acdf2
pm-19305 Fix pr comments
LRNcardozoWDF e404cb3
pm-19305 Fix test coverage
LRNcardozoWDF 8bb7d69
Merge branch 'main' into cmcg/pm-19305-vault-timeout-policy
LRNcardozoWDF b663543
pm-19305 Fix tests
LRNcardozoWDF 69a91ff
pm-19305 Add missing tests
LRNcardozoWDF 03bacf1
Merge branch 'main' into cmcg/pm-19305-vault-timeout-policy
LRNcardozoWDF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
BitwardenKit/Core/Platform/Models/Domain/SessionTimeoutPolicy.swift
This file contains hidden or 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,32 @@ | ||
| /// An object that represents a session timeout policy | ||
| /// | ||
| public struct SessionTimeoutPolicy { | ||
| // MARK: Properties | ||
|
|
||
| /// The action to perform on session timeout. | ||
| public let timeoutAction: SessionTimeoutAction? | ||
|
|
||
| /// An enumeration of session timeout types to choose from. | ||
| public let timeoutType: SessionTimeoutType? | ||
|
|
||
| /// An enumeration of session timeout values to choose from. | ||
| public let timeoutValue: SessionTimeoutValue? | ||
|
|
||
| // MARK: Initialization | ||
|
|
||
| /// Initialize `SessionTimeoutPolicy` with the specified values. | ||
| /// | ||
| /// - Parameters: | ||
| /// - timeoutAction: The action to perform on session timeout. | ||
| /// - timeoutType: The type of session timeout. | ||
| /// - timeoutValue: The session timeout value. | ||
| public init( | ||
| timeoutAction: SessionTimeoutAction?, | ||
| timeoutType: SessionTimeoutType?, | ||
| timeoutValue: SessionTimeoutValue?, | ||
| ) { | ||
| self.timeoutAction = timeoutAction | ||
| self.timeoutType = timeoutType | ||
| self.timeoutValue = timeoutValue | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
BitwardenKit/Core/Platform/Models/Enum/SessionTimeoutAction.swift
This file contains hidden or 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,23 @@ | ||
| import BitwardenResources | ||
|
|
||
| /// The action to perform on session timeout. | ||
| /// | ||
| public enum SessionTimeoutAction: Int, CaseIterable, Codable, Equatable, Menuable, Sendable { | ||
| /// Lock the vault. | ||
| case lock = 0 | ||
|
|
||
| /// Log the user out. | ||
| case logout = 1 | ||
|
|
||
| /// All of the cases to show in the menu. | ||
| public static let allCases: [SessionTimeoutAction] = [.lock, .logout] | ||
|
|
||
| public var localizedName: String { | ||
| switch self { | ||
| case .lock: | ||
| Localizations.lock | ||
| case .logout: | ||
| Localizations.logOut | ||
| } | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
BitwardenKit/Core/Platform/Models/Enum/SessionTimeoutType.swift
This file contains hidden or 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,93 @@ | ||
| // MARK: - SessionTimeoutType | ||
|
|
||
| /// An enumeration of session timeout types to choose from. | ||
| /// | ||
| public enum SessionTimeoutType: Codable, Equatable, Hashable, Sendable { | ||
| /// Time out immediately. | ||
| case immediately | ||
|
|
||
| /// Time out on app restart. | ||
| case onAppRestart | ||
|
|
||
| /// Never time out the session. | ||
| case never | ||
|
|
||
| /// A custom timeout value. | ||
| case custom | ||
|
|
||
| // MARK: Properties | ||
|
|
||
| /// The string representation of a session timeout type. | ||
| public var rawValue: String { | ||
| switch self { | ||
| case .immediately: | ||
| "immediately" | ||
| case .onAppRestart: | ||
| "onAppRestart" | ||
| case .never: | ||
| "never" | ||
| case .custom: | ||
| "custom" | ||
| } | ||
| } | ||
|
|
||
| /// A safe string representation of the timeout type. | ||
| public var timeoutType: String { | ||
| switch self { | ||
| case .immediately: | ||
| "immediately" | ||
| case .onAppRestart: | ||
| "on app restart" | ||
| case .never: | ||
| "never" | ||
| case .custom: | ||
| "custom" | ||
| } | ||
| } | ||
|
|
||
| // MARK: Initialization | ||
|
|
||
| /// Initialize a `SessionTimeoutType` using a string of the raw value. | ||
| /// | ||
| /// - Parameter rawValue: The string representation of the type raw value. | ||
| /// | ||
| public init(rawValue: String?) { | ||
| switch rawValue { | ||
| case "custom": | ||
| self = .custom | ||
| case "immediately": | ||
| self = .immediately | ||
| case "never": | ||
| self = .never | ||
| case "onAppRestart", | ||
| "onSystemLock": | ||
| self = .onAppRestart | ||
| default: | ||
| self = .custom | ||
| } | ||
| } | ||
|
|
||
| /// Initialize a `SessionTimeoutType` using a SessionTimeoutValue that belongs to that type. | ||
| /// | ||
| /// - Parameter value: The SessionTimeoutValue that belongs to the type. | ||
| /// | ||
| public init(value: SessionTimeoutValue) { | ||
| switch value { | ||
| case .custom: | ||
| self = .custom | ||
| case .immediately: | ||
| self = .immediately | ||
| case .never: | ||
| self = .never | ||
| case .onAppRestart: | ||
| self = .onAppRestart | ||
| case .fifteenMinutes, | ||
| .fiveMinutes, | ||
| .fourHours, | ||
| .oneHour, | ||
| .oneMinute, | ||
| .thirtyMinutes: | ||
| self = .custom | ||
| } | ||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
BitwardenKit/Core/Platform/Models/Enum/SessionTimeoutTypeTests.swift
This file contains hidden or 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,52 @@ | ||
| import BitwardenKit | ||
| import XCTest | ||
|
|
||
| final class SessionTimeoutTypeTests: BitwardenTestCase { | ||
| // MARK: Tests | ||
|
|
||
| /// `init(rawValue:)` returns the correct case for the given raw value string. | ||
| func test_initFromRawValue() { | ||
| XCTAssertEqual(SessionTimeoutType.immediately, SessionTimeoutType(rawValue: "immediately")) | ||
| XCTAssertEqual(SessionTimeoutType.onAppRestart, SessionTimeoutType(rawValue: "onAppRestart")) | ||
| // `onSystemLock` value maps to `onAppRestart` on mobile. | ||
| XCTAssertEqual(SessionTimeoutType.onAppRestart, SessionTimeoutType(rawValue: "onSystemLock")) | ||
| XCTAssertEqual(SessionTimeoutType.never, SessionTimeoutType(rawValue: "never")) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(rawValue: "custom")) | ||
| // `nil` value maps to `custom` on mobile in support to legacy. | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(rawValue: nil)) | ||
| } | ||
|
|
||
| /// `init(value:)` returns the correct case for the given `SessionTimeoutValue`. | ||
| func test_initFromSessionTimeoutValue() { | ||
| XCTAssertEqual(SessionTimeoutType.immediately, SessionTimeoutType(value: .immediately)) | ||
| XCTAssertEqual(SessionTimeoutType.onAppRestart, SessionTimeoutType(value: .onAppRestart)) | ||
| XCTAssertEqual(SessionTimeoutType.never, SessionTimeoutType(value: .never)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .custom(123))) | ||
| } | ||
|
|
||
| /// `init(value:)` returns `.custom` for all predefined timeout values. | ||
| func test_initFromSessionTimeoutValue_predefined() { | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .oneMinute)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .fiveMinutes)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .fifteenMinutes)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .thirtyMinutes)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .oneHour)) | ||
| XCTAssertEqual(SessionTimeoutType.custom, SessionTimeoutType(value: .fourHours)) | ||
| } | ||
|
|
||
| /// `rawValue` returns the correct string values. | ||
| func test_rawValues() { | ||
| XCTAssertEqual(SessionTimeoutType.immediately.rawValue, "immediately") | ||
| XCTAssertEqual(SessionTimeoutType.onAppRestart.rawValue, "onAppRestart") | ||
| XCTAssertEqual(SessionTimeoutType.never.rawValue, "never") | ||
| XCTAssertEqual(SessionTimeoutType.custom.rawValue, "custom") | ||
| } | ||
|
|
||
| /// `timeoutType` returns the correct string representation values. | ||
| func test_timeoutType() { | ||
| XCTAssertEqual(SessionTimeoutType.immediately.timeoutType, "immediately") | ||
| XCTAssertEqual(SessionTimeoutType.onAppRestart.timeoutType, "on app restart") | ||
| XCTAssertEqual(SessionTimeoutType.never.timeoutType, "never") | ||
| XCTAssertEqual(SessionTimeoutType.custom.timeoutType, "custom") | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum lacks dedicated unit tests, particularly for:
init(rawValue:)method with all possible string values.custominit(value:)method with all SessionTimeoutValue casesThese initialization paths are critical for policy enforcement compatibility with legacy servers. Add tests in a new file:
BitwardenKit/Core/Platform/Models/Enum/SessionTimeoutTypeTests.swift