Skip to content

Commit

Permalink
[PM-14186] Update SDK to make SSH key properties required (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Oct 30, 2024
1 parent 56367cc commit eaa7923
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,13 @@ data class SyncResponseJson(
@Serializable
data class SshKey(
@SerialName("publicKey")
val publicKey: String?,
val publicKey: String,

@SerialName("privateKey")
val privateKey: String?,
val privateKey: String,

@SerialName("keyFingerprint")
val keyFingerprint: String?,
val keyFingerprint: String,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,58 +53,52 @@ fun VaultItemSshKeyContent(
)
}

sshKeyItemState.publicKey?.let { publicKey ->
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
label = stringResource(id = R.string.public_key),
value = publicKey,
onValueChange = { },
singleLine = false,
readOnly = true,
modifier = Modifier
.testTag("SshKeyItemPublicKeyEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
label = stringResource(id = R.string.public_key),
value = sshKeyItemState.publicKey,
onValueChange = { },
singleLine = false,
readOnly = true,
modifier = Modifier
.testTag("SshKeyItemPublicKeyEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}

sshKeyItemState.privateKey?.let { privateKey ->
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenPasswordField(
label = stringResource(id = R.string.private_key),
value = privateKey,
onValueChange = { },
singleLine = false,
readOnly = true,
showPassword = sshKeyItemState.showPrivateKey,
showPasswordTestTag = "ViewPrivateKeyButton",
showPasswordChange = vaultSshKeyItemTypeHandlers.onShowPrivateKeyClick,
modifier = Modifier
.testTag("SshKeyItemPrivateKeyEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenPasswordField(
label = stringResource(id = R.string.private_key),
value = sshKeyItemState.privateKey,
onValueChange = { },
singleLine = false,
readOnly = true,
showPassword = sshKeyItemState.showPrivateKey,
showPasswordTestTag = "ViewPrivateKeyButton",
showPasswordChange = vaultSshKeyItemTypeHandlers.onShowPrivateKeyClick,
modifier = Modifier
.testTag("SshKeyItemPrivateKeyEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}

sshKeyItemState.fingerprint?.let { fingerprint ->
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
label = stringResource(id = R.string.fingerprint),
value = fingerprint,
onValueChange = { },
singleLine = false,
readOnly = true,
modifier = Modifier
.testTag("SshKeyItemFingerprintEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}
item {
Spacer(modifier = Modifier.height(8.dp))
BitwardenTextField(
label = stringResource(id = R.string.fingerprint),
value = sshKeyItemState.fingerprint,
onValueChange = { },
singleLine = false,
readOnly = true,
modifier = Modifier
.testTag("SshKeyItemFingerprintEntry")
.fillMaxWidth()
.padding(horizontal = 16.dp),
)
}

item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,9 @@ data class VaultItemState(
*/
data class SshKey(
val name: String?,
val publicKey: String?,
val privateKey: String?,
val fingerprint: String?,
val publicKey: String,
val privateKey: String,
val fingerprint: String,
val showPrivateKey: Boolean,
) : ItemType()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ data class VaultState(
override val extraIconList: List<IconRes> = emptyList(),
override val overflowOptions: List<ListingItemOverflowAction.VaultAction>,
override val shouldShowMasterPasswordReprompt: Boolean,
val publicKey: Text?,
val privateKey: Text?,
val fingerprint: Text?,
val publicKey: Text,
val privateKey: Text,
val fingerprint: Text,
) : VaultItem() {
override val supportingLabel: Text? get() = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ private fun VaultAddEditState.ViewState.Content.ItemType.toCipherType(): CipherT
private fun VaultAddEditState.ViewState.Content.ItemType.toSshKeyView(): SshKeyView? =
(this as? VaultAddEditState.ViewState.Content.ItemType.SshKey)?.let {
SshKeyView(
publicKey = it.publicKey.orNullIfBlank(),
privateKey = it.privateKey.orNullIfBlank(),
fingerprint = it.fingerprint.orNullIfBlank(),
publicKey = it.publicKey,
privateKey = it.privateKey,
fingerprint = it.fingerprint,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,16 @@ private fun CipherView.toVaultItemOrNull(
name = name.asText(),
publicKey = sshKey
?.publicKey
?.asText(),
.orEmpty()
.asText(),
privateKey = sshKey
?.privateKey
?.asText(),
.orEmpty()
.asText(),
fingerprint = sshKey
?.fingerprint
?.asText(),
.orEmpty()
.asText(),
overflowOptions = toOverflowActions(
hasMasterPassword = hasMasterPassword,
isPremiumUser = isPremiumUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,12 +2151,6 @@ class VaultItemScreenTest : BaseComposeTest() {
val publicKey = "the public key"
mutableStateFlow.update { it.copy(viewState = DEFAULT_SSH_KEY_VIEW_STATE) }
composeTestRule.onNodeWithTextAfterScroll(publicKey).assertIsDisplayed()

mutableStateFlow.update { currentState ->
updateSshKeyType(currentState) { copy(publicKey = null) }
}

composeTestRule.assertScrollableNodeDoesNotExist(publicKey)
}

@Test
Expand All @@ -2173,12 +2167,6 @@ class VaultItemScreenTest : BaseComposeTest() {
composeTestRule
.onNodeWithText(privateKey)
.assertIsDisplayed()

mutableStateFlow.update { currentState ->
updateSshKeyType(currentState) { copy(privateKey = null) }
}

composeTestRule.assertScrollableNodeDoesNotExist(privateKey)
}

@Test
Expand All @@ -2205,12 +2193,6 @@ class VaultItemScreenTest : BaseComposeTest() {
val fingerprint = "the fingerprint"
mutableStateFlow.update { it.copy(viewState = DEFAULT_SSH_KEY_VIEW_STATE) }
composeTestRule.onNodeWithTextAfterScroll(fingerprint).assertIsDisplayed()

mutableStateFlow.update { currentState ->
updateSshKeyType(currentState) { copy(fingerprint = null) }
}

composeTestRule.assertScrollableNodeDoesNotExist(fingerprint)
}

//endregion ssh key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ fun createIdentityView(isEmpty: Boolean): IdentityView =

fun createSshKeyView(isEmpty: Boolean): SshKeyView =
SshKeyView(
privateKey = "privateKey".takeUnless { isEmpty },
publicKey = "publicKey".takeUnless { isEmpty },
fingerprint = "fingerprint".takeUnless { isEmpty },
privateKey = "privateKey".takeUnless { isEmpty }.orEmpty(),
publicKey = "publicKey".takeUnless { isEmpty }.orEmpty(),
fingerprint = "fingerprint".takeUnless { isEmpty }.orEmpty(),
)

fun createCipherView(type: CipherType, isEmpty: Boolean): CipherView =
Expand Down Expand Up @@ -154,7 +154,7 @@ fun createCipherView(type: CipherType, isEmpty: Boolean): CipherView =
creationDate = Instant.ofEpochSecond(1_000L),
deletedDate = null,
revisionDate = Instant.ofEpochSecond(1_000L),
sshKey = createSshKeyView(isEmpty = isEmpty),
sshKey = createSshKeyView(isEmpty),
)

fun createCommonContent(
Expand Down Expand Up @@ -272,8 +272,8 @@ fun createIdentityContent(
fun createSshKeyContent(isEmpty: Boolean): VaultItemState.ViewState.Content.ItemType.SshKey =
VaultItemState.ViewState.Content.ItemType.SshKey(
name = "mockName".takeUnless { isEmpty },
privateKey = "privateKey".takeUnless { isEmpty },
publicKey = "publicKey".takeUnless { isEmpty },
fingerprint = "fingerprint".takeUnless { isEmpty },
privateKey = "privateKey".takeUnless { isEmpty }.orEmpty(),
publicKey = "publicKey".takeUnless { isEmpty }.orEmpty(),
fingerprint = "fingerprint".takeUnless { isEmpty }.orEmpty(),
showPrivateKey = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,9 @@ class VaultDataExtensionsTest {
folderId = null,
sshKey = createMockSshKeyView(number = 1)
.copy(
publicKey = null,
privateKey = null,
fingerprint = null,
publicKey = "publicKey",
privateKey = "privateKey",
fingerprint = "fingerprint",
),
),
createMockCipherView(
Expand Down Expand Up @@ -945,16 +945,16 @@ class VaultDataExtensionsTest {
createMockSshKeyVaultItem(number = 1),
createMockSshKeyVaultItem(number = 2)
.copy(
publicKey = null,
privateKey = null,
fingerprint = null,
publicKey = "publicKey".asText(),
privateKey = "privateKey".asText(),
fingerprint = "fingerprint".asText(),
shouldShowMasterPasswordReprompt = true,
),
createMockSshKeyVaultItem(number = 3)
.copy(
publicKey = null,
privateKey = null,
fingerprint = null,
publicKey = "".asText(),
privateKey = "".asText(),
fingerprint = "".asText(),
),
),
trashItemsCount = 0,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ androidxSplash = "1.1.0-rc01"
androidXAppCompat = "1.7.0"
androdixAutofill = "1.1.0"
androidxWork = "2.9.1"
bitwardenSdk = "1.0.0-20241024.173753-4"
bitwardenSdk = "1.0.0-20241030.101847-8"
crashlytics = "3.0.2"
detekt = "1.23.7"
firebaseBom = "33.5.1"
Expand Down

0 comments on commit eaa7923

Please sign in to comment.