Skip to content

Commit

Permalink
Merge branch 'release/candidate' into feat/e2ei/respect-e2ei-creating…
Browse files Browse the repository at this point in the history
…-mls-client
  • Loading branch information
mchenani authored Jan 26, 2024
2 parents 9b1b9ec + 65b08ae commit e805c3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ internal class CertificateRevocationListRepositoryDataSource(
metadataDAO.getSerializable(CRL_LIST_KEY, CRLUrlExpirationList.serializer())

override suspend fun addOrUpdateCRL(url: String, timestamp: ULong) {

metadataDAO.getSerializable(CRL_LIST_KEY, CRLUrlExpirationList.serializer())
val newCRLUrls = metadataDAO.getSerializable(CRL_LIST_KEY, CRLUrlExpirationList.serializer())
?.let { crlExpirationList ->
val crlWithExpiration = crlExpirationList.cRLWithExpirationList.find {
it.url == url
}
val newCRLs = crlWithExpiration?.let { item ->
crlWithExpiration?.let { item ->
crlExpirationList.cRLWithExpirationList.map { current ->
if (current.url == url) {
return@map item.copy(expiration = timestamp)
Expand All @@ -72,12 +71,15 @@ internal class CertificateRevocationListRepositoryDataSource(
)
}

metadataDAO.putSerializable(
CRL_LIST_KEY,
CRLUrlExpirationList(newCRLs),
CRLUrlExpirationList.serializer()
)
}
} ?: run {
// add new CRL
listOf(CRLWithExpiration(url, timestamp))
}
metadataDAO.putSerializable(
CRL_LIST_KEY,
CRLUrlExpirationList(newCRLUrls),
CRLUrlExpirationList.serializer()
)
}

override suspend fun getCurrentClientCrlUrl(): Either<CoreFailure, String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ class CertificateRevocationListRepositoryTest {
)
}.wasInvoked(once)
}
@Test
fun givenNoStoredList_whenUpdatingCRLs_thenAddNewCRL() = runTest {
val (arrangement, crlRepository) = Arrangement()
.withNullCRLResult()
.arrange()

crlRepository.addOrUpdateCRL(DUMMY_URL, TIMESTAMP)

verify(arrangement.metadataDAO).coroutine {
putSerializable(
CRL_LIST_KEY,
CRLUrlExpirationList(listOf(CRLWithExpiration(DUMMY_URL, TIMESTAMP))),
CRLUrlExpirationList.serializer()
)
}.wasInvoked(once)
}

@Test
fun givenPassedCRLExistsInStoredList_whenUpdatingCRLs_thenUpdateCurrentCRL() = runTest {
Expand Down Expand Up @@ -111,6 +127,14 @@ class CertificateRevocationListRepositoryTest {
)
}.thenReturn(CRLUrlExpirationList(listOf()))
}
suspend fun withNullCRLResult() = apply {
given(metadataDAO).coroutine {
metadataDAO.getSerializable(
CRL_LIST_KEY,
CRLUrlExpirationList.serializer()
)
}.thenReturn(null)
}

suspend fun withCRLs() = apply {
given(metadataDAO).coroutine {
Expand Down

0 comments on commit e805c3a

Please sign in to comment.