mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 02:36:12 -04:00
Refactor: Use DeviceProfilesRepo for keys
This commit replaces the direct usage of GeneralSettings for fetching identity and encryption keys with the DeviceProfilesRepo. BaseAirPodsTest is updated to reflect this change, mocking DeviceProfilesRepo instead of GeneralSettings.
This commit is contained in:
@@ -6,16 +6,17 @@ import eu.darken.capod.common.SystemClockWrap
|
||||
import eu.darken.capod.common.bluetooth.BleScanResult
|
||||
import eu.darken.capod.common.fromHex
|
||||
import eu.darken.capod.common.serialization.SerializationModule
|
||||
import eu.darken.capod.main.core.GeneralSettings
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import eu.darken.capod.pods.core.apple.protocol.ContinuityProtocol
|
||||
import eu.darken.capod.profiles.core.DeviceProfile
|
||||
import eu.darken.capod.profiles.core.DeviceProfilesRepo
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import testhelpers.BaseTest
|
||||
import testhelpers.preferences.mockFlowPreference
|
||||
import java.time.Instant
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -29,14 +30,14 @@ abstract class BaseAirPodsTest : BaseTest() {
|
||||
@Component.Factory
|
||||
interface Factory {
|
||||
fun create(
|
||||
@BindsInstance generalSettings: GeneralSettings,
|
||||
@BindsInstance profilesRepo: DeviceProfilesRepo,
|
||||
): AppleFactoryTestComponent
|
||||
}
|
||||
}
|
||||
|
||||
val generalSettings = mockk<GeneralSettings>().apply {
|
||||
every { mainDeviceIdentityKey } returns mockFlowPreference(null)
|
||||
every { mainDeviceEncryptionKey } returns mockFlowPreference(null)
|
||||
val profileList = mutableListOf<DeviceProfile>()
|
||||
val profileRepo = mockk<DeviceProfilesRepo>().apply {
|
||||
every { profiles } returns flowOf(profileList)
|
||||
}
|
||||
|
||||
private fun hexToByteArray(hex: String): ByteArray = hex
|
||||
@@ -44,23 +45,11 @@ abstract class BaseAirPodsTest : BaseTest() {
|
||||
.replace("<", "")
|
||||
.fromHex()
|
||||
|
||||
private fun cleanKey(key: String): ByteArray = hexToByteArray(key)
|
||||
fun cleanKey(key: String): ByteArray = hexToByteArray(key)
|
||||
.also { require(it.size == 16) { "Not a valid key: ${it.size} byte" } }
|
||||
|
||||
fun setKeyIRK(key: String?) {
|
||||
generalSettings.apply {
|
||||
every { mainDeviceIdentityKey } returns mockFlowPreference(key?.let { cleanKey(it) })
|
||||
}
|
||||
}
|
||||
|
||||
fun setKeyEnc(key: String?) {
|
||||
generalSettings.apply {
|
||||
every { mainDeviceEncryptionKey } returns mockFlowPreference(key?.let { cleanKey(it) })
|
||||
}
|
||||
}
|
||||
|
||||
val factory: AppleFactory = DaggerBaseAirPodsTest_AppleFactoryTestComponent.factory().create(
|
||||
generalSettings = generalSettings
|
||||
profilesRepo = profileRepo
|
||||
).appleFactory
|
||||
|
||||
@BeforeEach
|
||||
|
||||
@@ -4,6 +4,7 @@ import eu.darken.capod.common.toHex
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import eu.darken.capod.pods.core.apple.BaseAirPodsTest
|
||||
import eu.darken.capod.pods.core.apple.HasAppleColor
|
||||
import eu.darken.capod.profiles.core.AppleDeviceProfile
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -206,8 +207,15 @@ class AirPodsProTest : BaseAirPodsTest() {
|
||||
payload.public.data.toByteArray().toHex(" ") shouldBe "01 0E 20 51 9A 98 33 00 04"
|
||||
payload.private shouldBe null
|
||||
}
|
||||
setKeyIRK("79-04-65-1E-E2-CC-D9-26-F2-6E-20-EE-3E-CC-DE-79")
|
||||
setKeyEnc("3B-9C-80-57-E6-45-7F-F2-1B-8E-07-63-6C-99-E0-29")
|
||||
|
||||
profileList.add(
|
||||
AppleDeviceProfile(
|
||||
label = "TestProfile",
|
||||
identityKey = cleanKey("79-04-65-1E-E2-CC-D9-26-F2-6E-20-EE-3E-CC-DE-79"),
|
||||
encryptionKey = cleanKey("3B-9C-80-57-E6-45-7F-F2-1B-8E-07-63-6C-99-E0-29")
|
||||
)
|
||||
)
|
||||
|
||||
create<AirPodsPro>(data, address) {
|
||||
batteryLeftPodPercent shouldBe 0.98f
|
||||
isLeftPodCharging shouldBe false
|
||||
|
||||
Reference in New Issue
Block a user