2016-01-29 11:04:59 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-06-01 15:42:32 +02:00
|
|
|
from datetime import date
|
|
|
|
|
2015-01-31 21:48:07 +01:00
|
|
|
from django.conf import settings
|
2019-01-30 21:27:25 +01:00
|
|
|
from django.contrib.auth import get_user_model
|
2014-06-01 01:36:50 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.utils import override_settings
|
2014-06-01 15:42:32 +02:00
|
|
|
from django.utils import timezone
|
2014-06-01 14:43:42 +02:00
|
|
|
from passlib.hash import sha512_crypt
|
|
|
|
|
2014-06-01 01:36:50 +02:00
|
|
|
from osusers.models import (
|
2019-01-30 21:27:25 +01:00
|
|
|
CANNOT_USE_PRIMARY_GROUP_AS_ADDITIONAL,
|
2023-02-18 22:46:48 +01:00
|
|
|
AdditionalGroup,
|
2014-06-01 01:36:50 +02:00
|
|
|
Group,
|
|
|
|
Shadow,
|
2015-01-31 21:48:07 +01:00
|
|
|
SshPublicKey,
|
2014-06-01 01:36:50 +02:00
|
|
|
User,
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
from taskresults.models import TaskResult
|
|
|
|
|
|
|
|
EXAMPLE_KEY_1_RFC4716 = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
Comment: "1024-bit RSA, converted from OpenSSH by me@example.com"
|
|
|
|
x-command: /home/me/bin/lock-in-guest.sh
|
|
|
|
AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRb
|
|
|
|
YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ
|
|
|
|
5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
|
|
|
EXAMPLE_KEY_2_RFC4716 = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
Comment: This is my public key for use on \
|
|
|
|
servers which I don't like.
|
|
|
|
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
|
|
|
|
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
|
|
|
|
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
|
|
|
|
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
|
|
|
|
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
|
|
|
|
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
|
|
|
|
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
|
|
|
|
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
|
|
|
|
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
|
|
|
EXAMPLE_KEY_3_RFC4716 = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
Comment: DSA Public Key for use with MyIsp
|
|
|
|
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
|
|
|
|
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
|
|
|
|
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
|
|
|
|
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
|
|
|
|
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
|
|
|
|
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
|
|
|
|
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
|
|
|
|
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
|
|
|
|
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
EXAMPLE_KEY_4_OPENSSH = "".join(
|
|
|
|
(
|
|
|
|
"ssh-rsa ",
|
|
|
|
"AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRb",
|
|
|
|
"YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ",
|
|
|
|
"5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=",
|
|
|
|
)
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
EXAMPLE_KEY_5_RFC4716_MULTILINE = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
Comment: DSA Public Key \\
|
|
|
|
for use with \\
|
|
|
|
MyIsp
|
|
|
|
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
|
|
|
|
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
|
|
|
|
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
|
|
|
|
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
|
|
|
|
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
|
|
|
|
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
|
|
|
|
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
|
|
|
|
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
|
|
|
|
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
|
|
|
EXAMPLE_KEY_6_RFC4716_EMPTY_LINE = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
Comment: DSA Public Key for use with MyIsp
|
|
|
|
|
|
|
|
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
|
|
|
|
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
|
|
|
|
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
|
|
|
|
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
|
|
|
|
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
|
|
|
|
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
|
|
|
|
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
|
|
|
|
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
|
|
|
|
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
2015-12-06 17:47:27 +01:00
|
|
|
EXAMPLE_KEY_7_NO_COMMENT = """---- BEGIN SSH2 PUBLIC KEY ----
|
|
|
|
AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRb
|
|
|
|
YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ
|
|
|
|
5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=
|
|
|
|
---- END SSH2 PUBLIC KEY ----"""
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
EXAMPLE_KEY_8_OPENSSH_BROKEN = "".join(("ssh-rsa ", "AschrÖdderöd"))
|
2015-12-06 17:47:27 +01:00
|
|
|
|
|
|
|
EXAMPLE_KEY_9_RFC4716_ONLY_HEADER = "---- BEGIN SSH2 PUBLIC KEY ----"
|
|
|
|
|
2015-01-31 21:48:07 +01:00
|
|
|
Customer = get_user_model()
|
2014-06-01 01:36:50 +02:00
|
|
|
|
|
|
|
|
2014-06-01 01:45:50 +02:00
|
|
|
@override_settings(
|
2019-01-30 21:27:25 +01:00
|
|
|
CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND="memory", BROKER_BACKEND="memory"
|
2014-06-01 01:45:50 +02:00
|
|
|
)
|
|
|
|
class TestCaseWithCeleryTasks(TestCase):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class AdditionalGroupTest(TestCaseWithCeleryTasks):
|
2014-06-01 16:30:14 +02:00
|
|
|
def setUp(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
customer = Customer.objects.create(username="test")
|
|
|
|
self.group1 = Group.objects.create(groupname="test1", gid=1000)
|
2014-06-01 16:30:14 +02:00
|
|
|
self.user = User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=customer,
|
|
|
|
username="test",
|
|
|
|
uid=1000,
|
|
|
|
group=self.group1,
|
|
|
|
homedir="/home/test",
|
|
|
|
shell="/bin/bash",
|
|
|
|
)
|
2014-06-01 16:30:14 +02:00
|
|
|
|
|
|
|
def test_clean_primary_group(self):
|
|
|
|
testsubj = AdditionalGroup(user=self.user, group=self.group1)
|
2014-06-01 01:36:50 +02:00
|
|
|
with self.assertRaises(ValidationError) as cm:
|
|
|
|
testsubj.clean()
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(cm.exception.message, CANNOT_USE_PRIMARY_GROUP_AS_ADDITIONAL)
|
2014-06-01 01:36:50 +02:00
|
|
|
|
|
|
|
def test_clean_other_group(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group2 = Group.objects.create(groupname="test2", gid=1001)
|
2014-06-01 16:30:14 +02:00
|
|
|
testsubj = AdditionalGroup(user=self.user, group=group2)
|
2014-06-01 01:36:50 +02:00
|
|
|
testsubj.clean()
|
|
|
|
|
2014-06-01 16:30:14 +02:00
|
|
|
def test_save(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group2 = Group.objects.create(groupname="test2", gid=1001)
|
2014-06-01 16:30:14 +02:00
|
|
|
addgroup = AdditionalGroup(user=self.user, group=group2)
|
|
|
|
addgroup.save()
|
2015-01-31 21:48:07 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertTrue(len(taskres), 4)
|
|
|
|
creators = [r.creator for r in taskres]
|
|
|
|
for tcount, tcreator in [
|
2019-01-30 21:27:25 +01:00
|
|
|
(2, "handle_group_created"),
|
|
|
|
(1, "handle_user_created"),
|
|
|
|
(1, "handle_user_added_to_group"),
|
|
|
|
]:
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(creators.count(tcreator), tcount)
|
2014-06-01 16:30:14 +02:00
|
|
|
|
2015-12-06 17:47:27 +01:00
|
|
|
def test_save_again(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group2 = Group.objects.create(groupname="test2", gid=1001)
|
2015-12-06 17:47:27 +01:00
|
|
|
TaskResult.objects.all().delete()
|
2016-01-28 14:44:29 +01:00
|
|
|
addgroup = AdditionalGroup(user=self.user, group=group2)
|
|
|
|
addgroup.save()
|
|
|
|
TaskResult.objects.all().delete()
|
|
|
|
addgroup.save()
|
2015-12-06 17:47:27 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
|
|
|
self.assertEqual(len(taskres), 0)
|
|
|
|
|
2014-06-01 16:30:14 +02:00
|
|
|
def test_delete(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group2 = Group.objects.create(groupname="test2", gid=1001)
|
|
|
|
# noinspection PyUnresolvedReferences
|
2014-06-01 16:30:14 +02:00
|
|
|
addgroup = AdditionalGroup.objects.create(user=self.user, group=group2)
|
|
|
|
addgroup.delete()
|
2019-01-30 21:27:25 +01:00
|
|
|
# noinspection PyUnresolvedReferences
|
2014-06-01 16:30:14 +02:00
|
|
|
self.assertEqual(len(AdditionalGroup.objects.all()), 0)
|
|
|
|
|
|
|
|
def test___str__(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group2 = Group.objects.create(groupname="test2", gid=1001)
|
|
|
|
# noinspection PyUnresolvedReferences
|
2014-06-01 16:30:14 +02:00
|
|
|
addgroup = AdditionalGroup.objects.create(user=self.user, group=group2)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(str(addgroup), "test (1000) in test2 (1001)")
|
2014-06-01 16:30:14 +02:00
|
|
|
|
2014-06-01 01:36:50 +02:00
|
|
|
|
2014-06-01 11:56:42 +02:00
|
|
|
@override_settings(OSUSER_MINGID=10000)
|
2014-06-01 21:28:24 +02:00
|
|
|
class GroupManagerTest(TestCaseWithCeleryTasks):
|
2014-06-01 11:56:42 +02:00
|
|
|
def test_get_next_gid_first(self):
|
|
|
|
self.assertEqual(Group.objects.get_next_gid(), 10000)
|
|
|
|
|
|
|
|
def test_get_next_gid_second(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
Group.objects.create(gid=10010, groupname="test")
|
2014-06-01 11:56:42 +02:00
|
|
|
self.assertEqual(Group.objects.get_next_gid(), 10011)
|
|
|
|
|
|
|
|
|
2014-06-01 01:45:50 +02:00
|
|
|
class GroupTest(TestCaseWithCeleryTasks):
|
2014-06-01 11:56:42 +02:00
|
|
|
def test___str__(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(gid=10000, groupname="test")
|
|
|
|
self.assertEqual(str(group), "test (10000)")
|
2014-06-01 11:56:42 +02:00
|
|
|
|
|
|
|
def test_save(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group(gid=10000, groupname="test")
|
2014-06-01 11:56:42 +02:00
|
|
|
self.assertIs(group.save(), group)
|
2016-01-28 14:44:29 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
|
|
|
self.assertTrue(len(taskres), 1)
|
|
|
|
creators = [r.creator for r in taskres]
|
2019-01-30 21:27:25 +01:00
|
|
|
for tcount, tcreator in [(1, "handle_group_created")]:
|
2016-01-28 14:44:29 +01:00
|
|
|
self.assertEqual(creators.count(tcreator), tcount)
|
|
|
|
|
|
|
|
def test_save_again(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(gid=10000, groupname="test")
|
|
|
|
TaskResult.objects.all().delete()
|
2016-01-28 14:44:29 +01:00
|
|
|
group.save()
|
|
|
|
taskres = TaskResult.objects.all()
|
|
|
|
self.assertEqual(len(taskres), 0)
|
2014-06-01 11:56:42 +02:00
|
|
|
|
|
|
|
def test_delete(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(gid=10000, groupname="test")
|
2014-06-01 11:56:42 +02:00
|
|
|
self.assertEqual(len(Group.objects.all()), 1)
|
|
|
|
group.delete()
|
|
|
|
self.assertEqual(len(Group.objects.all()), 0)
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(len(TaskResult.objects.all()), 2)
|
2015-01-31 21:48:07 +01:00
|
|
|
tr = TaskResult.objects.first()
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(tr.creator, "handle_group_created")
|
2014-06-01 01:36:50 +02:00
|
|
|
|
|
|
|
|
2014-06-01 15:42:32 +02:00
|
|
|
class ShadowManagerTest(TestCaseWithCeleryTasks):
|
2015-01-31 21:48:07 +01:00
|
|
|
def setUp(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
self.customer = Customer.objects.create(username="test")
|
2015-01-31 21:48:07 +01:00
|
|
|
super(ShadowManagerTest, self).setUp()
|
|
|
|
|
2014-06-01 15:42:32 +02:00
|
|
|
def test_create_shadow(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(gid=1000, groupname="test")
|
|
|
|
user = User.objects.create(
|
|
|
|
customer=self.customer,
|
|
|
|
username="test",
|
|
|
|
uid=1000,
|
|
|
|
group=group,
|
|
|
|
homedir="/home/test",
|
|
|
|
shell="/bin/fooshell",
|
|
|
|
)
|
|
|
|
shadow = Shadow.objects.create_shadow(user, "test")
|
|
|
|
self.assertTrue(sha512_crypt.verify("test", shadow.passwd))
|
|
|
|
self.assertEqual(
|
|
|
|
shadow.changedays, (timezone.now().date() - date(1970, 1, 1)).days
|
|
|
|
)
|
2014-06-01 15:42:32 +02:00
|
|
|
self.assertEqual(shadow.user, user)
|
|
|
|
self.assertEqual(shadow.minage, 0)
|
|
|
|
self.assertIsNone(shadow.maxage)
|
|
|
|
self.assertEqual(shadow.gracedays, 7)
|
|
|
|
self.assertEqual(shadow.inactdays, 30)
|
|
|
|
self.assertIsNone(shadow.expiredays)
|
|
|
|
|
|
|
|
|
2014-06-01 01:45:50 +02:00
|
|
|
class ShadowTest(TestCaseWithCeleryTasks):
|
2015-01-31 21:48:07 +01:00
|
|
|
def setUp(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
self.customer = Customer.objects.create(username="test")
|
2015-01-31 21:48:07 +01:00
|
|
|
super(ShadowTest, self).setUp()
|
|
|
|
|
2014-06-01 01:45:50 +02:00
|
|
|
def test___str__(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(groupname="test", gid=1000)
|
2014-06-01 01:45:50 +02:00
|
|
|
user = User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
username="test",
|
|
|
|
uid=1000,
|
|
|
|
group=group,
|
|
|
|
homedir="/home/test",
|
|
|
|
shell="/bin/bash",
|
|
|
|
)
|
2014-06-01 01:45:50 +02:00
|
|
|
shadow = Shadow(user=user)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(str(shadow), "for user test (1000)")
|
2014-06-01 01:36:50 +02:00
|
|
|
|
2014-06-01 16:09:30 +02:00
|
|
|
def test_set_password(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group = Group.objects.create(groupname="test", gid=1000)
|
2014-06-01 16:09:30 +02:00
|
|
|
user = User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
username="test",
|
|
|
|
uid=1000,
|
|
|
|
group=group,
|
|
|
|
homedir="/home/test",
|
|
|
|
shell="/bin/bash",
|
|
|
|
)
|
2014-06-01 16:09:30 +02:00
|
|
|
shadow = Shadow(user=user)
|
2019-01-30 21:27:25 +01:00
|
|
|
shadow.set_password("test")
|
|
|
|
self.assertTrue(sha512_crypt.verify("test", shadow.passwd))
|
2014-06-01 16:09:30 +02:00
|
|
|
|
2014-06-01 01:36:50 +02:00
|
|
|
|
2014-06-01 14:43:42 +02:00
|
|
|
@override_settings(
|
2019-01-30 21:27:25 +01:00
|
|
|
OSUSER_MINUID=10000,
|
|
|
|
OSUSER_MINGID=10000,
|
|
|
|
OSUSER_USERNAME_PREFIX="test",
|
|
|
|
OSUSER_HOME_BASEPATH="/home",
|
|
|
|
OSUSER_DEFAULT_SHELL="/bin/fooshell",
|
2014-06-01 14:43:42 +02:00
|
|
|
)
|
|
|
|
class UserManagerTest(TestCaseWithCeleryTasks):
|
|
|
|
def _create_group(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
return Group.objects.create(gid=10000, groupname="foo")
|
2014-06-01 14:43:42 +02:00
|
|
|
|
2015-01-31 21:48:07 +01:00
|
|
|
def setUp(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
self.customer = Customer.objects.create(username="test")
|
2015-01-31 21:48:07 +01:00
|
|
|
super(UserManagerTest, self).setUp()
|
|
|
|
|
2014-06-01 14:43:42 +02:00
|
|
|
def test_get_next_uid_first(self):
|
|
|
|
self.assertEqual(User.objects.get_next_uid(), 10000)
|
|
|
|
|
|
|
|
def test_get_next_uid_second(self):
|
|
|
|
User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
uid=10010,
|
|
|
|
username="foo",
|
|
|
|
group=self._create_group(),
|
|
|
|
homedir="/home/foo",
|
|
|
|
shell="/bin/fooshell",
|
|
|
|
)
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertEqual(User.objects.get_next_uid(), 10011)
|
|
|
|
|
|
|
|
def test_get_next_username_first(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(User.objects.get_next_username(), "test01")
|
2014-06-01 14:43:42 +02:00
|
|
|
|
|
|
|
def test_get_next_username_second(self):
|
|
|
|
User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
uid=10000,
|
|
|
|
username="test01",
|
|
|
|
group=self._create_group(),
|
|
|
|
homedir="/home/foo",
|
|
|
|
shell="/bin/fooshell",
|
|
|
|
)
|
|
|
|
self.assertEqual(User.objects.get_next_username(), "test02")
|
2014-06-01 14:43:42 +02:00
|
|
|
|
|
|
|
def test_get_next_username_gaps(self):
|
|
|
|
group = self._create_group()
|
|
|
|
User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
uid=10000,
|
|
|
|
username="test01",
|
|
|
|
group=group,
|
|
|
|
homedir="/home/foo",
|
|
|
|
shell="/bin/fooshell",
|
|
|
|
)
|
2014-06-01 14:43:42 +02:00
|
|
|
User.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer=self.customer,
|
|
|
|
uid=10002,
|
|
|
|
username="test03",
|
|
|
|
group=group,
|
|
|
|
homedir="/home/foo",
|
|
|
|
shell="/bin/fooshell",
|
|
|
|
)
|
|
|
|
self.assertEqual(User.objects.get_next_username(), "test02")
|
2014-06-01 14:43:42 +02:00
|
|
|
|
|
|
|
def test_create_user_first(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(customer=self.customer)
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsInstance(user, User)
|
|
|
|
self.assertEqual(user.uid, 10000)
|
|
|
|
self.assertEqual(user.group.gid, 10000)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(user.group.groupname, "test01")
|
|
|
|
self.assertEqual(user.username, "test01")
|
|
|
|
self.assertEqual(user.homedir, "/home/test01")
|
|
|
|
self.assertEqual(user.shell, "/bin/fooshell")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsNotNone(user.shadow)
|
|
|
|
|
2014-06-01 15:03:15 +02:00
|
|
|
def test_create_user_tasks(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
User.objects.create_user(customer=self.customer)
|
|
|
|
taskres = TaskResult.objects.all()
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(len(taskres), 3)
|
|
|
|
creators = [r.creator for r in taskres]
|
|
|
|
for creator in [
|
2019-01-30 21:27:25 +01:00
|
|
|
"handle_group_created",
|
|
|
|
"handle_user_created",
|
|
|
|
"handle_user_password_set",
|
|
|
|
]:
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertIn(creator, creators)
|
2014-06-01 15:03:15 +02:00
|
|
|
|
2014-06-01 14:43:42 +02:00
|
|
|
def test_create_user_second(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
User.objects.create_user(customer=self.customer)
|
|
|
|
user = User.objects.create_user(customer=self.customer)
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsInstance(user, User)
|
|
|
|
self.assertEqual(user.uid, 10001)
|
|
|
|
self.assertEqual(user.group.gid, 10001)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(user.group.groupname, "test02")
|
|
|
|
self.assertEqual(user.username, "test02")
|
|
|
|
self.assertEqual(user.homedir, "/home/test02")
|
|
|
|
self.assertEqual(user.shell, "/bin/fooshell")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsNotNone(user.shadow)
|
|
|
|
self.assertEqual(len(User.objects.all()), 2)
|
|
|
|
|
|
|
|
def test_create_user_known_password(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
user = User.objects.create_user(customer=self.customer, password="foobar")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsInstance(user, User)
|
|
|
|
self.assertEqual(user.uid, 10000)
|
|
|
|
self.assertEqual(user.group.gid, 10000)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(user.group.groupname, "test01")
|
|
|
|
self.assertEqual(user.username, "test01")
|
|
|
|
self.assertEqual(user.homedir, "/home/test01")
|
|
|
|
self.assertEqual(user.shell, "/bin/fooshell")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsNotNone(user.shadow)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertTrue(sha512_crypt.verify("foobar", user.shadow.passwd))
|
2014-06-01 14:43:42 +02:00
|
|
|
|
|
|
|
def test_create_user_predefined_username(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
user = User.objects.create_user(customer=self.customer, username="tester")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsInstance(user, User)
|
|
|
|
self.assertEqual(user.uid, 10000)
|
|
|
|
self.assertEqual(user.group.gid, 10000)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(user.group.groupname, "tester")
|
|
|
|
self.assertEqual(user.username, "tester")
|
|
|
|
self.assertEqual(user.homedir, "/home/tester")
|
|
|
|
self.assertEqual(user.shell, "/bin/fooshell")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsNotNone(user.shadow)
|
|
|
|
|
|
|
|
def test_create_user_commit(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(customer=self.customer, commit=True)
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsInstance(user, User)
|
|
|
|
self.assertEqual(user.uid, 10000)
|
|
|
|
self.assertEqual(user.group.gid, 10000)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(user.group.groupname, "test01")
|
|
|
|
self.assertEqual(user.username, "test01")
|
|
|
|
self.assertEqual(user.homedir, "/home/test01")
|
|
|
|
self.assertEqual(user.shell, "/bin/fooshell")
|
2014-06-01 14:43:42 +02:00
|
|
|
self.assertIsNotNone(user.shadow)
|
|
|
|
|
|
|
|
|
2014-06-01 14:51:33 +02:00
|
|
|
@override_settings(
|
2019-01-30 21:27:25 +01:00
|
|
|
OSUSER_MINUID=10000,
|
|
|
|
OSUSER_MINGID=10000,
|
|
|
|
OSUSER_USERNAME_PREFIX="test",
|
|
|
|
OSUSER_HOME_BASEPATH="/home",
|
|
|
|
OSUSER_DEFAULT_SHELL="/bin/fooshell",
|
2014-06-01 14:51:33 +02:00
|
|
|
)
|
2014-06-01 01:45:50 +02:00
|
|
|
class UserTest(TestCaseWithCeleryTasks):
|
2015-01-31 21:48:07 +01:00
|
|
|
def setUp(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
self.customer = Customer.objects.create_user("test")
|
2015-01-31 21:48:07 +01:00
|
|
|
super(UserTest, self).setUp()
|
2014-06-01 14:51:33 +02:00
|
|
|
|
|
|
|
def test___str__(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(str(user), "test01 (10000)")
|
2014-06-01 14:51:33 +02:00
|
|
|
|
|
|
|
def test_set_password(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertFalse(sha512_crypt.verify("test", user.shadow.passwd))
|
|
|
|
user.set_password("test")
|
|
|
|
self.assertTrue(sha512_crypt.verify("test", user.shadow.passwd))
|
2014-06-01 15:26:01 +02:00
|
|
|
|
|
|
|
def test_save(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2014-06-01 15:26:01 +02:00
|
|
|
user.save()
|
2015-01-31 21:48:07 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(len(taskres), 3)
|
|
|
|
creators = [r.creator for r in taskres]
|
|
|
|
for task in [
|
2019-01-30 21:27:25 +01:00
|
|
|
"handle_group_created",
|
|
|
|
"handle_user_created",
|
|
|
|
"handle_user_password_set",
|
|
|
|
]:
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertIn(task, creators)
|
2014-06-01 15:26:01 +02:00
|
|
|
|
|
|
|
def test_delete_only_user(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2014-06-01 15:26:01 +02:00
|
|
|
user.delete()
|
2015-01-31 21:48:07 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(len(taskres), 6)
|
|
|
|
creators = [r.creator for r in taskres]
|
|
|
|
for task in [
|
2019-01-30 21:27:25 +01:00
|
|
|
"handle_group_created",
|
|
|
|
"handle_user_created",
|
|
|
|
"handle_user_password_set",
|
|
|
|
"handle_user_deleted",
|
|
|
|
"handle_group_deleted",
|
|
|
|
"handle_user_deleted",
|
|
|
|
]:
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertIn(task, creators)
|
2014-06-01 15:26:01 +02:00
|
|
|
self.assertEqual(len(User.objects.all()), 0)
|
|
|
|
|
|
|
|
def test_delete_additional_groups(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
group1 = Group.objects.create(gid=2000, groupname="group1")
|
|
|
|
group2 = Group.objects.create(gid=2001, groupname="group2")
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2014-06-01 15:26:01 +02:00
|
|
|
for group in [group1, group2]:
|
2019-01-30 21:27:25 +01:00
|
|
|
# noinspection PyUnresolvedReferences
|
2014-06-01 15:26:01 +02:00
|
|
|
user.additionalgroup_set.add(
|
2019-01-30 21:27:25 +01:00
|
|
|
AdditionalGroup.objects.create(user=user, group=group)
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
TaskResult.objects.all().delete()
|
2014-06-01 15:26:01 +02:00
|
|
|
user.delete()
|
2015-01-31 21:48:07 +01:00
|
|
|
taskres = TaskResult.objects.all()
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(len(taskres), 5)
|
|
|
|
creators = [t.creator for t in taskres]
|
|
|
|
for tcount, tcreator in [
|
2019-01-30 21:27:25 +01:00
|
|
|
(2, "handle_user_removed_from_group"),
|
|
|
|
(2, "handle_user_deleted"),
|
|
|
|
(1, "handle_group_deleted"),
|
|
|
|
]:
|
2015-10-12 00:23:31 +02:00
|
|
|
self.assertEqual(creators.count(tcreator), tcount)
|
2014-06-01 15:26:01 +02:00
|
|
|
self.assertEqual(len(User.objects.all()), 0)
|
2019-01-30 21:27:25 +01:00
|
|
|
# noinspection PyUnresolvedReferences
|
2014-06-01 15:26:01 +02:00
|
|
|
self.assertEqual(len(AdditionalGroup.objects.all()), 0)
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test_is_sftp_user(self):
|
|
|
|
user = User.objects.create_user(self.customer)
|
|
|
|
self.assertFalse(user.is_sftp_user())
|
|
|
|
|
|
|
|
sftp_group = Group.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
gid=2000, groupname=settings.OSUSER_SFTP_GROUP
|
|
|
|
)
|
|
|
|
# noinspection PyUnresolvedReferences
|
2015-01-31 21:48:07 +01:00
|
|
|
user.additionalgroup_set.add(
|
2019-01-30 21:27:25 +01:00
|
|
|
AdditionalGroup.objects.create(user=user, group=sftp_group)
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertTrue(user.is_sftp_user())
|
|
|
|
|
|
|
|
|
|
|
|
class SshPublicKeyManagerTest(TestCaseWithCeleryTasks):
|
|
|
|
def test_parse_keytext_rfc4716_1(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_1_RFC4716)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
|
|
|
self.assertGreater(len(res[1]), 40)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-rsa")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(
|
2019-01-30 21:27:25 +01:00
|
|
|
res[2], '"1024-bit RSA, converted from OpenSSH by me@example.com"'
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test_parse_keytext_rfc4716_2(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_2_RFC4716)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-dss")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
|
|
|
self.assertEqual(
|
2019-01-30 21:27:25 +01:00
|
|
|
res[2], "This is my public key for use on servers which I don't like."
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test_parse_keytext_rfc4716_3(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_3_RFC4716)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-dss")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
|
|
|
self.assertEqual(res[2], "DSA Public Key for use with MyIsp")
|
|
|
|
|
|
|
|
def test_parse_keytext_openssh(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_4_OPENSSH)
|
2023-02-18 22:46:48 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-rsa")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[2], "")
|
2015-01-31 21:48:07 +01:00
|
|
|
|
2015-12-06 17:47:27 +01:00
|
|
|
def test_parse_keytext_invalid_multiline(self):
|
2015-01-31 21:48:07 +01:00
|
|
|
with self.assertRaises(ValueError):
|
2019-01-30 21:27:25 +01:00
|
|
|
SshPublicKey.objects.parse_key_text("\r\n".join(["xx"] * 10))
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test_parse_keytext_empty_line(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_6_RFC4716_EMPTY_LINE)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-dss")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
|
|
|
self.assertEqual(res[2], "DSA Public Key for use with MyIsp")
|
|
|
|
|
2015-12-06 17:47:27 +01:00
|
|
|
def test_parse_keytext_invalid_empty_rfc4716_header(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2019-01-30 21:27:25 +01:00
|
|
|
SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_9_RFC4716_ONLY_HEADER)
|
2015-12-06 17:47:27 +01:00
|
|
|
|
|
|
|
def test_parse_keytext_no_comment(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_7_NO_COMMENT)
|
2015-12-06 17:47:27 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-rsa")
|
2015-12-06 17:47:27 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[2], "")
|
2015-12-06 17:47:27 +01:00
|
|
|
|
2015-01-31 21:48:07 +01:00
|
|
|
def test_parse_keytext_multiline_comment(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
res = SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_5_RFC4716_MULTILINE)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(len(res), 3)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(res[0], "ssh-dss")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertGreater(len(res[1]), 40)
|
|
|
|
self.assertEqual(res[2], "DSA Public Key for use with MyIsp")
|
|
|
|
|
2015-12-06 17:47:27 +01:00
|
|
|
def test_parse_keytext_invalid(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2019-01-30 21:27:25 +01:00
|
|
|
SshPublicKey.objects.parse_key_text("invalid")
|
2015-12-06 17:47:27 +01:00
|
|
|
|
|
|
|
def test_parse_keytext_invalid_openssh(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2019-01-30 21:27:25 +01:00
|
|
|
SshPublicKey.objects.parse_key_text(EXAMPLE_KEY_8_OPENSSH_BROKEN)
|
2015-12-06 17:47:27 +01:00
|
|
|
|
2015-01-31 21:48:07 +01:00
|
|
|
def test_create_ssh_public_key(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
customer = Customer.objects.create_user("test")
|
2015-01-31 21:48:07 +01:00
|
|
|
user = User.objects.create_user(customer)
|
2019-01-30 21:27:25 +01:00
|
|
|
key = SshPublicKey.objects.create_ssh_public_key(user, EXAMPLE_KEY_4_OPENSSH)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertIsInstance(key, SshPublicKey)
|
|
|
|
self.assertEqual(key.user, user)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(key.algorithm, "ssh-rsa")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(key.data, EXAMPLE_KEY_4_OPENSSH.split()[1])
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(key.comment, "")
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SshPublicKeyTest(TestCaseWithCeleryTasks):
|
|
|
|
def setUp(self):
|
|
|
|
super(SshPublicKeyTest, self).setUp()
|
2019-01-30 21:27:25 +01:00
|
|
|
customer = Customer.objects.create_user("test")
|
2015-01-31 21:48:07 +01:00
|
|
|
self.user = User.objects.create_user(customer)
|
2015-01-31 23:00:33 +01:00
|
|
|
TaskResult.objects.all().delete()
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test__str__rfc4716(self):
|
|
|
|
res = SshPublicKey.objects.create_ssh_public_key(
|
2019-01-30 21:27:25 +01:00
|
|
|
self.user, EXAMPLE_KEY_3_RFC4716
|
|
|
|
)
|
|
|
|
self.maxDiff = None
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(
|
2019-01-30 21:27:25 +01:00
|
|
|
str(res),
|
|
|
|
"ssh-dss AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxae"
|
|
|
|
"hvx5wOJ0rzZdzoSOXxbETW6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7St"
|
|
|
|
"xyltHnXF1YLfKD1G4T6JYrdHYI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3g"
|
|
|
|
"Jq2e7Yisk/gF+1VAAAAFQDb8D5cvwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4"
|
|
|
|
"KLYk3IwRbXblwXdkPggA4pfdtW9vGfJ0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/F"
|
|
|
|
"XPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAAvioUPkmdMc0zuWoSOEsSNhVDtX3WdvVc"
|
|
|
|
"GcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACBAN7CY+KKv1gHpRzFwdQm7HK9bb1LA"
|
|
|
|
"o2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HSn24VYtYtsMu74qXviYjziVucWK"
|
|
|
|
"jjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5sY29ouezv4Xz2PuMch5VGPP"
|
|
|
|
"+CDqzCM4loWgV DSA Public Key for use with MyIsp",
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
|
|
|
|
def test__str__openssh(self):
|
|
|
|
res = SshPublicKey.objects.create_ssh_public_key(
|
2019-01-30 21:27:25 +01:00
|
|
|
self.user, EXAMPLE_KEY_4_OPENSSH
|
|
|
|
)
|
2015-01-31 21:48:07 +01:00
|
|
|
self.assertEqual(str(res), EXAMPLE_KEY_4_OPENSSH)
|
2015-01-31 23:00:33 +01:00
|
|
|
|
|
|
|
def test_call_tasks_on_save(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
SshPublicKey.objects.create_ssh_public_key(self.user, EXAMPLE_KEY_4_OPENSSH)
|
2015-01-31 23:00:33 +01:00
|
|
|
taskresults = TaskResult.objects.all()
|
|
|
|
self.assertEqual(len(taskresults), 1)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(taskresults[0].creator, "handle_ssh_keys_changed")
|
2015-01-31 23:00:33 +01:00
|
|
|
|
|
|
|
def test_call_tasks_on_delete(self):
|
|
|
|
key = SshPublicKey.objects.create_ssh_public_key(
|
2019-01-30 21:27:25 +01:00
|
|
|
self.user, EXAMPLE_KEY_4_OPENSSH
|
|
|
|
)
|
2015-01-31 23:00:33 +01:00
|
|
|
TaskResult.objects.all().delete()
|
|
|
|
key.delete()
|
|
|
|
taskresults = TaskResult.objects.all()
|
|
|
|
self.assertEqual(len(taskresults), 1)
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual(taskresults[0].creator, "handle_ssh_keys_changed")
|