Skip to content
Snippets Groups Projects
Commit 1f85ed9f authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Fix extra interface creation

Not sure why a tuple instead of network was returned...
There must have been a comma at the end of the line due to copy/pasting
and black converted that to a tuple.

Added a test for the create_interface function.

JIRA INFRA-697 #action In Progress
parent 537991a2
No related branches found
No related tags found
No related merge requests found
......@@ -265,7 +265,7 @@ def create_interface(hostname):
)
if form.validate_on_submit():
# User shall have access to the new interface domain
network = (models.Network.query.get(form.network_id.data),)
network = models.Network.query.get(form.network_id.data)
if not current_user.has_access_to_network(network):
abort(403)
# The total number of tags will always be quite small
......
......@@ -305,3 +305,50 @@ def test_create_host(client, domain_factory, network_factory, device_type):
assert host.interfaces[0].ip == ip
assert host.interfaces[0].mac == mac
assert host.interfaces[0].name == name
def test_create_interface(
client, host_factory, domain_factory, network_factory, interface_factory
):
host = host_factory(name="myhost")
domain = domain_factory(name="prod.example.org")
network1 = network_factory(domain=domain)
interface_factory(network=network1, host=host)
network2 = network_factory(
address="192.168.2.0/24",
first_ip="192.168.2.10",
last_ip="192.168.2.250",
domain=domain,
)
name = host.name + "-2"
ip = "192.168.2.11"
mac = "02:42:42:46:3c:75"
form = {
"host_id": host.id,
"interface_name": name,
"network_id": network2.id,
"random_mac": False,
"ip": ip,
"mac": mac,
"cnames_string": "",
"tags": [],
}
# Permission denied
# user_lab doesn't have permissions for the host domain: prod.example.org
login(client, "user_lab", "userlab")
response = client.post(f"/network/interfaces/create/{host.name}", data=form)
assert response.status_code == 403
# The host wasn't created
assert models.Interface.query.filter_by(name=name).first() is None
logout(client)
# Success with user_prod user
login(client, "user_prod", "userprod")
response = client.post(f"/network/interfaces/create/{host.name}", data=form)
assert response.status_code == 302
# The interface was created
interface = models.Interface.query.filter_by(name=name).first()
assert interface is not None
assert interface.ip == ip
assert interface.mac == mac
assert interface.name == name
assert interface.host == host
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment