mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Update secrets API, views
This commit is contained in:
@@ -80,9 +80,9 @@ class SecretTest(APIViewTestCases.APIViewTestCase):
|
||||
SecretRole.objects.bulk_create(secret_roles)
|
||||
|
||||
secrets = (
|
||||
Secret(device=device, role=secret_roles[0], name='Secret 1', plaintext='ABC'),
|
||||
Secret(device=device, role=secret_roles[0], name='Secret 2', plaintext='DEF'),
|
||||
Secret(device=device, role=secret_roles[0], name='Secret 3', plaintext='GHI'),
|
||||
Secret(assigned_object=device, role=secret_roles[0], name='Secret 1', plaintext='ABC'),
|
||||
Secret(assigned_object=device, role=secret_roles[0], name='Secret 2', plaintext='DEF'),
|
||||
Secret(assigned_object=device, role=secret_roles[0], name='Secret 3', plaintext='GHI'),
|
||||
)
|
||||
for secret in secrets:
|
||||
secret.encrypt(self.master_key)
|
||||
@@ -90,19 +90,22 @@ class SecretTest(APIViewTestCases.APIViewTestCase):
|
||||
|
||||
self.create_data = [
|
||||
{
|
||||
'device': device.pk,
|
||||
'assigned_object_type': 'dcim.device',
|
||||
'assigned_object_id': device.pk,
|
||||
'role': secret_roles[1].pk,
|
||||
'name': 'Secret 4',
|
||||
'plaintext': 'JKL',
|
||||
},
|
||||
{
|
||||
'device': device.pk,
|
||||
'assigned_object_type': 'dcim.device',
|
||||
'assigned_object_id': device.pk,
|
||||
'role': secret_roles[1].pk,
|
||||
'name': 'Secret 5',
|
||||
'plaintext': 'MNO',
|
||||
},
|
||||
{
|
||||
'device': device.pk,
|
||||
'assigned_object_type': 'dcim.device',
|
||||
'assigned_object_id': device.pk,
|
||||
'role': secret_roles[1].pk,
|
||||
'name': 'Secret 6',
|
||||
'plaintext': 'PQR',
|
||||
|
@@ -69,13 +69,14 @@ class SecretTestCase(
|
||||
|
||||
# Create one secret per device to allow bulk-editing of names (which must be unique per device/role)
|
||||
Secret.objects.bulk_create((
|
||||
Secret(device=devices[0], role=secretroles[0], name='Secret 1', ciphertext=b'1234567890'),
|
||||
Secret(device=devices[1], role=secretroles[0], name='Secret 2', ciphertext=b'1234567890'),
|
||||
Secret(device=devices[2], role=secretroles[0], name='Secret 3', ciphertext=b'1234567890'),
|
||||
Secret(assigned_object=devices[0], role=secretroles[0], name='Secret 1', ciphertext=b'1234567890'),
|
||||
Secret(assigned_object=devices[1], role=secretroles[0], name='Secret 2', ciphertext=b'1234567890'),
|
||||
Secret(assigned_object=devices[2], role=secretroles[0], name='Secret 3', ciphertext=b'1234567890'),
|
||||
))
|
||||
|
||||
cls.form_data = {
|
||||
'device': devices[1].pk,
|
||||
'assigned_object_type': 'dcim.device',
|
||||
'assigned_object_id': devices[1].pk,
|
||||
'role': secretroles[1].pk,
|
||||
'name': 'Secret X',
|
||||
}
|
||||
@@ -100,11 +101,12 @@ class SecretTestCase(
|
||||
def test_import_objects(self):
|
||||
self.add_permissions('secrets.add_secret')
|
||||
|
||||
device = Device.objects.get(name='Device 1')
|
||||
csv_data = (
|
||||
"device,role,name,plaintext",
|
||||
"Device 1,Secret Role 1,Secret 4,abcdefghij",
|
||||
"Device 1,Secret Role 1,Secret 5,abcdefghij",
|
||||
"Device 1,Secret Role 1,Secret 6,abcdefghij",
|
||||
"assigned_object_type,assigned_object_id,role,name,plaintext",
|
||||
f"device,{device.pk},Secret Role 1,Secret 4,abcdefghij",
|
||||
f"device,{device.pk},Secret Role 1,Secret 5,abcdefghij",
|
||||
f"device,{device.pk},Secret Role 1,Secret 6,abcdefghij",
|
||||
)
|
||||
|
||||
# Set the session_key cookie on the request
|
||||
|
Reference in New Issue
Block a user