mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 04:06:47 +00:00
test: test files named by their topic, one file per topic
- console settings were split over four files; who sees the form, the listen address, and the settings themselves are test_console_settings, and who may open a console is test_console_access; - the three template files are test_templates; - the quota lock test joins test_quota; - accounts' test_security_fixes held two topics: the SSH key tests are test_ssh_keys, the owner-row delete redirect is in test_views; - instances' test_security_mutations, who may change a VM, is test_permissions. The suite runs the same 2097 tests.
This commit is contained in:
parent
bdc8a6755c
commit
f3003bb414
15 changed files with 541 additions and 606 deletions
35
accounts/tests/test_ssh_keys.py
Normal file
35
accounts/tests/test_ssh_keys.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""A user's SSH keys: they go with the user, and a key is valid with or without a comment."""
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
|
||||
from accounts.models import UserSSHKey
|
||||
from accounts.utils import validate_ssh_key
|
||||
|
||||
|
||||
class SshKeyTestCase(TestCase):
|
||||
def test_ssh_key_cascade_deletion(self):
|
||||
user = get_user_model().objects.create_user(username="sec_acc_user", password="password")
|
||||
key = UserSSHKey.objects.create(
|
||||
user=user,
|
||||
keyname="my-key",
|
||||
keypublic="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGabcdef123456 test@example.com",
|
||||
)
|
||||
self.assertTrue(UserSSHKey.objects.filter(id=key.id).exists())
|
||||
|
||||
# When user is deleted, key should be deleted via CASCADE (not left orphan)
|
||||
user.delete()
|
||||
self.assertFalse(UserSSHKey.objects.filter(id=key.id).exists())
|
||||
|
||||
def test_validate_ssh_key_supports_keys_with_and_without_comment(self):
|
||||
rsa_base = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC6OOdbfv27QVnSC6sKxGaHb6YFc+3gxCkyVR3cTSXE/n5BEGf8aOgBpepULWa1RZfxYHY14PlKULDygdXSdrrR2kNSwoKz/Oo4d+3EE92L7ocl1+djZbptzgWgtw1OseLwbFik+iKlIdqPsH+IUQvX7yV545ZQtAP8Qj1R+uCqkw=="
|
||||
# Key with comment
|
||||
key_with_comment = f"{rsa_base} test@test"
|
||||
self.assertTrue(validate_ssh_key(key_with_comment))
|
||||
|
||||
# Key without comment
|
||||
key_without_comment = rsa_base
|
||||
self.assertTrue(validate_ssh_key(key_without_comment))
|
||||
|
||||
# Invalid key
|
||||
self.assertFalse(validate_ssh_key("not a valid key string"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue