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

[PM-15119] Fix SSH Key item cloning issue #1156

Merged
merged 1 commit into from
Nov 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ enum FeatureFlag: String, CaseIterable, Codable {
.importLoginsFlow,
.nativeCarouselFlow,
.nativeCreateAccountFlow,
.sshKeyVaultItem,
.testLocalFeatureFlag,
.testLocalInitialBoolFlag,
.testLocalInitialIntFlag,
.testLocalInitialStringFlag:
false
case .emailVerification,
.refactorSsoDetailsEndpoint,
.sshKeyVaultItem,
.testRemoteFeatureFlag,
.testRemoteInitialBoolFlag,
.testRemoteInitialIntFlag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class FeatureFlagTests: BitwardenTestCase {
func test_isRemotelyConfigured() {
XCTAssertTrue(FeatureFlag.emailVerification.isRemotelyConfigured)
XCTAssertTrue(FeatureFlag.refactorSsoDetailsEndpoint.isRemotelyConfigured)
XCTAssertTrue(FeatureFlag.sshKeyVaultItem.isRemotelyConfigured)
XCTAssertTrue(FeatureFlag.testRemoteInitialBoolFlag.isRemotelyConfigured)
XCTAssertTrue(FeatureFlag.testRemoteInitialIntFlag.isRemotelyConfigured)
XCTAssertTrue(FeatureFlag.testRemoteInitialStringFlag.isRemotelyConfigured)
Expand All @@ -25,7 +26,6 @@ final class FeatureFlagTests: BitwardenTestCase {
XCTAssertFalse(FeatureFlag.importLoginsFlow.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.nativeCarouselFlow.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.nativeCreateAccountFlow.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.sshKeyVaultItem.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.testLocalFeatureFlag.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.testLocalInitialBoolFlag.isRemotelyConfigured)
XCTAssertFalse(FeatureFlag.testLocalInitialIntFlag.isRemotelyConfigured)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,26 +1086,6 @@ class AddEditItemProcessorTests: BitwardenTestCase {
XCTAssertEqual(coordinator.routes.last, .dismiss())
}

/// `perform(_:)` with `.savePressed` saves the item for SSH Key
@MainActor
func test_perform_savePressed_sshKey() async {
subject.state.type = .sshKey
subject.state.name = "sshKey"

await subject.perform(.savePressed)

try XCTAssertEqual(
XCTUnwrap(vaultRepository.addCipherCiphers.first).type,
.sshKey
)

try XCTAssertEqual(
XCTUnwrap(vaultRepository.addCipherCiphers.first).name,
"sshKey"
)
XCTAssertEqual(coordinator.routes.last, .dismiss())
}

/// `perform(_:)` with `.savePressed` saves the item.
@MainActor
func test_perform_savePressed_card() async throws {
Expand Down Expand Up @@ -1178,6 +1158,50 @@ class AddEditItemProcessorTests: BitwardenTestCase {
XCTAssertEqual(coordinator.routes.last, .dismiss())
}

/// `perform(_:)` with `.savePressed` saves the item for `.sshKey`.
@MainActor
func test_perform_savePressed_sshKey() async throws {
subject.state.name = "vault item"
subject.state.type = .sshKey
let expectedSSHKeyItemState = SSHKeyItemState(
canViewPrivateKey: true,
isPrivateKeyVisible: false,
privateKey: "privateKey",
publicKey: "publicKey",
keyFingerprint: "fingerprint"
)
subject.state.sshKeyState = expectedSSHKeyItemState
await subject.perform(.savePressed)

try XCTAssertEqual(
XCTUnwrap(vaultRepository.addCipherCiphers.first).creationDate.timeIntervalSince1970,
Date().timeIntervalSince1970,
accuracy: 1
)
try XCTAssertEqual(
XCTUnwrap(vaultRepository.addCipherCiphers.first).revisionDate.timeIntervalSince1970,
Date().timeIntervalSince1970,
accuracy: 1
)

let added = try XCTUnwrap(vaultRepository.addCipherCiphers.first)
XCTAssertNil(added.identity)
XCTAssertNil(added.login)
XCTAssertNil(added.secureNote)
XCTAssertNotNil(added.sshKey)
XCTAssertNil(added.card)
XCTAssertEqual(added.sshKeyItemState(), expectedSSHKeyItemState)
let unwrappedState = try XCTUnwrap(subject.state as? CipherItemState)
XCTAssertEqual(
added,
unwrappedState
.newCipherView(
creationDate: vaultRepository.addCipherCiphers[0].creationDate
)
)
XCTAssertEqual(coordinator.routes.last, .dismiss())
}

/// `perform(_:)` with `.savePressed` in the app extension completes the autofill request if a
/// username and password was entered.
@MainActor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ struct SSHKeyItemState: Equatable, Sendable {

/// The fingerprint of the SSH key.
var keyFingerprint: String = ""

/// Gets the `SshKeyView` from this state.
var sshKeyView: SshKeyView {
SshKeyView(
privateKey: privateKey,
publicKey: publicKey,
fingerprint: keyFingerprint
)
}
}
2 changes: 1 addition & 1 deletion BitwardenShared/UI/Vault/VaultItem/CipherItemState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ extension CipherItemState {
identity: type == .identity ? identityState.identityView : nil,
card: type == .card ? cardItemState.cardView : nil,
secureNote: type == .secureNote ? .init(type: .generic) : nil,
sshKey: nil, // SSH keys cannot be created in mobile yet.
sshKey: type == .sshKey ? sshKeyState.sshKeyView : nil,
favorite: isFavoriteOn,
reprompt: isMasterPasswordRePromptOn ? .password : .none,
organizationUseTotp: false,
Expand Down
Loading