mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
[PM-12406] Add verified organization domain details service call to OrganizationService
This commit is contained in:
parent
97571601ff
commit
ea16cd964d
3 changed files with 73 additions and 3 deletions
|
@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.datasource.network.service
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationAutoEnrollStatusResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationAutoEnrollStatusResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
||||||
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifiedOrganizationDomainSsoDetailsResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an API for querying organization endpoints.
|
* Provides an API for querying organization endpoints.
|
||||||
|
@ -38,4 +39,12 @@ interface OrganizationService {
|
||||||
suspend fun getOrganizationKeys(
|
suspend fun getOrganizationKeys(
|
||||||
organizationId: String,
|
organizationId: String,
|
||||||
): Result<OrganizationKeysResponseJson>
|
): Result<OrganizationKeysResponseJson>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request organization verified domain details for an [email] needed for SSO
|
||||||
|
* requests.
|
||||||
|
*/
|
||||||
|
suspend fun getVerifiedOrganizationDomainSsoDetails(
|
||||||
|
email: String,
|
||||||
|
): Result<VerifiedOrganizationDomainSsoDetailsResponse>
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomain
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationResetPasswordEnrollRequestJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationResetPasswordEnrollRequestJson
|
||||||
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifiedOrganizationDomainSsoDetailsRequest
|
||||||
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifiedOrganizationDomainSsoDetailsResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of [OrganizationService].
|
* Default implementation of [OrganizationService].
|
||||||
|
@ -52,4 +54,13 @@ class OrganizationServiceImpl(
|
||||||
.getOrganizationKeys(
|
.getOrganizationKeys(
|
||||||
organizationId = organizationId,
|
organizationId = organizationId,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override suspend fun getVerifiedOrganizationDomainSsoDetails(
|
||||||
|
email: String,
|
||||||
|
): Result<VerifiedOrganizationDomainSsoDetailsResponse> = unauthenticatedOrganizationApi
|
||||||
|
.getVerifiedOrganizationDomainsByEmail(
|
||||||
|
body = VerifiedOrganizationDomainSsoDetailsRequest(
|
||||||
|
email = email,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.x8bit.bitwarden.data.auth.datasource.network.api.UnauthenticatedOrgan
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationAutoEnrollStatusResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationAutoEnrollStatusResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationDomainSsoDetailsResponseJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysResponseJson
|
||||||
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifiedOrganizationDomainSsoDetailsResponse
|
||||||
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
||||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
@ -55,7 +56,9 @@ class OrganizationServiceTest : BaseServiceTest() {
|
||||||
runTest {
|
runTest {
|
||||||
val email = "test@gmail.com"
|
val email = "test@gmail.com"
|
||||||
server.enqueue(
|
server.enqueue(
|
||||||
MockResponse().setResponseCode(200).setBody(ORGANIZATION_DOMAIN_SSO_DETAILS_JSON),
|
MockResponse()
|
||||||
|
.setResponseCode(200)
|
||||||
|
.setBody(ORGANIZATION_DOMAIN_SSO_DETAILS_JSON),
|
||||||
)
|
)
|
||||||
val result = organizationService.getOrganizationDomainSsoDetails(email)
|
val result = organizationService.getOrganizationDomainSsoDetails(email)
|
||||||
assertEquals(ORGANIZATION_DOMAIN_SSO_BODY.asSuccess(), result)
|
assertEquals(ORGANIZATION_DOMAIN_SSO_BODY.asSuccess(), result)
|
||||||
|
@ -74,7 +77,9 @@ class OrganizationServiceTest : BaseServiceTest() {
|
||||||
fun `getOrganizationAutoEnrollStatus when response is success should return valid response`() =
|
fun `getOrganizationAutoEnrollStatus when response is success should return valid response`() =
|
||||||
runTest {
|
runTest {
|
||||||
server.enqueue(
|
server.enqueue(
|
||||||
MockResponse().setResponseCode(200).setBody(ORGANIZATION_AUTO_ENROLL_STATUS_JSON),
|
MockResponse()
|
||||||
|
.setResponseCode(200)
|
||||||
|
.setBody(ORGANIZATION_AUTO_ENROLL_STATUS_JSON),
|
||||||
)
|
)
|
||||||
val result = organizationService.getOrganizationAutoEnrollStatus("orgId")
|
val result = organizationService.getOrganizationAutoEnrollStatus("orgId")
|
||||||
assertEquals(ORGANIZATION_AUTO_ENROLL_STATUS_RESPONSE.asSuccess(), result)
|
assertEquals(ORGANIZATION_AUTO_ENROLL_STATUS_RESPONSE.asSuccess(), result)
|
||||||
|
@ -91,7 +96,9 @@ class OrganizationServiceTest : BaseServiceTest() {
|
||||||
@Test
|
@Test
|
||||||
fun `getOrganizationKeys when response is success should return valid response`() = runTest {
|
fun `getOrganizationKeys when response is success should return valid response`() = runTest {
|
||||||
server.enqueue(
|
server.enqueue(
|
||||||
MockResponse().setResponseCode(200).setBody(ORGANIZATION_KEYS_JSON),
|
MockResponse()
|
||||||
|
.setResponseCode(200)
|
||||||
|
.setBody(ORGANIZATION_KEYS_JSON),
|
||||||
)
|
)
|
||||||
val result = organizationService.getOrganizationKeys("orgId")
|
val result = organizationService.getOrganizationKeys("orgId")
|
||||||
assertEquals(ORGANIZATION_KEYS_RESPONSE.asSuccess(), result)
|
assertEquals(ORGANIZATION_KEYS_RESPONSE.asSuccess(), result)
|
||||||
|
@ -103,6 +110,26 @@ class OrganizationServiceTest : BaseServiceTest() {
|
||||||
val result = organizationService.getOrganizationKeys("orgId")
|
val result = organizationService.getOrganizationKeys("orgId")
|
||||||
assertTrue(result.isFailure)
|
assertTrue(result.isFailure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MaxLineLength")
|
||||||
|
@Test
|
||||||
|
fun `getVerifiedOrganizationDomainSsoDetails when response is success should return valid response`() = runTest {
|
||||||
|
server.enqueue(
|
||||||
|
MockResponse()
|
||||||
|
.setResponseCode(200)
|
||||||
|
.setBody(ORGANIZATION_VERIFIED_DOMAIN_SSO_DETAILS_JSON),
|
||||||
|
)
|
||||||
|
val result = organizationService.getVerifiedOrganizationDomainSsoDetails("example@bitwarden.com")
|
||||||
|
assertEquals(ORGANIZATION_VERIFIED_DOMAIN_SSO_DETAILS_RESPONSE.asSuccess(), result)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("MaxLineLength")
|
||||||
|
@Test
|
||||||
|
fun `getVerifiedOrganizationDomainSsoDetails when response is an error should return an error`() = runTest {
|
||||||
|
server.enqueue(MockResponse().setResponseCode(400))
|
||||||
|
val result = organizationService.getVerifiedOrganizationDomainSsoDetails("example@bitwarden.com")
|
||||||
|
assertTrue(result.isFailure)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val ORGANIZATION_AUTO_ENROLL_STATUS_JSON = """
|
private const val ORGANIZATION_AUTO_ENROLL_STATUS_JSON = """
|
||||||
|
@ -143,3 +170,26 @@ private val ORGANIZATION_KEYS_RESPONSE = OrganizationKeysResponseJson(
|
||||||
privateKey = "privateKey",
|
privateKey = "privateKey",
|
||||||
publicKey = "publicKey",
|
publicKey = "publicKey",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private const val ORGANIZATION_VERIFIED_DOMAIN_SSO_DETAILS_JSON = """
|
||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"organizationIdentifier": "Test Identifier",
|
||||||
|
"organizationName": "Bitwarden",
|
||||||
|
"domainName": "bitwarden.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
private val ORGANIZATION_VERIFIED_DOMAIN_SSO_DETAILS_RESPONSE =
|
||||||
|
VerifiedOrganizationDomainSsoDetailsResponse(
|
||||||
|
verifiedOrganizationDomainSsoDetails = listOf(
|
||||||
|
VerifiedOrganizationDomainSsoDetailsResponse.VerifiedOrganizationDomainSsoDetail(
|
||||||
|
organizationIdentifier = "Test Identifier",
|
||||||
|
organizationName = "Bitwarden",
|
||||||
|
domainName = "bitwarden.com",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue