mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
BIT-326 Use correct value for deviceName on get token request (#114)
This commit is contained in:
parent
d81f0820b3
commit
b0b64178f7
3 changed files with 24 additions and 2 deletions
|
@ -5,6 +5,7 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJs
|
|||
import com.x8bit.bitwarden.data.platform.datasource.network.model.toBitwardenError
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.util.base64UrlEncode
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.util.parseErrorBodyOrNull
|
||||
import com.x8bit.bitwarden.data.platform.util.DeviceModelProvider
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
|
||||
import java.util.UUID
|
||||
|
@ -14,6 +15,7 @@ class IdentityServiceImpl constructor(
|
|||
private val json: Json,
|
||||
// TODO: use correct base URL here BIT-328
|
||||
private val baseUrl: String = "https://vault.bitwarden.com",
|
||||
private val deviceModelProvider: DeviceModelProvider = DeviceModelProvider(),
|
||||
) : IdentityService {
|
||||
|
||||
override suspend fun getToken(
|
||||
|
@ -29,8 +31,7 @@ class IdentityServiceImpl constructor(
|
|||
authEmail = email.base64UrlEncode(),
|
||||
// TODO: use correct device identifier here BIT-325
|
||||
deviceIdentifier = UUID.randomUUID().toString(),
|
||||
// TODO: use correct values for deviceName and deviceType BIT-326
|
||||
deviceName = "Pixel 6",
|
||||
deviceName = deviceModelProvider.deviceModel,
|
||||
deviceType = "0",
|
||||
grantType = "password",
|
||||
passwordHash = passwordHash,
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.x8bit.bitwarden.data.platform.util
|
||||
|
||||
import android.os.Build
|
||||
|
||||
/**
|
||||
* Provides device model string. Useful for mocking static [Build.model] call tests.
|
||||
*/
|
||||
class DeviceModelProvider {
|
||||
|
||||
/**
|
||||
* Device model.
|
||||
*/
|
||||
val deviceModel: String = Build.MODEL
|
||||
}
|
|
@ -3,6 +3,9 @@ package com.x8bit.bitwarden.data.auth.datasource.network.service
|
|||
import com.x8bit.bitwarden.data.auth.datasource.network.api.IdentityApi
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
|
||||
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
||||
import com.x8bit.bitwarden.data.platform.util.DeviceModelProvider
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
|
@ -14,11 +17,15 @@ import retrofit2.create
|
|||
class IdentityServiceTest : BaseServiceTest() {
|
||||
|
||||
private val identityApi: IdentityApi = retrofit.create()
|
||||
private val deviceModelProvider = mockk<DeviceModelProvider>() {
|
||||
every { deviceModel } returns "Test Device"
|
||||
}
|
||||
|
||||
private val identityService = IdentityServiceImpl(
|
||||
api = identityApi,
|
||||
json = Json,
|
||||
baseUrl = server.url("/").toString(),
|
||||
deviceModelProvider = deviceModelProvider,
|
||||
)
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue