Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions infra/auth-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(project(":infra:enrolment-records-store"))
implementation(project(":infra:images"))
implementation(project(":infra:recent-user-activity"))
implementation(project(":infra:license"))

implementation(project(":fingerprint:infra:scanner"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.simprints.infra.config.store.ConfigRepository
import com.simprints.infra.enrolment.records.store.EnrolmentRecordRepository
import com.simprints.infra.events.EventRepository
import com.simprints.infra.images.ImageRepository
import com.simprints.infra.license.LicenseRepository
import com.simprints.infra.logging.LoggingConstants
import com.simprints.infra.logging.Simber
import com.simprints.infra.network.SimNetwork
Expand All @@ -24,6 +25,7 @@ internal class SignerManager @Inject constructor(
private val imageRepository: ImageRepository,
private val eventRepository: EventRepository,
private val enrolmentRecordRepository: EnrolmentRecordRepository,
private val licenseRepository: LicenseRepository,
private val scannerManager: ScannerManager,
@DispatcherIO private val dispatcher: CoroutineDispatcher,
) {
Expand Down Expand Up @@ -61,6 +63,7 @@ internal class SignerManager @Inject constructor(
eventRepository.deleteAll()
enrolmentRecordRepository.deleteAll()
scannerManager.deleteFirmwareFiles()
licenseRepository.deleteCachedLicenses()

Simber.tag(LoggingConstants.CrashReportTag.LOGOUT.name).i("Signed out")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.simprints.infra.enrolment.records.store.EnrolmentRecordRepository
import com.simprints.infra.events.EventRepository
import com.simprints.infra.events.sampledata.SampleDefaults.DEFAULT_PROJECT_ID
import com.simprints.infra.images.ImageRepository
import com.simprints.infra.license.LicenseRepository
import com.simprints.infra.network.SimNetwork
import com.simprints.infra.recent.user.activity.RecentUserActivityManager
import com.simprints.testtools.common.syntax.assertThrows
Expand Down Expand Up @@ -47,6 +48,9 @@ internal class SignerManagerTest {
@MockK
lateinit var mockImageRepository: ImageRepository

@MockK
lateinit var mockLicenseRepository: LicenseRepository

@MockK
lateinit var mockEnrolmentRecordRepository: EnrolmentRecordRepository

Expand Down Expand Up @@ -74,6 +78,7 @@ internal class SignerManagerTest {
mockImageRepository,
mockEventRepository,
mockEnrolmentRecordRepository,
mockLicenseRepository,
scannerManager,
UnconfinedTestDispatcher(),
)
Expand Down Expand Up @@ -186,6 +191,7 @@ internal class SignerManagerTest {
coVerify { mockEventRepository.deleteAll() }
coVerify { mockEnrolmentRecordRepository.deleteAll() }
coVerify { scannerManager.deleteFirmwareFiles() }
coVerify { mockLicenseRepository.deleteCachedLicenses() }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface LicenseRepository {

suspend fun getCachedLicense(licenseVendor: Vendor): License?
suspend fun deleteCachedLicense(licenseVendor: Vendor)

suspend fun deleteCachedLicenses()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ internal class LicenseRepositoryImpl @Inject constructor(

override suspend fun deleteCachedLicense(licenseVendor: Vendor) = licenseLocalDataSource.deleteCachedLicense(licenseVendor)

override suspend fun deleteCachedLicenses() = licenseLocalDataSource.deleteCachedLicenses()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal interface LicenseLocalDataSource {

suspend fun deleteCachedLicense(vendor: Vendor)

suspend fun deleteCachedLicenses()

companion object {
const val LICENSES_FOLDER = "licenses"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ internal class LicenseLocalDataSourceImpl @Inject constructor(
}
}

override suspend fun deleteCachedLicenses(): Unit = withContext(dispatcherIo) {
try {
val deleted = File(licenseDirectoryPath).deleteRecursively()
Simber.d("Deleted all licenses successfully = $deleted")
} catch (t: Throwable) {
Simber.e(t)
}
}

private fun getFileFromStorage(vendor: Vendor): String? = try {
val file = File("$licenseDirectoryPath/$vendor")
val encryptedFile = keyHelper.getEncryptedFileBuilder(file, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class LicenseLocalDataSourceImplTest {
assertThat(File("${filesDirPath}/${LicenseLocalDataSource.LICENSES_FOLDER}/$licenseVendor").exists()).isFalse()
}

@Test
fun `check delete all deletes the dir`() = runTest {
localSource.deleteCachedLicenses()

assertThat(File("${filesDirPath}/${LicenseLocalDataSource.LICENSES_FOLDER}/$licenseVendor").exists()).isFalse()
}

@Test
fun `check getting the file renames old Roc license file to RANK_ONE_FACE `() = runTest {
// Create the license folder and the old ROC.lic file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.simprints.infra.license.remote.ApiLicenseResult
import com.simprints.infra.license.remote.License
import com.simprints.infra.license.remote.LicenseRemoteDataSource
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.flow.toCollection
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -148,7 +149,7 @@ class LicenseRepositoryImplTest {
}

@Test
fun ` test getCachedLicense success`() = runTest {
fun `test getCachedLicense success`() = runTest {
// Given
coEvery { licenseLocalDataSource.getLicense(RANK_ONE_FACE) } returns license
// When
Expand All @@ -157,15 +158,28 @@ class LicenseRepositoryImplTest {
assertThat(cachedLicense).isEqualTo(license)
}

fun ` test getCachedLicense failure`() = runTest {
@Test
fun `test getCachedLicense failure`() = runTest {
// Given
coEvery { licenseLocalDataSource.getLicense(RANK_ONE_FACE) } returns null
// When
val license= licenseRepositoryImpl.getCachedLicense(RANK_ONE_FACE)
// Then
assertThat(license).isNull()
}

@Test
fun `deletes cached licence`() = runTest {
licenseRepositoryImpl.deleteCachedLicense(RANK_ONE_FACE)

coVerify { licenseLocalDataSource.deleteCachedLicense(RANK_ONE_FACE) }
}

@Test
fun `deletes all cached licence`() = runTest {
licenseRepositoryImpl.deleteCachedLicenses()

coVerify { licenseLocalDataSource.deleteCachedLicenses() }
}

companion object {
Expand Down