From 65a701e44b227ef19390980f6c93f36716cbd773 Mon Sep 17 00:00:00 2001 From: Carlos Nihelton Date: Tue, 10 May 2022 07:23:14 -0300 Subject: [PATCH] API Test for the username validation. --- subiquity/tests/api/test_api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index 09f5ff42..40527651 100755 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -1059,3 +1059,27 @@ class TestSource(TestAPI): search_drivers=False) resp = await inst.get('/source') self.assertFalse(resp['search_drivers']) + + +class TestIdentityValidation(TestAPI): + async def test_username_validation(self): + async with start_server('examples/simple.json') as inst: + resp = await inst.get('/identity/validate_username', + username='plugdev') + self.assertEqual(resp, 'SYSTEM_RESERVED') + + resp = await inst.get('/identity/validate_username', + username='lxd') + self.assertEqual(resp, 'ALREADY_IN_USE') + + resp = await inst.get('/identity/validate_username', + username='root') + self.assertNotEqual(resp, 'OK') + + resp = await inst.get('/identity/validate_username', + username='r'*33) + self.assertEqual(resp, 'TOO_LONG') + + resp = await inst.get('/identity/validate_username', + username='01root') + self.assertEqual(resp, 'INVALID_CHARS')