This file is indexed.

/usr/lib/python2.7/dist-packages/nss_cache/maps/shadow_test.py is in nsscache 0.33-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""Unit tests for shadow.py.

We only test what is overridden in the shadow subclasses, most
functionality is in base.py and tested in passwd_test.py since a
subclass is required to test the abstract class functionality.
"""

__author__ = 'vasilios@google.com (Vasilios Hoffman)'

import unittest

from nss_cache.maps import passwd
from nss_cache.maps import shadow


class TestShadowMap(unittest.TestCase):
  """Tests for the ShadowMap class."""

  def __init__(self, obj):
    """Set some default avalible data for testing."""
    super(TestShadowMap, self).__init__(obj)
    self._good_entry = shadow.ShadowMapEntry()
    self._good_entry.name = 'foo'
    self._good_entry.lstchg = None
    self._good_entry.min = None
    self._good_entry.max = None
    self._good_entry.warn = None
    self._good_entry.inact = None
    self._good_entry.expire = None
    self._good_entry.flag = None
    
  def testInit(self):
    """Construct an empty or seeded ShadowMap."""
    self.assertEquals(shadow.ShadowMap, type(shadow.ShadowMap()),
                      msg='failed to create emtpy ShadowMap')
    smap = shadow.ShadowMap([self._good_entry])
    self.assertEquals(self._good_entry, smap.PopItem(),
                      msg='failed to seed ShadowMap with list')
    self.assertRaises(TypeError, shadow.ShadowMap, ['string'])
    
  def testAdd(self):
    """Add throws an error for objects it can't verify."""
    smap = shadow.ShadowMap()
    entry = self._good_entry
    self.assert_(smap.Add(entry), msg='failed to append new entry.')

    self.assertEquals(1, len(smap), msg='unexpected size for Map.')
        
    ret_entry = smap.PopItem()
    self.assertEquals(ret_entry, entry, msg='failed to pop existing entry.')

    pentry = passwd.PasswdMapEntry()
    pentry.name = 'foo'
    pentry.uid = 10
    pentry.gid = 10
    self.assertRaises(TypeError, smap.Add, pentry)


class TestShadowMapEntry(unittest.TestCase):
  """Tests for the ShadowMapEntry class."""
    
  def testInit(self):
    """Construct empty and seeded ShadowMapEntry."""
    self.assert_(shadow.ShadowMapEntry(),
                 msg='Could not create empty ShadowMapEntry')
    seed = {'name': 'foo'}
    entry = shadow.ShadowMapEntry(seed)
    self.assert_(entry.Verify(),
                 msg='Could not verify seeded ShadowMapEntry')
    self.assertEquals(entry.name, 'foo',
                      msg='Entry returned wrong value for name')
    self.assertEquals(entry.passwd, '!!',
                      msg='Entry returned wrong value for passwd')
    self.assertEquals(entry.lstchg, None,
                      msg='Entry returned wrong value for lstchg')
    self.assertEquals(entry.min, None,
                      msg='Entry returned wrong value for min')
    self.assertEquals(entry.max, None,
                      msg='Entry returned wrong value for max')
    self.assertEquals(entry.warn, None,
                      msg='Entry returned wrong value for warn')
    self.assertEquals(entry.inact, None,
                      msg='Entry returned wrong value for inact')
    self.assertEquals(entry.expire, None,
                      msg='Entry returned wrong value for expire')
    self.assertEquals(entry.flag, None,
                      msg='Entry returned wrong value for flag')

  def testAttributes(self):
    """Test that we can get and set all expected attributes."""
    entry = shadow.ShadowMapEntry()
    entry.name = 'foo'
    self.assertEquals(entry.name, 'foo',
                      msg='Could not set attribute: name')
    entry.passwd = 'seekret'
    self.assertEquals(entry.passwd, 'seekret',
                      msg='Could not set attribute: passwd')
    entry.lstchg = 0
    self.assertEquals(entry.lstchg, 0,
                      msg='Could not set attribute: lstchg')
    entry.min = 0
    self.assertEquals(entry.min, 0,
                      msg='Could not set attribute: min')
    entry.max = 0
    self.assertEquals(entry.max, 0,
                      msg='Could not set attribute: max')
    entry.warn = 0
    self.assertEquals(entry.warn, 0,
                      msg='Could not set attribute: warn')
    entry.inact = 0
    self.assertEquals(entry.inact, 0,
                      msg='Could not set attribute: inact')
    entry.expire = 0
    self.assertEquals(entry.expire, 0,
                      msg='Could not set attribute: expire')
    entry.flag = 0
    self.assertEquals(entry.flag, 0,
                      msg='Could not set attribute: flag')

  def testVerify(self):
    """Test that the object can verify it's attributes and itself."""
    entry = shadow.ShadowMapEntry()
    
    # Emtpy object should bomb
    self.failIf(entry.Verify())

  def testKey(self):
    """Key() should return the value of the 'name' attribute."""
    entry = shadow.ShadowMapEntry()
    entry.name = 'foo'
    self.assertEquals(entry.Key(), entry.name)


if __name__ == '__main__':
  unittest.main()