mirror of
https://github.com/bitwarden/android.git
synced 2024-11-25 02:46:00 +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.model.toBitwardenError
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.network.util.base64UrlEncode
|
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.datasource.network.util.parseErrorBodyOrNull
|
||||||
|
import com.x8bit.bitwarden.data.platform.util.DeviceModelProvider
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
|
import java.net.HttpURLConnection.HTTP_BAD_REQUEST
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
@ -14,6 +15,7 @@ class IdentityServiceImpl constructor(
|
||||||
private val json: Json,
|
private val json: Json,
|
||||||
// TODO: use correct base URL here BIT-328
|
// TODO: use correct base URL here BIT-328
|
||||||
private val baseUrl: String = "https://vault.bitwarden.com",
|
private val baseUrl: String = "https://vault.bitwarden.com",
|
||||||
|
private val deviceModelProvider: DeviceModelProvider = DeviceModelProvider(),
|
||||||
) : IdentityService {
|
) : IdentityService {
|
||||||
|
|
||||||
override suspend fun getToken(
|
override suspend fun getToken(
|
||||||
|
@ -29,8 +31,7 @@ class IdentityServiceImpl constructor(
|
||||||
authEmail = email.base64UrlEncode(),
|
authEmail = email.base64UrlEncode(),
|
||||||
// TODO: use correct device identifier here BIT-325
|
// TODO: use correct device identifier here BIT-325
|
||||||
deviceIdentifier = UUID.randomUUID().toString(),
|
deviceIdentifier = UUID.randomUUID().toString(),
|
||||||
// TODO: use correct values for deviceName and deviceType BIT-326
|
deviceName = deviceModelProvider.deviceModel,
|
||||||
deviceName = "Pixel 6",
|
|
||||||
deviceType = "0",
|
deviceType = "0",
|
||||||
grantType = "password",
|
grantType = "password",
|
||||||
passwordHash = passwordHash,
|
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.api.IdentityApi
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
|
||||||
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
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.coroutines.test.runTest
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.mockwebserver.MockResponse
|
import okhttp3.mockwebserver.MockResponse
|
||||||
|
@ -14,11 +17,15 @@ import retrofit2.create
|
||||||
class IdentityServiceTest : BaseServiceTest() {
|
class IdentityServiceTest : BaseServiceTest() {
|
||||||
|
|
||||||
private val identityApi: IdentityApi = retrofit.create()
|
private val identityApi: IdentityApi = retrofit.create()
|
||||||
|
private val deviceModelProvider = mockk<DeviceModelProvider>() {
|
||||||
|
every { deviceModel } returns "Test Device"
|
||||||
|
}
|
||||||
|
|
||||||
private val identityService = IdentityServiceImpl(
|
private val identityService = IdentityServiceImpl(
|
||||||
api = identityApi,
|
api = identityApi,
|
||||||
json = Json,
|
json = Json,
|
||||||
baseUrl = server.url("/").toString(),
|
baseUrl = server.url("/").toString(),
|
||||||
|
deviceModelProvider = deviceModelProvider,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue