mirror of
https://github.com/bitwarden/android.git
synced 2025-12-10 09:56:45 -06:00
[PM-23278] Add SDK makeUpdateKdf call
This commit is contained in:
parent
9adc25471e
commit
5ff44d6133
@ -6,6 +6,7 @@ import com.bitwarden.core.DerivePinKeyResponse
|
|||||||
import com.bitwarden.core.InitOrgCryptoRequest
|
import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoMethod
|
import com.bitwarden.core.InitUserCryptoMethod
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
|
import com.bitwarden.core.UpdateKdfResponse
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
import com.bitwarden.crypto.Kdf
|
import com.bitwarden.crypto.Kdf
|
||||||
import com.bitwarden.crypto.TrustDeviceResponse
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
@ -473,4 +474,13 @@ interface VaultSdkSource {
|
|||||||
fido2CredentialStore: Fido2CredentialStore,
|
fido2CredentialStore: Fido2CredentialStore,
|
||||||
relyingPartyId: String,
|
relyingPartyId: String,
|
||||||
): Result<List<Fido2CredentialAutofillView>>
|
): Result<List<Fido2CredentialAutofillView>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the KDF settings for the user with the given [userId].
|
||||||
|
*/
|
||||||
|
suspend fun makeUpdateKdf(
|
||||||
|
userId: String,
|
||||||
|
password: String,
|
||||||
|
kdf: Kdf,
|
||||||
|
): Result<UpdateKdfResponse>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.bitwarden.core.DeriveKeyConnectorRequest
|
|||||||
import com.bitwarden.core.DerivePinKeyResponse
|
import com.bitwarden.core.DerivePinKeyResponse
|
||||||
import com.bitwarden.core.InitOrgCryptoRequest
|
import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
|
import com.bitwarden.core.UpdateKdfResponse
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
import com.bitwarden.crypto.Kdf
|
import com.bitwarden.crypto.Kdf
|
||||||
import com.bitwarden.crypto.TrustDeviceResponse
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
@ -581,4 +582,14 @@ class VaultSdkSourceImpl(
|
|||||||
)
|
)
|
||||||
.silentlyDiscoverCredentials(relyingPartyId)
|
.silentlyDiscoverCredentials(relyingPartyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun makeUpdateKdf(
|
||||||
|
userId: String,
|
||||||
|
password: String,
|
||||||
|
kdf: Kdf,
|
||||||
|
): Result<UpdateKdfResponse> = runCatchingWithLogs {
|
||||||
|
getClient(userId = userId)
|
||||||
|
.crypto()
|
||||||
|
.makeUpdateKdf(password = password, kdf = kdf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,9 @@ import com.bitwarden.core.DeriveKeyConnectorRequest
|
|||||||
import com.bitwarden.core.DerivePinKeyResponse
|
import com.bitwarden.core.DerivePinKeyResponse
|
||||||
import com.bitwarden.core.InitOrgCryptoRequest
|
import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
|
import com.bitwarden.core.MasterPasswordAuthenticationData
|
||||||
|
import com.bitwarden.core.MasterPasswordUnlockData
|
||||||
|
import com.bitwarden.core.UpdateKdfResponse
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
import com.bitwarden.core.data.util.asFailure
|
import com.bitwarden.core.data.util.asFailure
|
||||||
import com.bitwarden.core.data.util.asSuccess
|
import com.bitwarden.core.data.util.asSuccess
|
||||||
@ -1363,6 +1366,63 @@ class VaultSdkSourceTest {
|
|||||||
)
|
)
|
||||||
assertTrue(result.isFailure)
|
assertTrue(result.isFailure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `makeUpdateKdf should return results when successful`() = runTest {
|
||||||
|
val kdf = mockk<Kdf>()
|
||||||
|
val updateKdfResponse = UpdateKdfResponse(
|
||||||
|
masterPasswordAuthenticationData = MasterPasswordAuthenticationData(
|
||||||
|
kdf = kdf,
|
||||||
|
salt = "mockSalt",
|
||||||
|
masterPasswordAuthenticationHash = "mockHash",
|
||||||
|
),
|
||||||
|
masterPasswordUnlockData = MasterPasswordUnlockData(
|
||||||
|
kdf = kdf,
|
||||||
|
masterKeyWrappedUserKey = "mockKey",
|
||||||
|
salt = "mockSalt",
|
||||||
|
),
|
||||||
|
oldMasterPasswordAuthenticationData = MasterPasswordAuthenticationData(
|
||||||
|
kdf = kdf,
|
||||||
|
salt = "mockSalt",
|
||||||
|
masterPasswordAuthenticationHash = "mockHash",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
coEvery {
|
||||||
|
clientCrypto.makeUpdateKdf(
|
||||||
|
password = "mockPassword",
|
||||||
|
kdf = kdf,
|
||||||
|
)
|
||||||
|
} returns updateKdfResponse
|
||||||
|
|
||||||
|
val result = vaultSdkSource.makeUpdateKdf(
|
||||||
|
userId = "mockUserId",
|
||||||
|
password = "mockPassword",
|
||||||
|
kdf = kdf,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
updateKdfResponse.asSuccess(),
|
||||||
|
result,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `makeUpdateKdf should return Failure when Bitwarden exception is thrown`() =
|
||||||
|
runTest {
|
||||||
|
val kdf = mockk<Kdf>()
|
||||||
|
coEvery {
|
||||||
|
clientCrypto.makeUpdateKdf(
|
||||||
|
password = "mockPassword",
|
||||||
|
kdf = kdf,
|
||||||
|
)
|
||||||
|
} throws BitwardenException.E("mockException")
|
||||||
|
val result = vaultSdkSource.makeUpdateKdf(
|
||||||
|
userId = "mockUserId",
|
||||||
|
password = "mockPassword",
|
||||||
|
kdf = kdf,
|
||||||
|
)
|
||||||
|
assertTrue(result.isFailure)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val DEFAULT_SIGNATURE = "0987654321ABCDEF"
|
private const val DEFAULT_SIGNATURE = "0987654321ABCDEF"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user