Exemple #1
0
    def testUpdateMapsTrapsPermissionDenied(self):
        self.mox.StubOutWithMock(map_updater.MapUpdater, 'UpdateFromSource')
        map_updater.MapUpdater.UpdateFromSource(mox.IgnoreArg(),
                                                incremental=True,
                                                force_write=False).AndRaise(
                                                    error.PermissionDenied)

        self.mox.StubOutClassWithMocks(lock, 'PidFile')
        lock_mock = lock.PidFile(filename=None)
        lock_mock.Lock(force=False).AndReturn(True)
        lock_mock.Locked().AndReturn(True)
        lock_mock.Unlock()

        self.conf.maps = [config.MAP_PASSWORD]
        self.conf.cache = 'dummy'
        modify_stamp = 1
        map_entry = passwd.PasswdMapEntry({'name': 'foo', 'uid': 10, 'gid': 10})
        passwd_map = passwd.PasswdMap([map_entry])
        passwd_map.SetModifyTimestamp(modify_stamp)

        source_mock = self.mox.CreateMock(source.Source)

        self.mox.StubOutWithMock(source_factory, 'Create')
        source_factory.Create(self.conf.options[
            config.MAP_PASSWORD].source).AndReturn(source_mock)

        cache_mock = self.mox.CreateMock(caches.Cache)

        self.mox.StubOutWithMock(cache_factory, 'Create')

        self.mox.ReplayAll()

        c = command.Update()
        self.assertEqual(
            1, c.UpdateMaps(self.conf, incremental=True, force_write=False))
Exemple #2
0
    def testUpdateSingleMaps(self):
        self.mox.StubOutClassWithMocks(lock, 'PidFile')
        lock_mock = lock.PidFile(filename=None)
        lock_mock.Lock(force=False).AndReturn(True)
        lock_mock.Locked().AndReturn(True)
        lock_mock.Unlock()

        self.conf.maps = [config.MAP_PASSWORD]
        self.conf.cache = 'dummy'

        modify_stamp = 1
        map_entry = passwd.PasswdMapEntry({'name': 'foo', 'uid': 10, 'gid': 10})
        passwd_map = passwd.PasswdMap([map_entry])
        passwd_map.SetModifyTimestamp(modify_stamp)

        source_mock = self.mox.CreateMock(source.Source)
        source_mock.GetMap(config.MAP_PASSWORD,
                           location=None).AndReturn(passwd_map)

        self.mox.StubOutWithMock(source_factory, 'Create')
        source_factory.Create(self.conf.options[
            config.MAP_PASSWORD].source).AndReturn(source_mock)

        cache_mock = self.mox.CreateMock(caches.Cache)
        cache_mock.WriteMap(map_data=passwd_map).AndReturn(0)

        self.mox.StubOutWithMock(cache_factory, 'Create')
        cache_factory.Create(self.conf.options[config.MAP_PASSWORD].cache,
                             config.MAP_PASSWORD).AndReturn(cache_mock)

        self.mox.ReplayAll()
        c = command.Update()
        self.assertEqual(
            0, c.UpdateMaps(self.conf, incremental=True, force_write=False))
Exemple #3
0
 def testUpdateMapsWithBadMapName(self):
     c = command.Update()
     self.mox.StubOutWithMock(c, '_Lock')
     c._Lock(force=False, path=None).AndReturn(True)
     self.mox.ReplayAll()
     # Create an invalid map name.
     self.assertEqual(
         1, c.Run(self.conf, ['-m', config.MAP_PASSWORD + 'invalid']))
Exemple #4
0
 def testRunWithBadParameters(self):
     c = command.Update()
     # Trap stderr so the unit test runs clean,
     # since unit test status is printed on stderr.
     dev_null = StringIO.StringIO()
     stderr = sys.stderr
     sys.stderr = dev_null
     self.assertEquals(2, c.Run(None, ['--invalid']))
     sys.stderr = stderr
Exemple #5
0
    def testForceLockFlagCallsUpdateMapsWithForceLockTrue(self):
        c = command.Update()

        self.mox.StubOutWithMock(c, 'UpdateMaps')
        c.UpdateMaps(self.conf,
                     incremental=mox.IgnoreArg(),
                     force_lock=True,
                     force_write=mox.IgnoreArg()).AndReturn(0)
        self.mox.ReplayAll()

        self.assertEqual(0, c.Run(self.conf, ['--force-lock']))
Exemple #6
0
    def testRunWithNoParameters(self):
        c = command.Update()

        self.mox.StubOutWithMock(c, 'UpdateMaps')
        c.UpdateMaps(self.conf,
                     incremental=True,
                     force_lock=False,
                     force_write=False).AndReturn(0)
        self.mox.ReplayAll()

        self.assertEquals(0, c.Run(self.conf, []))
Exemple #7
0
    def testUpdateMapsCanForceLock(self):
        self.mox.StubOutClassWithMocks(lock, 'PidFile')
        lock_mock = lock.PidFile(filename=None)
        lock_mock.Lock(force=True).AndReturn(False)
        lock_mock.Locked().AndReturn(True)
        lock_mock.Unlock()

        self.mox.ReplayAll()

        c = command.Update()
        self.assertEquals(c.UpdateMaps(self.conf, False, force_lock=True),
                          c.ERR_LOCK)
Exemple #8
0
    def testSleep(self):
        self.mox.StubOutWithMock(time, 'sleep')
        time.sleep(1)

        c = command.Update()
        self.mox.StubOutWithMock(c, 'UpdateMaps')
        c.UpdateMaps(self.conf,
                     incremental=True,
                     force_lock=mox.IgnoreArg(),
                     force_write=mox.IgnoreArg()).AndReturn(0)
        self.mox.ReplayAll()

        c.Run(self.conf, ['-s', '1'])
Exemple #9
0
    def testRunWithFlags(self):
        c = command.Update()

        self.mox.StubOutWithMock(c, 'UpdateMaps')
        c.UpdateMaps(self.conf,
                     incremental=False,
                     force_lock=True,
                     force_write=True).AndReturn(0)
        self.mox.ReplayAll()

        self.assertEqual(
            0,
            c.Run(self.conf, [
                '-m', config.MAP_PASSWORD, '-f', '--force-write', '--force-lock'
            ]))
        self.assertEqual(['passwd'], self.conf.maps)
Exemple #10
0
    def testUpdateAutomounts(self):
        self.mox.StubOutClassWithMocks(lock, 'PidFile')
        lock_mock = lock.PidFile(filename=None)
        lock_mock.Lock(force=False).AndReturn(True)
        lock_mock.Locked().AndReturn(True)
        lock_mock.Unlock()

        self.conf.maps = [config.MAP_AUTOMOUNT]
        self.conf.cache = 'dummy'

        modify_stamp = 1
        map_entry = automount.AutomountMapEntry()
        map_entry.key = '/home'
        map_entry.location = 'foo'
        automount_map = automount.AutomountMap([map_entry])
        automount_map.SetModifyTimestamp(modify_stamp)

        source_mock = self.mox.CreateMock(source.Source)
        source_mock.GetAutomountMasterMap().AndReturn(automount_map)
        source_mock.GetMap(config.MAP_AUTOMOUNT,
                           location='foo').AndReturn(automount_map)

        self.mox.StubOutWithMock(source_factory, 'Create')
        source_factory.Create(self.conf.options[
            config.MAP_PASSWORD].source).AndReturn(source_mock)

        cache_mock = self.mox.CreateMock(caches.Cache)
        cache_mock.GetMapLocation().AndReturn('home')
        cache_mock.WriteMap(map_data=automount_map).AndReturn(0)
        cache_mock.WriteMap(map_data=automount_map).AndReturn(0)

        self.mox.StubOutWithMock(cache_factory, 'Create')
        cache_factory.Create(
            self.conf.options[config.MAP_AUTOMOUNT].cache,
            config.MAP_AUTOMOUNT,
            automount_mountpoint='/home').AndReturn(cache_mock)
        cache_factory.Create(self.conf.options[config.MAP_AUTOMOUNT].cache,
                             config.MAP_AUTOMOUNT,
                             automount_mountpoint=None).AndReturn(cache_mock)

        self.mox.ReplayAll()

        c = command.Update()
        self.assertEquals(
            0, c.UpdateMaps(self.conf, incremental=True, force_write=False))
Exemple #11
0
 def testForceLockFlag(self):
     c = command.Update()
     (options, _) = c.parser.parse_args([])
     self.assertEqual(False, options.force_lock)
     (options, _) = c.parser.parse_args(['--force-lock'])
     self.assertEqual(True, options.force_lock)
Exemple #12
0
 def testForceWriteFlag(self):
     c = command.Update()
     (options, _) = c.parser.parse_args([])
     self.assertEqual(False, options.force_write)
     (options, _) = c.parser.parse_args(['--force-write'])
     self.assertEqual(True, options.force_write)
Exemple #13
0
 def testHelp(self):
     c = command.Update()
     self.failIfEqual(None, c.Help())
Exemple #14
0
 def testConstructor(self):
     c = command.Update()
     self.failIfEqual(None, c)
Exemple #15
0
 def testHelp(self):
     c = command.Update()
     self.assertNotEqual(None, c.Help())
Exemple #16
0
 def testConstructor(self):
     c = command.Update()
     self.assertNotEqual(None, c)