Esempio n. 1
0
 def test_duplicate(self):
     content = 'root:x:0:0:root:/root:/bin/bash'
     content2 = 'root:x:1:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     with self.assertRaises(KeyError):
         mngids.parse(content2, arr)
Esempio n. 2
0
 def test_duplicate(self):
     content = 'root:x:0:0:root:/root:/bin/bash'
     content2 = 'root:x:1:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     with self.assertRaises(KeyError):
         mngids.parse(content2, arr)
Esempio n. 3
0
 def test_parsecmdline_addgroup_non_exist(self):
     cmd = 'addgroup root'.split(' ')
     content = 'user:x:1000:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 4
0
 def test_parsecmdline_addgroup_without_name(self):
     cmd = 'addgroup -g 1000 -b /root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 5
0
    def test_parsecmdline_find_gu_name(self):
        # Be sure parse_cmdline is able to find username or groupname
        passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
        group = 'cloud-users:x:1000:'
        uids = {}
        gids = {}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)

        cmd = [
            'useradd', 'jenkins', '--shell', '/bin/bash', '--gid',
            'cloud-users', '--comment', 'eNovance Jenkins User', '-m'
        ]
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[7], '1000')

        cmd = [
            'useradd', '--shell', '/bin/bash', '--gid', 'cloud-users',
            '--comment', 'eNovance Jenkins User', '-m', 'jenkins'
        ]
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')

        cmd = [
            'useradd', '--shell', '/bin/bash', '--gid', 'cloud-users',
            'jenkins', '--comment', 'eNovance Jenkins User', '-m'
        ]
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')

        cmd = ['groupadd', 'cloud-users']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        # 1010 is replaced by what we have in gids (usually provided in ids.tables
        cmd = ['groupadd', '--gid', '1010', 'cloud-users', '-o']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        cmd = ['groupadd', '--gid', '1010', '-f', 'cloud-users', '-o']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        cmd = [
            'useradd', '--shell', '/bin/bash', '--gid', 'cloud-users', '-f',
            '10', 'jenkins', '--comment', 'eNovance Jenkins User', '-m'
        ]
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')
Esempio n. 6
0
 def test_parsecmdline_addgroup_with_missing_arg_value(self):
     cmd = 'groupadd --gid root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 7
0
 def test_parsecmdline_addgroup_with_missing_arg_value(self):
     cmd = 'groupadd --gid root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 8
0
 def test_parsecmdline_addgroup_without_name(self):
     cmd = 'addgroup -g 1000 -b /root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 9
0
 def test_parsecmdline_addgroup_non_exist(self):
     cmd = 'addgroup root'.split(' ')
     content = 'user:x:1000:'
     gids = {}
     mngids.parse(content, gids)
     with self.assertRaises(KeyError):
         mngids.parse_cmdline(cmd, {}, gids)
Esempio n. 10
0
 def test_parsecmdline_addgroup_path(self):
     cmd = './addgroup root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids, True)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1')
Esempio n. 11
0
 def test_parsecmdline_addgroup_non_exist(self):
     cmd = 'addgroup root'.split(' ')
     content = 'user:x:1000:'
     gids = {}
     mngids.parse(content, gids)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1001')
Esempio n. 12
0
 def test_parsecmdline_addgroup_non_exist(self):
     cmd = 'addgroup root'.split(' ')
     content = 'user:x:1000:'
     gids = {}
     mngids.parse(content, gids)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1001')
Esempio n. 13
0
 def test_parsecmdline_addgroup_path(self):
     cmd = './addgroup root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids, True)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1')
Esempio n. 14
0
 def test_parsecmdline_addgroup_noaction(self):
     cmd = 'addgroup --gid 2 root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids, True)
     l = len(cmd)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(len(cmd), l)
     self.assertEquals(cmd[2], '1')
Esempio n. 15
0
 def test_parsecmdline_addgroup_noaction(self):
     cmd = 'addgroup --gid 2 root'.split(' ')
     content = 'root:x:1:'
     gids = {}
     mngids.parse(content, gids, True)
     l = len(cmd)
     mngids.parse_cmdline(cmd, {}, gids)
     self.assertEquals(len(cmd), l)
     self.assertEquals(cmd[2], '1')
Esempio n. 16
0
    def test_parsecmdline_find_gu_name(self):
        # Be sure parse_cmdline is able to find username or groupname
        passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
        group = 'cloud-users:x:1000:'
        uids = {}
        gids = {}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)

        cmd = ['useradd', 'jenkins', '--shell', '/bin/bash',
               '--gid', 'cloud-users',
               '--comment', 'eNovance Jenkins User', '-m']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[7], '1000')

        cmd = ['useradd', '--shell', '/bin/bash',
               '--gid', 'cloud-users',
               '--comment', 'eNovance Jenkins User', '-m', 'jenkins']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')

        cmd = ['useradd', '--shell', '/bin/bash',
               '--gid', 'cloud-users', 'jenkins',
               '--comment', 'eNovance Jenkins User', '-m']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')

        cmd = ['groupadd', 'cloud-users']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        # 1010 is replaced by what we have in gids (usually provided in ids.tables
        cmd = ['groupadd', '--gid', '1010', 'cloud-users', '-o']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        cmd = ['groupadd', '--gid', '1010', '-f', 'cloud-users', '-o']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1000')

        cmd = ['useradd', '--shell', '/bin/bash',
               '--gid', 'cloud-users', '-f', '10', 'jenkins',
               '--comment', 'eNovance Jenkins User', '-m']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1000')
        self.assertEquals(cmd[6], '1000')
Esempio n. 17
0
 def test_parsecmdline(self):
     cmd = 'adduser root'.split(' ')
     content = 'root:x:0:1:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     mngids.parse_cmdline(cmd, uids, {})
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[3], '--gid')
     self.assertEquals(cmd[4], '1')
Esempio n. 18
0
 def test_parsecmdline(self):
     cmd = 'adduser root'.split(' ')
     content = 'root:x:0:1:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     mngids.parse_cmdline(cmd, uids, {})
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[3], '--gid')
     self.assertEquals(cmd[4], '1')
Esempio n. 19
0
 def test_parsecmdline(self):
     cmd = 'adduser root'.split(' ')
     content = 'root:x:0:0:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     orig = mngids.call_addgroup
     mngids.call_addgroup = lambda x: x
     mngids.parse_cmdline(cmd, uids, {})
     mngids.call_addgroup = orig
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
Esempio n. 20
0
 def test_parsecmdline(self):
     cmd = 'adduser root'.split(' ')
     content = 'root:x:0:0:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     orig = mngids.call_addgroup
     mngids.call_addgroup = lambda x: x
     mngids.parse_cmdline(cmd, uids, {})
     mngids.call_addgroup = orig
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
Esempio n. 21
0
 def test_parsecmdline_noaction1(self):
     cmd = 'adduser --uid 2 root'.split(' ')
     l = len(cmd)
     content = 'root:x:0:1:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     mngids.parse_cmdline(cmd, uids, {})
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1')
     self.assertEquals(cmd[4], '0')
     self.assertEquals(len(cmd), l + 2)
Esempio n. 22
0
 def test_parsecmdline_noaction1(self):
     cmd = 'adduser --uid 2 root'.split(' ')
     l = len(cmd)
     content = 'root:x:0:1:root:/root:/bin/bash'
     uids = {}
     mngids.parse(content, uids)
     mngids.parse_cmdline(cmd, uids, {})
     self.assertEquals(cmd[1], '--gid')
     self.assertEquals(cmd[2], '1')
     self.assertEquals(cmd[4], '0')
     self.assertEquals(len(cmd), l + 2)
Esempio n. 23
0
 def test_parsecmdline_group(self):
     cmd = 'adduser --gid nogroup root'.split(' ')
     passwd = 'root:x:0:1:root:/root:/bin/bash'
     group = 'nogroup:x:65534:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[3], '--gid')
     self.assertEquals(cmd[4], '65534')
Esempio n. 24
0
 def test_parsecmdline_group(self):
     cmd = 'adduser --gid nogroup root'.split(' ')
     passwd = 'root:x:0:1:root:/root:/bin/bash'
     group = 'nogroup:x:65534:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[3], '--gid')
     self.assertEquals(cmd[4], '65534')
Esempio n. 25
0
 def test_parsecmdline_noaction(self):
     cmd = 'adduser --gid root root'.split(' ')
     l = len(cmd)
     passwd = 'root:x:0:1:root:/root:/bin/bash'
     group = 'root:x:1:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[4], '1')
     self.assertEquals(len(cmd), l + 2)
Esempio n. 26
0
 def test_parsecmdline_wrong_order(self):
     cmd = ['useradd', 'jenkins', '--shell', '/bin/bash',
            '--gid', 'cloud-users',
            '--comment', 'eNovance Jenkins User', '-m']
     passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
     group = 'cloud-users:x:1000:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '1000')
     self.assertEquals(cmd[7], '1000')
Esempio n. 27
0
 def test_parsecmdline_noaction(self):
     cmd = 'adduser --gid root root'.split(' ')
     l = len(cmd)
     passwd = 'root:x:0:1:root:/root:/bin/bash'
     group = 'root:x:1:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '0')
     self.assertEquals(cmd[4], '1')
     self.assertEquals(len(cmd), l + 2)
Esempio n. 28
0
 def test_parsecmdline_wrong_order(self):
     cmd = [
         'useradd', 'jenkins', '--shell', '/bin/bash', '--gid',
         'cloud-users', '--comment', 'eNovance Jenkins User', '-m'
     ]
     passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
     group = 'cloud-users:x:1000:'
     uids = {}
     gids = {}
     mngids.parse(passwd, uids)
     mngids.parse(group, gids, True)
     mngids.parse_cmdline(cmd, uids, gids)
     self.assertEquals(cmd[1], '--uid')
     self.assertEquals(cmd[2], '1000')
     self.assertEquals(cmd[7], '1000')
Esempio n. 29
0
    def test_calls(self):
        passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
        group = 'jenkins:x:1000:'
        uids = {'john': ('1001', '1001')}
        gids = {'john': ('1001', '')}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)

        cmd = ['useradd', 'john']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1001')

        cmd = ['useradd', 'john', '-u', '1001']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1001')
        self.assertEquals(cmd[4], '-u')
        self.assertEquals(cmd[5], '1001')

        cmd = ['useradd', 'john', '-u', '1001', '-g', '1001']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[2], '-u')
        self.assertEquals(cmd[3], '1001')
        self.assertEquals(cmd[4], '-g')
        self.assertEquals(cmd[5], '1001')

        cmd = ['useradd', 'john', '-u', '1001', '-g', '1002']
        with self.assertRaises(KeyError):
            # KeyError: "mngids.py: 1002 not found (--gid) in [('1000', ''), ('1001', '')]"
            mngids.parse_cmdline(cmd, uids, gids)

        uids = {'john': ('1001', '1002')}
        gids = {'john': ('1002', '')}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)
        cmd = ['useradd', 'john', '-u', '1001']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1002')
        self.assertEquals(cmd[4], '-u')
        self.assertEquals(cmd[5], '1001')
Esempio n. 30
0
    def test_calls(self):
        passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'
        group = 'jenkins:x:1000:'
        uids = {'john': ('1001', '1001')}
        gids = {'john': ('1001', '')}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)

        cmd = ['useradd', 'john']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--uid')
        self.assertEquals(cmd[2], '1001')

        cmd = ['useradd', 'john', '-u', '1001']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1001')
        self.assertEquals(cmd[4], '-u')
        self.assertEquals(cmd[5], '1001')

        cmd = ['useradd', 'john', '-u', '1001', '-g', '1001']
        mngids.parse_cmdline(cmd, uids, gids)
        self.assertEquals(cmd[2], '-u')
        self.assertEquals(cmd[3], '1001')
        self.assertEquals(cmd[4], '-g')
        self.assertEquals(cmd[5], '1001')

        cmd = ['useradd', 'john', '-u', '1001', '-g', '1002']
        with self.assertRaises(KeyError):
            # KeyError: "mngids.py: 1002 not found (--gid) in [('1000', ''), ('1001', '')]"
            mngids.parse_cmdline(cmd, uids, gids)

        uids = {'john': ('1001', '1002')}
        gids = {'john': ('1002', '')}
        mngids.parse(passwd, uids)
        mngids.parse(group, gids, True)
        cmd = ['useradd', 'john', '-u', '1001']
        orig = mngids.call_addgroup
        mngids.call_addgroup = lambda x: x
        mngids.parse_cmdline(cmd, uids, gids)
        mngids.call_addgroup = orig
        self.assertEquals(cmd[1], '--gid')
        self.assertEquals(cmd[2], '1002')
        self.assertEquals(cmd[4], '-u')
        self.assertEquals(cmd[5], '1001')
Esempio n. 31
0
 def test_comment(self):
     content = '#root:x:0:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     self.assertEquals(arr, {})
Esempio n. 32
0
 def test_parse_group(self):
     arr = {}
     mngids.parse(GROUP, arr, True)
     self.assertEquals(arr['root'], ('0', ''))
Esempio n. 33
0
 def test_parse(self):
     content = 'root:x:0:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     self.assertEquals(arr['root'], ('0', '0'))
Esempio n. 34
0
 def test_parse(self):
     content = 'root:x:0:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     self.assertEquals(arr['root'], ('0', '0'))
Esempio n. 35
0
 def test_comment(self):
     content = '#root:x:0:0:root:/root:/bin/bash'
     arr = {}
     mngids.parse(content, arr)
     self.assertEquals(arr, {})
Esempio n. 36
0
 def test_parse_group(self):
     arr = {}
     mngids.parse(GROUP, arr, True)
     self.assertEquals(arr['root'], ('0', ''))