コード例 #1
0
 def testInit(self):
     """Construct an empty and seeded NetgroupMapEntry."""
     self.assertTrue(netgroup.NetgroupMapEntry(),
                     msg='Could not create empty NetgroupMapEntry')
     entries = ['bar', ('baz', '-', None)]
     seed = {'name': 'foo', 'entries': entries}
     entry = netgroup.NetgroupMapEntry(seed)
     self.assertTrue(entry.Verify(),
                     msg='Could not verify seeded NetgroupMapEntry')
     self.assertEqual(entry.name,
                      'foo',
                      msg='Entry returned wrong value for name')
     self.assertEqual(entry.entries,
                      entries,
                      msg='Entry returned wrong value for entries')
コード例 #2
0
 def testAttributes(self):
     """Test that we can get and set all expected attributes."""
     entry = netgroup.NetgroupMapEntry()
     entry.name = 'foo'
     self.assertEqual(entry.name,
                      'foo',
                      msg='Could not set attribute: name')
     entries = ['foo', '(-,bar,)']
     entry.entries = entries
     self.assertEqual(entry.entries,
                      entries,
                      msg='Could not set attribute: entries')
コード例 #3
0
    def testWriteNetgroupEntry(self):
        """We correctly write a typical entry in /etc/netgroup format."""
        cache = files.FilesNetgroupMapHandler(self.config)
        file_mock = self.mox.CreateMock(sys.stdout)
        file_mock.write(
            'administrators unix_admins noc_monkeys (-,zero_cool,)\n')

        map_entry = netgroup.NetgroupMapEntry()
        map_entry.name = 'administrators'
        map_entry.entries = 'unix_admins noc_monkeys (-,zero_cool,)'

        self.mox.ReplayAll()

        cache._WriteData(file_mock, map_entry)
コード例 #4
0
ファイル: ldapsource.py プロジェクト: 3c2b2ff5/nsscache
    def Transform(self, obj):
        """Transforms an LDAP nisNetgroup object into a netgroup(5) entry."""
        netgroup_ent = netgroup.NetgroupMapEntry()
        netgroup_ent.name = obj['cn'][0]

        entries = set()
        if 'memberNisNetgroup' in obj:
            entries.update(obj['memberNisNetgroup'])
        if 'nisNetgroupTriple' in obj:
            entries.update(obj['nisNetgroupTriple'])

        # final data is stored as a string in the object
        netgroup_ent.entries = ' '.join(sorted(entries))

        return netgroup_ent
コード例 #5
0
ファイル: file_formats.py プロジェクト: thnitendra/nsscache
    def _ReadEntry(self, line):
        """Return a NetgroupMapEntry from a record in the target cache."""
        map_entry = netgroup.NetgroupMapEntry()

        # the first word is our name, but since the whole line is space delimited
        # avoid .split(' ') since groups can have thousands of members.
        index = line.find(' ')

        if index == -1:
            if line:
                # empty group is OK, as long as the line isn't blank
                map_entry.name = line
                return map_entry
            raise RuntimeError('Failed to parse entry: %s' % line)

        map_entry.name = line[0:index]

        # the rest is our entries, and for better or for worse this preserves extra
        # leading spaces
        map_entry.entries = line[index + 1:]

        return map_entry
コード例 #6
0
    def testVerify(self):
        """Test that the object can verify it's attributes and itself."""
        entry = netgroup.NetgroupMapEntry()

        # Empty object should bomb
        self.assertFalse(entry.Verify())
コード例 #7
0
 def __init__(self, obj):
     """Set some default avalible data for testing."""
     super(TestNetgroupMap, self).__init__(obj)
     self._good_entry = netgroup.NetgroupMapEntry()
     self._good_entry.name = 'foo'
     self._good_entry.entries = [('-', 'bob', None), 'othernetgroup']
コード例 #8
0
 def testKey(self):
     """Key() should return the value of the 'name' attribute."""
     entry = netgroup.NetgroupMapEntry()
     entry.name = 'foo'
     self.assertEqual(entry.Key(), entry.name)