[PM-12406] Add verified organization domain details service call to OrganizationService

This commit is contained in:
André Bispo 2024-10-25 22:44:15 +01:00
parent 97571601ff
commit ea16cd964d
No known key found for this signature in database
GPG key ID: E5610EF043C76548
3 changed files with 73 additions and 3 deletions

View file

@ -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>
} }

View file

@ -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,
),
)
} }

View file

@ -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",
),
),
)