'If the key file is readable, L{SSHPublicKeyDatabase.checkKey} should
switch its uid/gid to the ones of the authenticated user.'

def test_checkKeyAsRoot(self):

    keyFile = self.sshDir.child('authorized_keys')
    keyFile.setContent(self.content)
    keyFile.chmod(0)
    self.addCleanup(keyFile.chmod, 511)
    savedSeteuid = self.mockos.seteuid
    def seteuid(euid):
        keyFile.chmod(511)
        return savedSeteuid(euid)
    self.mockos.euid = 2345
    self.mockos.egid = 1234
    self.patch(self.mockos, 'seteuid', seteuid)
    self.patch(util, 'os', self.mockos)
    user = UsernamePassword('user', 'password')
    user.blob = 'foobar'
    self.assertTrue(self.checker.checkKey(user))
    self.assertEqual(self.mockos.seteuidCalls, [0, 1, 0, 2345])
    self.assertEqual(self.mockos.setegidCalls, [2, 1234])
