Skip to content
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 @@ -580,6 +580,7 @@ extension CollectionDetailsResponseModel {
externalId: collection.externalId,
hidePasswords: collection.hidePasswords,
id: id,
manage: collection.manage,
name: collection.name,
organizationId: collection.organizationId,
readOnly: collection.readOnly
Expand All @@ -604,7 +605,8 @@ extension BitwardenSdk.Collection {
name: model.name,
externalId: model.externalId,
hidePasswords: model.hidePasswords,
readOnly: model.readOnly
readOnly: model.readOnly,
manage: model.manage
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ struct CipherSSHKeyModel: Codable, Equatable {
// MARK: Properties

/// The key fingerprint of the SSH key.
let keyFingerprint: String?
let keyFingerprint: String

/// The private key of the SSH key.
let privateKey: String?
let privateKey: String

/// The public key of the SSH key.
let publicKey: String?
let publicKey: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Foundation

extension CipherSSHKeyModel {
static func fixture(
keyFingerprint: String? = "keyFingerprint",
privateKey: String? = "privateKey",
publicKey: String? = "publicKey"
keyFingerprint: String = "keyFingerprint",
privateKey: String = "privateKey",
publicKey: String = "publicKey"
) -> CipherSSHKeyModel {
self.init(
keyFingerprint: keyFingerprint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ struct CollectionDetailsResponseModel: Codable, Equatable {
/// The collection's identifier.
let id: String

/// Whether the collection can be managed by the user.
@DefaultFalse var manage: Bool

/// The collection's name.
let name: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extension CollectionDetailsResponseModel {
externalId: String? = nil,
hidePasswords: Bool = false,
id: String = UUID().uuidString,
manage: Bool = false,
name: String = "",
organizationId: String = UUID().uuidString,
readOnly: Bool = false
Expand All @@ -15,6 +16,7 @@ extension CollectionDetailsResponseModel {
externalId: externalId,
hidePasswords: hidePasswords,
id: id,
manage: manage,
name: name,
organizationId: organizationId,
readOnly: readOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ extension CollectionView {
name: collection.name,
externalId: collection.externalId,
hidePasswords: collection.hidePasswords,
readOnly: collection.readOnly
readOnly: collection.readOnly,
manage: collection.manage
)
}
}
Expand Down
31 changes: 14 additions & 17 deletions BitwardenShared/UI/Vault/Extensions/Alert+Vault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,31 @@ extension Alert {
})
}
case .sshKey:
if let publicKey = cipherView.sshKey?.publicKey {
if let sshKey = cipherView.sshKey {
alertActions.append(AlertAction(title: Localizations.copyPublicKey, style: .default) { _, _ in
await action(.copy(
toast: Localizations.publicKey,
value: publicKey,
value: sshKey.publicKey,
requiresMasterPasswordReprompt: false,
logEvent: nil,
cipherId: cipherView.id
))
})
}
if let privateKey = cipherView.sshKey?.privateKey,
cipherView.viewPassword {
alertActions.append(AlertAction(title: Localizations.copyPrivateKey, style: .default) { _, _ in
await action(.copy(
toast: Localizations.privateKey,
value: privateKey,
requiresMasterPasswordReprompt: cipherView.reprompt == .password && hasMasterPassword,
logEvent: nil,
cipherId: cipherView.id
))
})
}
if let fingerprint = cipherView.sshKey?.fingerprint {
if cipherView.viewPassword {
alertActions.append(AlertAction(title: Localizations.copyPrivateKey, style: .default) { _, _ in
await action(.copy(
toast: Localizations.privateKey,
value: sshKey.privateKey,
requiresMasterPasswordReprompt: cipherView.reprompt == .password && hasMasterPassword,
logEvent: nil,
cipherId: cipherView.id
))
})
}
alertActions.append(AlertAction(title: Localizations.copyFingerprint, style: .default) { _, _ in
await action(.copy(
toast: Localizations.fingerprint,
value: fingerprint,
value: sshKey.fingerprint,
requiresMasterPasswordReprompt: false,
logEvent: nil,
cipherId: cipherView.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ extension Collection {
name: String = "",
externalId: String = "",
hidePasswords: Bool = false,
manage: Bool = false,
readOnly: Bool = false
) -> Collection {
Collection(
Expand All @@ -258,7 +259,8 @@ extension Collection {
name: name,
externalId: externalId,
hidePasswords: hidePasswords,
readOnly: readOnly
readOnly: readOnly,
manage: manage
)
}
}
Expand Down Expand Up @@ -290,6 +292,7 @@ extension CollectionView {
id: String = "collection-view-1",
name: String = "",
organizationId: String = "",
manage: Bool = false,
readOnly: Bool = false
) -> CollectionView {
CollectionView(
Expand All @@ -298,7 +301,8 @@ extension CollectionView {
name: name,
externalId: externalId,
hidePasswords: hidePasswords,
readOnly: readOnly
readOnly: readOnly,
manage: manage
)
}
}
Expand Down Expand Up @@ -479,19 +483,19 @@ extension BitwardenSdk.LoginUriView {

extension BitwardenSdk.SshKey {
static func fixture(
privateKey: String? = "privateKey",
publicKey: String? = "publicKey",
fingerprint: String? = "fingerprint"
privateKey: String = "privateKey",
publicKey: String = "publicKey",
fingerprint: String = "fingerprint"
) -> SshKey {
SshKey(privateKey: privateKey, publicKey: publicKey, fingerprint: fingerprint)
}
}

extension BitwardenSdk.SshKeyView {
static func fixture(
privateKey: String? = "privateKey",
publicKey: String? = "publicKey",
fingerprint: String? = "fingerprint"
privateKey: String = "privateKey",
publicKey: String = "publicKey",
fingerprint: String = "fingerprint"
) -> SshKeyView {
SshKeyView(privateKey: privateKey, publicKey: publicKey, fingerprint: fingerprint)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,10 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
/// Snapshots the previews for SSH key type.
@MainActor
func test_snapshot_sshKey() {
processor.state = sshKeyCipherItemState(isPrivateKeyVisible: false)
processor.state = sshKeyCipherItemState(
canViewPrivateKey: true,
isPrivateKeyVisible: false
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
Expand All @@ -819,7 +822,23 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
/// Snapshots the previews for SSH key type when private key is visible.
@MainActor
func test_snapshot_sshKeyPrivateKeyVisible() {
processor.state = sshKeyCipherItemState(isPrivateKeyVisible: true)
processor.state = sshKeyCipherItemState(
canViewPrivateKey: true,
isPrivateKeyVisible: true
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
)
}

/// Snapshots the previews for SSH key type when `canViewPrivateKey` is `false`.
@MainActor
func test_snapshot_sshKeyCantViewPrivateKey() {
processor.state = sshKeyCipherItemState(
canViewPrivateKey: false,
isPrivateKeyVisible: false
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
Expand All @@ -829,9 +848,11 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
// MARK: Private

/// Creates a `CipherItemState` for an SSH key item.
/// - Parameter isPrivateKeyVisible: Whether the private key is visible.
/// - Parameters:
/// - canViewPrivateKey: Whether the private key can be viewed.
/// - isPrivateKeyVisible: Whether the private key is visible.
/// - Returns: The `CipherItemState` for SSH key item.
private func sshKeyCipherItemState(isPrivateKeyVisible: Bool) -> CipherItemState {
private func sshKeyCipherItemState(canViewPrivateKey: Bool, isPrivateKeyVisible: Bool) -> CipherItemState {
var state = CipherItemState(
existing: .fixture(
id: "fake-id"
Expand All @@ -841,6 +862,7 @@ class AddEditItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_b
state.name = "Example"
state.type = .sshKey
state.sshKeyState = SSHKeyItemState(
canViewPrivateKey: canViewPrivateKey,
isPrivateKeyVisible: isPrivateKeyVisible,
privateKey: "ajsdfopij1ZXCVZXC12312QW",
publicKey: "ssh-ed25519 AAAAA/asdjfoiwejrpo23323j23ASdfas",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Foundation

/// The state for an SSH key item.
struct SSHKeyItemState: Equatable, Sendable {
/// Whether the user has permissions to view the cipher's private key.
var canViewPrivateKey: Bool = false

/// The visibility of the private key.
var isPrivateKeyVisible: Bool = false

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,13 @@ class ViewItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_body
/// Snapshots the previews for SSH key type.
@MainActor
func test_snapshot_sshKey() {
processor.state.loadingState = .data(sshKeyCipherItemState(isPrivateKeyVisible: false))
processor.state.loadingState =
.data(
sshKeyCipherItemState(
canViewPrivateKey: true,
isPrivateKeyVisible: false
)
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
Expand All @@ -575,7 +581,29 @@ class ViewItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_body
/// Snapshots the previews for SSH key type when private key is visible.
@MainActor
func test_snapshot_sshKeyPrivateKeyVisible() {
processor.state.loadingState = .data(sshKeyCipherItemState(isPrivateKeyVisible: true))
processor.state.loadingState =
.data(
sshKeyCipherItemState(
canViewPrivateKey: true,
isPrivateKeyVisible: true
)
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
)
}

/// Snapshots the previews for SSH key type when `canViewPrivateKey` is `false`.
@MainActor
func test_snapshot_sshKeyCantViewPrivateKey() {
processor.state.loadingState =
.data(
sshKeyCipherItemState(
canViewPrivateKey: false,
isPrivateKeyVisible: false
)
)
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5]
Expand All @@ -585,9 +613,11 @@ class ViewItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_body
// MARK: Private

/// Creates a `CipherItemState` for an SSH key item.
/// - Parameter isPrivateKeyVisible: Whether the private key is visible.
/// - Parameters:
/// - canViewPrivateKey: Whether the private key can be viewed.
/// - isPrivateKeyVisible: Whether the private key is visible
/// - Returns: The `CipherItemState` for SSH key item.
private func sshKeyCipherItemState(isPrivateKeyVisible: Bool) -> CipherItemState {
private func sshKeyCipherItemState(canViewPrivateKey: Bool, isPrivateKeyVisible: Bool) -> CipherItemState {
var state = CipherItemState(
existing: .fixture(
id: "fake-id"
Expand All @@ -597,6 +627,7 @@ class ViewItemViewTests: BitwardenTestCase { // swiftlint:disable:this type_body
state.name = "Example"
state.type = .sshKey
state.sshKeyState = SSHKeyItemState(
canViewPrivateKey: canViewPrivateKey,
isPrivateKeyVisible: isPrivateKeyVisible,
privateKey: "ajsdfopij1ZXCVZXC12312QW",
publicKey: "ssh-ed25519 AAAAA/asdjfoiwejrpo23323j23ASdfas",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ extension CipherView {
/// - Returns: An `SSHKeyItemState` representing the SSH key information of the cipher.
///
func sshKeyItemState() -> SSHKeyItemState {
// TODO: PM-10401 create state when SDK is updated
SSHKeyItemState(
guard let sshKey else { return .init() }
return SSHKeyItemState(
canViewPrivateKey: viewPassword,
isPrivateKeyVisible: false,
privateKey: "Test",
publicKey: "Test",
keyFingerprint: "Test"
privateKey: sshKey.privateKey,
publicKey: sshKey.publicKey,
keyFingerprint: sshKey.fingerprint
)
}

Expand Down
Loading
Loading