コード例 #1
0
 def test_validate_authentication(self):
     # we can only test for invalid credentials
     auth = authorizers.UnixAuthorizer(require_valid_shell=False)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       '?!foo', '?!foo', None)
     auth = authorizers.UnixAuthorizer(require_valid_shell=True)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       '?!foo', '?!foo', None)
コード例 #2
0
    def test_require_valid_shell(self):
        def get_fake_shell_user():
            for user in self.get_users():
                shell = pwd.getpwnam(user).pw_shell
                # On linux fake shell is usually /bin/false, on
                # freebsd /usr/sbin/nologin;  in case of other
                # UNIX variants test needs to be adjusted.
                if '/false' in shell or '/nologin' in shell:
                    return user
            self.fail("no user found")

        user = get_fake_shell_user()
        self.assertRaisesWithMsg(AuthorizerError,
                                 "user %s has not a valid shell" % user,
                                 authorizers.UnixAuthorizer,
                                 allowed_users=[user])
        # commented as it first fails for invalid home
        #self.assertRaisesWithMsg(ValueError,
        #                     "user %s has not a valid shell" % user,
        #                     authorizers.UnixAuthorizer, anonymous_user=user)
        auth = authorizers.UnixAuthorizer()
        self.assertTrue(auth._has_valid_shell(self.get_current_user()))
        self.assertFalse(auth._has_valid_shell(user))
        self.assertRaisesWithMsg(AuthorizerError,
                                 "User %s doesn't have a valid shell." % user,
                                 auth.override_user,
                                 user,
                                 perm='r')
コード例 #3
0
 def test_validate_authentication_anonymous(self):
     current_user = self.get_current_user()
     auth = authorizers.UnixAuthorizer(anonymous_user=current_user,
                                       require_valid_shell=False)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       'foo', 'passwd', None)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       current_user, 'passwd', None)
     auth.validate_authentication('anonymous', 'passwd', None)
コード例 #4
0
 def test_get_perms_anonymous(self):
     auth = authorizers.UnixAuthorizer(
         global_perm='elr', anonymous_user=self.get_current_user())
     self.assertTrue('e' in auth.get_perms('anonymous'))
     self.assertFalse('w' in auth.get_perms('anonymous'))
     warnings.filterwarnings("ignore")
     auth.override_user('anonymous', perm='w')
     warnings.resetwarnings()
     self.assertTrue('w' in auth.get_perms('anonymous'))
コード例 #5
0
 def setUp(self):
     if os.name != 'posix':
         self.skipTest("UNIX only")
     if sys.version_info < (2, 5):
         self.skipTest("python >= 2.5 only")
     try:
         import spwd  # NOQA
     except ImportError:
         self.skipTest("spwd module not available")
     try:
         authorizers.UnixAuthorizer()
     except AuthorizerError:  # not root
         self.skipTest("need root access")
コード例 #6
0
def test_main():
    test_suite = unittest.TestSuite()
    tests = []

    # FTPS tests
    if FTPS_SUPPORT:
        ftps_tests = [
            TestFTPS,
            TestFtpAuthenticationTLSMixin,
            TestTFtpDummyCmdsTLSMixin,
            TestFtpCmdsSemanticTLSMixin,
            TestFtpFsOperationsTLSMixin,
            TestFtpStoreDataTLSMixin,
            TestFtpRetrieveDataTLSMixin,
            TestFtpListingCmdsTLSMixin,
            TestFtpAbortTLSMixin,
            TestTimeoutsTLSMixin,
            TestConfigurableOptionsTLSMixin,
            TestCallbacksTLSMixin,
            TestCornerCasesTLSMixin,
        ]
        if SUPPORTS_IPV4:
            ftps_tests.append(TestIPv4EnvironmentTLSMixin)
        if SUPPORTS_IPV6:
            ftps_tests.append(TestIPv6EnvironmentTLSMixin)
        tests += ftps_tests
    else:
        if sys.version_info < (2, 7):
            warn("FTPS tests skipped (requires python 2.7)")
        elif ssl is None:
            warn("FTPS tests skipped (requires ssl module)")
        elif not hasattr(handlers, 'TLS_FTPHandler'):
            warn("FTPS tests skipped (requires PyOpenSSL module)")
        else:
            warn("FTPS tests skipped")

    # threaded FTP server tests
    ftp_thread_tests = [
        TestFtpAuthenticationThreadMixin,
        TestTFtpDummyCmdsThreadMixin,
        TestFtpCmdsSemanticThreadMixin,
        TestFtpFsOperationsThreadMixin,
        TestFtpStoreDataThreadMixin,
        TestFtpRetrieveDataThreadMixin,
        TestFtpListingCmdsThreadMixin,
        TestFtpAbortThreadMixin,
        #TestTimeoutsThreadMixin,
        #TestConfigurableOptionsThreadMixin,
        TestCallbacksThreadMixin,
        TestCornerCasesThreadMixin,
        TestFTPServerThreadMixin,
    ]
    tests += ftp_thread_tests

    # multi process FTP server tests
    if MPROCESS_SUPPORT:
        ftp_mproc_tests = [
            TestFtpAuthenticationMProcMixin,
            TestTFtpDummyCmdsMProcMixin,
            TestFtpCmdsSemanticMProcMixin,
            TestFtpFsOperationsMProcMixin,
            TestFtpStoreDataMProcMixin,
            TestFtpRetrieveDataMProcMixin,
            TestFtpListingCmdsMProcMixin,
            TestFtpAbortMProcMixin,
            #TestTimeoutsMProcMixin,
            #TestConfigurableOptionsMProcMixin,
            #TestCallbacksMProcMixin,
            TestCornerCasesMProcMixin,
            TestFTPServerMProcMixin,
        ]
        tests += ftp_mproc_tests

    # POSIX tests
    if os.name == 'posix':
        tests.append(TestUnixFilesystem)

        if hasattr(authorizers, "UnixAuthorizer"):
            try:
                authorizers.UnixAuthorizer()
            except AuthorizerError:  # not root
                warn("UnixAuthorizer tests skipped (root privileges are "
                     "required)")
            else:
                tests.append(TestUnixAuthorizer)
        else:
            try:
                import spwd
            except ImportError:
                warn("UnixAuthorizer tests skipped (spwd module is missing")
            else:
                warn("UnixAuthorizer tests skipped")

    # Windows tests
    elif os.name in ('nt', 'ce'):
        if hasattr(authorizers, "WindowsAuthorizer"):
            tests.append(TestWindowsAuthorizer)
        else:
            try:
                import win32api
            except ImportError:
                warn("WindowsAuthorizer tests skipped (pywin32 extension "
                     "is required)")
            else:
                warn("WindowsAuthorizer tests skipped")

    for test in tests:
        test_suite.addTest(unittest.makeSuite(test))
    try:
        result = unittest.TextTestRunner(verbosity=2).run(test_suite)
    finally:
        cleanup()
    return result