mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 13:15:14 +02:00
nodes: per-node default credentials seeded from the template
Add default_username/default_password as controller-only node properties (the netmiko_device_type pattern): they are not sent to the compute, persist with the project topology and can be updated or cleared per node. Creating a node from a template seeds them from the template appliance metadata, and the metadata itself is dropped there so it never leaks into the node properties.
This commit is contained in:
5 files changed
+125
No files matched your search
@@ -204,6 +204,48 @@ async def test_add_node_local(controller):
|
||||
project.emit_notification.assert_any_call("node.created", node.asdict())
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_from_template_seeds_default_credentials(controller):
|
||||
"""
|
||||
The appliance metadata stays template level: creating a node from a
|
||||
template seeds the default credentials on the node and must not leak
|
||||
the metadata into the node properties sent to the compute.
|
||||
"""
|
||||
|
||||
compute = MagicMock()
|
||||
compute.id = "local"
|
||||
controller._computes["local"] = compute
|
||||
project = Project(controller=controller, name="Test")
|
||||
project.emit_notification = MagicMock()
|
||||
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
template = {
|
||||
"name": "VPCS_TEST",
|
||||
"template_type": "vpcs",
|
||||
"compute_id": "local",
|
||||
"default_name_format": "PC{0}",
|
||||
"properties": {"startup_script": "test.cfg"},
|
||||
"appliance_metadata": {
|
||||
"vendor_name": "Test vendor",
|
||||
"default_username": "admin",
|
||||
"default_password": "secret",
|
||||
},
|
||||
}
|
||||
|
||||
node = await project.add_node_from_template(template)
|
||||
|
||||
# credentials seeded from the appliance metadata
|
||||
assert node.default_username == "admin"
|
||||
assert node.default_password == "secret"
|
||||
# the metadata itself never reaches the node properties
|
||||
assert "appliance_metadata" not in node.properties
|
||||
assert "default_username" not in node.properties
|
||||
assert "default_password" not in node.properties
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_non_local(controller):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user