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
25 changes: 25 additions & 0 deletions qubesmanager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def __init_basic_tab__(self):
self.netVM.currentIndexChanged.connect(self.check_warn_dispvmnetvm)
self.netVM.currentIndexChanged.connect(self.check_warn_templatenetvm)
self.netVM.currentIndexChanged.connect(self.check_network_availability)
self.netVM.currentIndexChanged.connect(self.check_warn_anonnetvm)

try:
self.include_in_backups.setChecked(self.vm.include_in_backups)
Expand Down Expand Up @@ -745,6 +746,30 @@ def check_warn_dispvmnetvm(self):
else:
self.warn_netvm_dispvm.setVisible(False)

def check_warn_anonnetvm(self):
if 'anon-vm' not in self.vm.tags:
return

current_net_vm = self.netVM.currentData()

if current_net_vm is None:
return

if current_net_vm == qubesadmin.DEFAULT:
current_net_vm = self.vm.property_get_default('netvm')

if 'anon-gateway' not in current_net_vm.tags:
QtWidgets.QMessageBox.warning(
self,
self.tr("Warning!"),
self.tr(
"Anonymous qubes must be connected to an anonymous gateway "
"to ensure privacy and anonymity. By changing the net qube "
"to a gateway that does not provide anonymity, your IP "
"address will be leaked on the Internet. Continue at your "
"own risk.")
)

def rename_vm(self):

dependencies = admin_utils.vm_dependencies(self.vm.app, self.vm)
Expand Down
36 changes: 35 additions & 1 deletion qubesmanager/tests/test_vm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def settings_fixture(request, qapp, test_qubes_app) -> Tuple[
name="test-pci-dev", qapp=test_qubes_app, label="green",
virt_mode='hvm'
)

test_qubes_app._qubes['sys-whonix'] = MockQube(
name="sys-whonix", qapp=test_qubes_app, tags=['anon-gateway'])

test_qubes_app._qubes['anon-whonix'] = MockQube(
name="anon-whonix", qapp=test_qubes_app, tags=['anon-vm'])

test_qubes_app._devices.append(
MockDevice(test_qubes_app, 'pci', 'USB Controller', '00:03.2',
'dom0', attached='test-pci-dev'))
Expand Down Expand Up @@ -316,7 +323,6 @@ def test_102_change_netvm(settings_fixture):
assert expected_call not in settings_window.qubesapp.actual_calls, \
"Unnecessary NetVM change"


@mock.patch('PyQt6.QtWidgets.QMessageBox.warning')
@pytest.mark.parametrize("settings_fixture", ["fedora-35"], indirect=True)
def test_103_change_netvm_tpl(mock_warning, settings_fixture):
Expand Down Expand Up @@ -583,6 +589,34 @@ def test_112_clonevm(mock_clone, settings_fixture):
mock_clone.assert_called_with(mock.ANY, mock.ANY, src_vm=vm)


@mock.patch('PyQt6.QtWidgets.QMessageBox.warning')
@pytest.mark.parametrize("settings_fixture", ["anon-whonix"], indirect=True)
def test_113_change_netvm_anon(mock_warning, settings_fixture):
settings_window, page, vm_name = settings_fixture
vm = settings_window.qubesapp.domains[vm_name]

change_netvm_call = (vm_name, 'admin.vm.property.Set', 'netvm', b'sys-net')
get_tag_call = (vm_name, 'admin.vm.tag.Get', 'anon-vm', None)

assert settings_window.netVM.isEnabled()

_select_item(settings_window.netVM, "sys-net")

assert get_tag_call in settings_window.qubesapp.actual_calls

assert change_netvm_call not in settings_window.qubesapp.expected_calls
settings_window.qubesapp.expected_calls[change_netvm_call] = b'0\x00'

settings_window.accept()

settings_window.qubesapp.expected_calls[change_netvm_call] = b'0\x00'

assert mock_warning.call_count == 1, ("Didn't warn for changing netvm "
"on anon-vm")

assert change_netvm_call in settings_window.qubesapp.actual_calls


# ADVANCED TAB

@check_errors
Expand Down