summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/testcases/base.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-04-03 11:52:06 -0400
committerScott Moser <smoser@brickies.net>2017-04-03 11:52:06 -0400
commit3b2e493b51153cd5bc1fa91e6ac52f59d41fe3fb (patch)
tree678b118605245e5bb1b218565728270702aba5b4 /tests/cloud_tests/testcases/base.py
parente018fa910fdf0dbf3aa22e59e935461babd205c4 (diff)
parent61eb03fef92f435434d974fb46439189ef0b5f97 (diff)
downloadvyos-cloud-init-3b2e493b51153cd5bc1fa91e6ac52f59d41fe3fb.tar.gz
vyos-cloud-init-3b2e493b51153cd5bc1fa91e6ac52f59d41fe3fb.zip
merge from master at 0.7.9-90-g61eb03fe
Diffstat (limited to 'tests/cloud_tests/testcases/base.py')
-rw-r--r--tests/cloud_tests/testcases/base.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/cloud_tests/testcases/base.py b/tests/cloud_tests/testcases/base.py
index 5395b9a3..64d5507a 100644
--- a/tests/cloud_tests/testcases/base.py
+++ b/tests/cloud_tests/testcases/base.py
@@ -2,6 +2,7 @@
from cloudinit import util as c_util
+import crypt
import json
import unittest
@@ -14,6 +15,9 @@ class CloudTestCase(unittest.TestCase):
conf = None
_cloud_config = None
+ def shortDescription(self):
+ return None
+
@property
def cloud_config(self):
"""
@@ -78,4 +82,56 @@ class CloudTestCase(unittest.TestCase):
result = self.get_status_data(self.get_data_file('result.json'))
self.assertEqual(len(result['errors']), 0)
+
+class PasswordListTest(CloudTestCase):
+ def test_shadow_passwords(self):
+ shadow = self.get_data_file('shadow')
+ users = {}
+ dupes = []
+ for line in shadow.splitlines():
+ user, encpw = line.split(":")[0:2]
+ if user in users:
+ dupes.append(user)
+ users[user] = encpw
+
+ jane_enc = "$5$iW$XsxmWCdpwIW8Yhv.Jn/R3uk6A4UaicfW5Xp7C9p9pg."
+ self.assertEqual([], dupes)
+ self.assertEqual(jane_enc, users['jane'])
+
+ mikey_enc = "$5$xZ$B2YGGEx2AOf4PeW48KC6.QyT1W2B4rZ9Qbltudtha89"
+ self.assertEqual(mikey_enc, users['mikey'])
+
+ # shadow entry is $N$salt$, so we encrypt with the same format
+ # and salt and expect the result.
+ tom = "mypassword123!"
+ fmtsalt = users['tom'][0:users['tom'].rfind("$") + 1]
+ tom_enc = crypt.crypt(tom, fmtsalt)
+ self.assertEqual(tom_enc, users['tom'])
+
+ harry_enc = ("$6$LF$9Z2p6rWK6TNC1DC6393ec0As.18KRAvKDbfsG"
+ "JEdWN3sRQRwpdfoh37EQ3yUh69tP4GSrGW5XKHxMLiKowJgm/")
+ dick_enc = "$1$ssisyfpf$YqvuJLfrrW6Cg/l53Pi1n1"
+
+ # these should have been changed to random values.
+ self.assertNotEqual(harry_enc, users['harry'])
+ self.assertTrue(users['harry'].startswith("$"))
+ self.assertNotEqual(dick_enc, users['dick'])
+ self.assertTrue(users['dick'].startswith("$"))
+
+ self.assertNotEqual(users['harry'], users['dick'])
+
+ def test_shadow_expected_users(self):
+ """Test every tom, dick, and harry user in shadow"""
+ out = self.get_data_file('shadow')
+ self.assertIn('tom:', out)
+ self.assertIn('dick:', out)
+ self.assertIn('harry:', out)
+ self.assertIn('jane:', out)
+ self.assertIn('mikey:', out)
+
+ def test_sshd_config(self):
+ """Test sshd config allows passwords"""
+ out = self.get_data_file('sshd_config')
+ self.assertIn('PasswordAuthentication yes', out)
+
# vi: ts=4 expandtab