diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-09-08 14:35:53 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-09-09 12:52:08 +0200 |
| commit | b80d26872f8346aa7f470b658569e94b007b0dbe (patch) | |
| tree | 807c8db111427dbeead95ea36ceb13e1a20197c3 /android/app/src/test | |
| parent | b79b4c95ada5e4a38cbb05e7533e8a06daeca069 (diff) | |
| download | mullvadvpn-b80d26872f8346aa7f470b658569e94b007b0dbe.tar.xz mullvadvpn-b80d26872f8346aa7f470b658569e94b007b0dbe.zip | |
Do not block exit relays when daita is enabled
If a entry relay is selected it should be blocked in the exit list
when daita is enabled and direct only is disabled.
This is because the entry relay is automatically selected in these
circumstances.
Diffstat (limited to 'android/app/src/test')
2 files changed, 58 insertions, 0 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt index 8aa1e9b038..a71c95863f 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt @@ -16,10 +16,12 @@ import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.RelayItem import net.mullvad.mullvadvpn.lib.model.RelayItemSelection +import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.lib.ui.component.relaylist.RelayListItem import net.mullvad.mullvadvpn.repository.CustomListsRepository import net.mullvad.mullvadvpn.repository.RelayListFilterRepository +import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository import net.mullvad.mullvadvpn.usecase.FilterChip import net.mullvad.mullvadvpn.usecase.FilterChipUseCase @@ -50,6 +52,7 @@ class SearchLocationViewModelTest { private val mockCustomListsRelayItemUseCase: CustomListsRelayItemUseCase = mockk() private val mockSelectHopUseCase: SelectHopUseCase = mockk() private val mockModifyMultihopUseCase: ModifyMultihopUseCase = mockk() + private val mockSettingsRepository: SettingsRepository = mockk() private val filteredRelayList = MutableStateFlow<List<RelayItem.Location.Country>>(emptyList()) private val selectedLocation = @@ -59,6 +62,7 @@ class SearchLocationViewModelTest { private val customListRelayItems = MutableStateFlow<List<RelayItem.CustomList>>(emptyList()) private val filterChips = MutableStateFlow<List<FilterChip>>(emptyList()) private val wireguardConstraints = MutableStateFlow<WireguardConstraints>(mockk(relaxed = true)) + private val settingsFlow = MutableStateFlow(mockk<Settings>(relaxed = true)) private lateinit var viewModel: SearchLocationViewModel @@ -72,6 +76,7 @@ class SearchLocationViewModelTest { every { mockFilterChipUseCase(any()) } returns filterChips every { mockWireguardConstraintsRepository.wireguardConstraints } returns wireguardConstraints + every { mockSettingsRepository.settingsUpdates } returns settingsFlow viewModel = SearchLocationViewModel( @@ -86,6 +91,7 @@ class SearchLocationViewModelTest { customListsRelayItemUseCase = mockCustomListsRelayItemUseCase, selectHopUseCase = mockSelectHopUseCase, modifyMultihopUseCase = mockModifyMultihopUseCase, + settingsRepository = mockSettingsRepository, savedStateHandle = SearchLocationNavArgs(relayListType = RelayListType.Single).toSavedStateHandle(), ) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt index 8c01d592e5..436e061d1d 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt @@ -3,9 +3,13 @@ package net.mullvad.mullvadvpn.viewmodel.location import app.cash.turbine.test import io.mockk.every import io.mockk.mockk +import io.mockk.mockkStatic +import io.mockk.unmockkAll +import io.mockk.verify import kotlin.test.assertIs import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.runTest +import net.mullvad.mullvadvpn.compose.state.MultihopRelayListType import net.mullvad.mullvadvpn.compose.state.RelayListType import net.mullvad.mullvadvpn.compose.state.SelectLocationListUiState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule @@ -26,6 +30,7 @@ import net.mullvad.mullvadvpn.usecase.SelectedLocationUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListsRelayItemUseCase import net.mullvad.mullvadvpn.usecase.customlists.FilterCustomListsRelayItemUseCase import net.mullvad.mullvadvpn.util.Lce +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach @@ -68,6 +73,14 @@ class SelectLocationListViewModelTest { every { mockCustomListRelayItemsUseCase() } returns customListRelayItems every { mockSettingsRepository.settingsUpdates } returns settings every { recentsUseCase(any()) } returns recentsRelayItems + + mockkStatic(RELAY_ITEM_LIST_CREATOR_CLASS) + mockkStatic(LOCATION_UTIL_CLASS) + } + + @AfterEach + fun tearDown() { + unmockkAll() } @Test @@ -127,6 +140,40 @@ class SelectLocationListViewModelTest { } } + @Test + fun `given relay list type exit and entry blocked isEntryBlocked should be true`() = runTest { + // Arrange + viewModel = + createSelectLocationListViewModel(RelayListType.Multihop(MultihopRelayListType.EXIT)) + filteredRelayList.value = testCountries + val exitLocation = Constraint.Only(GeoLocationId.Country("us")) + selectedLocationFlow.value = + RelayItemSelection.Multiple( + entryLocation = Constraint.Only(GeoLocationId.Country("se")), + exitLocation = exitLocation, + ) + every { settings.value.entryBlocked() } returns true + + // Act, Assert + viewModel.uiState.test { + awaitItem() + + verify { + relayListItems( + relayListType = RelayListType.Multihop(MultihopRelayListType.EXIT), + relayCountries = testCountries, + customLists = any(), + recents = any(), + selectedItem = any(), + selectedByThisEntryExitList = exitLocation.getOrNull(), + selectedByOtherEntryExitList = null, + expandedItems = emptySet(), + isEntryBlocked = true, + ) + } + } + } + private fun createSelectLocationListViewModel(relayListType: RelayListType) = SelectLocationListViewModel( relayListType = relayListType, @@ -157,6 +204,11 @@ class SelectLocationListViewModelTest { } companion object { + private const val RELAY_ITEM_LIST_CREATOR_CLASS = + "net.mullvad.mullvadvpn.viewmodel.location.RelayItemListCreatorKt" + private const val LOCATION_UTIL_CLASS = + "net.mullvad.mullvadvpn.viewmodel.location.LocationUtilKt" + private val testCountries = listOf( RelayItem.Location.Country( |
