Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indexing bug in SettingsAddConnection #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions dbusmock/templates/networkmanager.py
Expand Up @@ -674,14 +674,13 @@ def SettingsAddConnection(self, connection_settings):
main_connections = settings_obj.ListConnections()

# Mimic how NM names connections
connection_name = str(len(main_connections))

connection_path = SETTINGS_OBJ + '/' + connection_name

if connection_path in main_connections:
raise dbus.exceptions.DBusException(
'Connection %s already exists' % connection_path,
name=MAIN_IFACE + '.AlreadyExists',)
count = 0
while True:
connection_obj_path = dbus.ObjectPath(SETTINGS_OBJ + '/' + str(count))
if connection_obj_path not in main_connections:
break
count += 1
connection_path = str(connection_obj_path)

self.AddObject(connection_path,
CSETTINGS_IFACE,
Expand Down
47 changes: 47 additions & 0 deletions tests/test_networkmanager.py
Expand Up @@ -342,6 +342,53 @@ def test_remove_connection(self):
self.assertFalse(re.compile('The_SSID.*\s802-11-wireless').search(self.read_active_connection()))
self.assertRegex(self.read_device(), 'wlan0.*\sdisconnected')

def test_add_remove_settings(self):
connection = {
'connection': {
'timestamp': 1441979296,
'type': 'vpn',
'id': 'a',
'uuid': '11111111-1111-1111-1111-111111111111'
},
'vpn': {
'service-type': 'org.freedesktop.NetworkManager.openvpn',
'data': {
'connection-type': 'tls'
}
},
'ipv4': {
'routes': dbus.Array([], signature='o'),
'never-default': True,
'addresses': dbus.Array([], signature='o'),
'dns': dbus.Array([], signature='o'),
'method': 'auto'
},
'ipv6': {
'addresses': dbus.Array([], signature='o'),
'ip6-privacy': 0,
'dns': dbus.Array([], signature='o'),
'never-default': True,
'routes': dbus.Array([], signature='o'),
'method': 'auto'
}
}

connectionA = self.settings.AddConnection(connection)
connection['connection']['id'] = 'b'
connection['connection']['uuid'] = '11111111-1111-1111-1111-111111111112'
connectionB = self.settings.AddConnection(connection)
self.assertEqual(self.settings.ListConnections(), [connectionA, connectionB])

connectionA_i = dbus.Interface(
self.dbus_con.get_object(MAIN_IFACE, connectionA), CSETTINGS_IFACE)
connectionA_i.Delete()
self.assertEqual(self.settings.ListConnections(), [connectionB])

connection['connection']['id'] = 'c'
connection['connection']['uuid'] = '11111111-1111-1111-1111-111111111113'
connectionC = self.settings.AddConnection(connection)
self.assertEqual(self.settings.ListConnections(), [connectionB, connectionC])


if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))