fix: Unable to sync the cipher with a null password history last used date

This commit is contained in:
Artem Chepurnoy 2024-01-19 12:37:34 +02:00
parent b15a1dff67
commit dee746a5bc
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
2 changed files with 12 additions and 3 deletions

View File

@ -10,14 +10,19 @@ data class PasswordHistoryRequest(
@SerialName("password") @SerialName("password")
val password: String, val password: String,
@SerialName("lastUsedDate") @SerialName("lastUsedDate")
val lastUsedDate: Instant?, val lastUsedDate: Instant,
) )
fun PasswordHistoryRequest.Companion.of( fun PasswordHistoryRequest.Companion.of(
model: BitwardenCipher.Login.PasswordHistory, model: BitwardenCipher.Login.PasswordHistory,
) = kotlin.run { ) = kotlin.run {
val lastUsedDate = model.lastUsedDate
// Bitwarden forces us to have a last used date for
// the password history item. It still allows for existing
// items to have it as null tho.
?: Instant.fromEpochMilliseconds(0)
PasswordHistoryRequest( PasswordHistoryRequest(
password = model.password, password = model.password,
lastUsedDate = model.lastUsedDate, lastUsedDate = lastUsedDate,
) )
} }

View File

@ -182,7 +182,11 @@ suspend fun BitwardenCipher.Login.toDomain(
fun BitwardenCipher.Login.PasswordHistory.toDomain() = DSecret.Login.PasswordHistory( fun BitwardenCipher.Login.PasswordHistory.toDomain() = DSecret.Login.PasswordHistory(
password = password, password = password,
lastUsedDate = lastUsedDate, // Bitwarden forces us to have a last used date for
// the password history item. The ones that had it as
// null will end up converted to the zero Unix timestamp.
lastUsedDate = lastUsedDate
?.takeUnless { it.epochSeconds == 0L },
) )
fun BitwardenCipher.Login.PasswordStrength.toDomain() = PasswordStrength( fun BitwardenCipher.Login.PasswordStrength.toDomain() = PasswordStrength(