예제 #1
0
    def override_user(self,
                      username,
                      password=None,
                      homedir=None,
                      perm=None,
                      msg_login=None,
                      msg_quit=None):
        """Overrides the options specified in the class constructor
        for a specific user.
        """
        if not password and not homedir and not perm and not msg_login \
        and not msg_quit:
            raise ValueError("at least one keyword argument must be specified")
        if self.allowed_users and username not in self.allowed_users:
            raise ValueError('%s is not an allowed user' % username)
        if self.rejected_users and username in self.rejected_users:
            raise ValueError('%s is not an allowed user' % username)
        if username == "anonymous" and password:
            raise ValueError("can't assign password to anonymous user")
        if not self.has_user(username):
            raise ValueError('no such user %s' % username)
        if homedir is not None and not isinstance(homedir, unicode):
            homedir = homedir.decode('utf8')

        if username in self._dummy_authorizer.user_table:
            # re-set parameters
            del self._dummy_authorizer.user_table[username]
        self._dummy_authorizer.add_user(username, password or "", homedir
                                        or getcwdu(), perm or "", msg_login
                                        or "", msg_quit or "")
        if homedir is None:
            self._dummy_authorizer.user_table[username]['home'] = ""
예제 #2
0
    def override_user(self, username, password=None, homedir=None, perm=None,
                      msg_login=None, msg_quit=None):
        """Overrides the options specified in the class constructor
        for a specific user.
        """
        if not password and not homedir and not perm and not msg_login \
        and not msg_quit:
            raise ValueError("at least one keyword argument must be specified")
        if self.allowed_users and username not in self.allowed_users:
            raise ValueError('%s is not an allowed user' % username)
        if self.rejected_users and username in self.rejected_users:
            raise ValueError('%s is not an allowed user' % username)
        if username == "anonymous" and password:
            raise ValueError("can't assign password to anonymous user")
        if not self.has_user(username):
            raise ValueError('no such user %s' % username)
        if homedir is not None and not isinstance(homedir, unicode):
            homedir = homedir.decode('utf8')

        if username in self._dummy_authorizer.user_table:
            # re-set parameters
            del self._dummy_authorizer.user_table[username]
        self._dummy_authorizer.add_user(username, password or "",
                                                  homedir or getcwdu(),
                                                  perm or "",
                                                  msg_login or "",
                                                  msg_quit or "")
        if homedir is None:
            self._dummy_authorizer.user_table[username]['home'] = ""
예제 #3
0
 def test_case(self):
     root = getcwdu()
     fs = filesystems.UnixFilesystem(root, None)
     self.assertEqual(fs.root, root)
     self.assertEqual(fs.cwd, root)
     cdup = os.path.dirname(root)
     self.assertEqual(fs.ftp2fs(u('..')), cdup)
     self.assertEqual(fs.fs2ftp(root), root)
예제 #4
0
 def test_override_user_homedir(self):
     auth = self.authorizer_class()
     user = self.get_current_user()
     dir = os.path.dirname(getcwdu())
     auth.override_user(user, homedir=dir)
     self.assertEqual(auth.get_home_dir(user), dir)
     # make sure other settings keep using default values
     #self.assertEqual(auth.get_home_dir(user), self.get_current_user_homedir())
     self.assertEqual(auth.get_perms(user), "elradfmw")
     self.assertEqual(auth.get_msg_login(user), "Login successful.")
     self.assertEqual(auth.get_msg_quit(user), "Goodbye.")