Exemplo n.º 1
0
    def test_120_print_conf_config_includes_user_config(
            self, mock_run, mock_stderr, mock_stdout):
        # call
        rc = main([
            '-c',
            os.path.dirname(__file__) + "/password.conf", '--dry',
            '--print-conf'
        ])
        self.assertEqual(rc, 0)
        self.assertEqual(mock_stderr.getvalue(), '')
        self.assertFalse(mock_run.called)

        # write config into file
        import tempfile
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(mock_stdout.getvalue())
        f.close()

        try:
            # use temp file as config
            rc = main(['-c', f.name])
            self.assertEqual(rc, 0)
            self.assertEqual(mock_stderr.getvalue(), '')
            self.assertTrue(mock_run.called)

            # check that option from the first call are set in the config now
            config = mock_run.call_args[0][0]
            self.assertTrue(config.dry)
        finally:
            os.remove(f.name)
Exemplo n.º 2
0
    def test_115_print_conf_config_can_be_read_again_and_is_the_same(
            self, mock_run, mock_stderr, mock_stdout):
        # call
        rc = main(['--dry', '--print-conf'])
        self.assertEqual(rc, 0)
        self.assertEqual(mock_stderr.getvalue(), '')
        self.assertFalse(mock_run.called)

        # write config into file
        config_string = mock_stdout.getvalue()
        import tempfile
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(config_string)
        f.close()

        try:
            with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
                # use temp file as config
                rc = main(['-c', f.name, '--print-conf'])
                self.assertEqual(rc, 0)
                self.assertEqual(mock_stderr.getvalue(), '')
                self.assertFalse(mock_run.called)
                self.assertEqual(config_string, mock_stdout.getvalue())
        finally:
            os.remove(f.name)
Exemplo n.º 3
0
 def test_120_print_conf_config_includes_user_config(self, mock_run, mock_stderr, mock_stdout):
     # call
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--dry', '--print-conf'])
     self.assertEqual(rc, 0)
     self.assertEqual(mock_stderr.getvalue(), '')
     self.assertFalse(mock_run.called)
     
     # write config into file
     import tempfile
     f = tempfile.NamedTemporaryFile(delete=False)
     f.write(mock_stdout.getvalue())
     f.close()
     
     try:            
         # use temp file as config
         rc = main(['-c', f.name])
         self.assertEqual(rc, 0)
         self.assertEqual(mock_stderr.getvalue(), '')
         self.assertTrue(mock_run.called)
         
         # check that option from the first call are set in the config now 
         config = mock_run.call_args[0][0]
         self.assertTrue(config.dry)
     finally:
         os.remove(f.name)
Exemplo n.º 4
0
    def test_040_main_sets_globals(self, mock_run):
        rc = main(['-c', os.path.dirname(__file__) + "/password.conf"])
        self.assertEqual(rc, 0)

        self.assertTrue(mock_run.called)
        self.assertEqual(g.DEBUG, 0)
        self.assertFalse(g.VERBOSE)
Exemplo n.º 5
0
 def test_100_restrict_sets_config_test_restrict_to_users(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--restrict', ' foo1;foo2 ;cn=foo3,ou=users,dc=localhost;;;' ])
     self.assertEqual(rc, 0)
     self.assertTrue(mock_run.called)
     
     config = mock_run.call_args[0][0]
     self.assertEqual(config.restrict_to_users, set(['foo1', 'foo2', 'cn=foo3,ou=users,dc=localhost']))
Exemplo n.º 6
0
    def test_110_k_sets_config_ignore_cert(self, mock_run):
        rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '-k'])
        self.assertEqual(rc, 0)
        self.assertTrue(mock_run.called)

        config = mock_run.call_args[0][0]
        self.assertTrue(config.ignore_cert)
Exemplo n.º 7
0
 def test_010_shows_help(self, mock_stderr, mock_stdout):
     rc = main(['--help'])
     self.assertTrue(
         mock_stdout.getvalue().startswith(
             'Usage: ldap-notify [OPTION]...'),
         [mock_stdout.getvalue()[:40]])
     self.assertEqual(rc, 0)
Exemplo n.º 8
0
    def test_040_main_sets_globals(self, mock_run):
        rc = main(['-c', os.path.dirname(__file__) + "/password.conf"])
        self.assertEqual(rc, 0)

        self.assertTrue(mock_run.called)
        self.assertEqual(g.DEBUG, 0)
        self.assertFalse(g.VERBOSE)
Exemplo n.º 9
0
 def test_080_dry_sets_config_test_dry(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--dry' ])
     self.assertEqual(rc, 0)
     self.assertTrue(mock_run.called)
     
     config = mock_run.call_args[0][0]
     self.assertTrue(config.dry)
Exemplo n.º 10
0
 def test_110_k_sets_config_ignore_cert(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '-k' ])
     self.assertEqual(rc, 0)
     self.assertTrue(mock_run.called)
     
     config = mock_run.call_args[0][0]
     self.assertTrue(config.ignore_cert)
Exemplo n.º 11
0
    def test_080_dry_sets_config_test_dry(self, mock_run):
        rc = main(
            ['-c', os.path.dirname(__file__) + "/password.conf", '--dry'])
        self.assertEqual(rc, 0)
        self.assertTrue(mock_run.called)

        config = mock_run.call_args[0][0]
        self.assertTrue(config.dry)
Exemplo n.º 12
0
 def test_090_test_sets_config_test_test(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--test', 'foo@localhost' ])
     self.assertEqual(rc, 0)
     self.assertTrue(mock_run.called)
     
     config = mock_run.call_args[0][0]
     self.assertTrue(config.test.enabled)
     self.assertEqual(config.test.to_address, 'foo@localhost')
Exemplo n.º 13
0
 def test_020_shows_help_even_after_other_arguments(self, mock_stderr,
                                                    mock_stdout):
     rc = main(['-v', '--test', 'foo@localhost', '--help', '-d'])
     self.assertTrue(
         mock_stdout.getvalue().startswith(
             'Usage: ldap-notify [OPTION]...'),
         [mock_stdout.getvalue()[:40]])
     self.assertEqual(rc, 0)
Exemplo n.º 14
0
    def test_050_debug_increase_g_debug(self, mock_run):
        rc = main([
            '-c',
            os.path.dirname(__file__) + "/password.conf", '-d', '--debug', '-d'
        ])
        self.assertEqual(rc, 0)

        self.assertTrue(mock_run.called)
        self.assertEqual(g.DEBUG, 3)
Exemplo n.º 15
0
    def test_070_time_sets_now_timestamp(self, mock_run):
        rc = main([
            '-c',
            os.path.dirname(__file__) + "/password.conf", '--time',
            '20140825163831Z'
        ])
        self.assertEqual(rc, 0)

        self.assertTrue(mock_run.called)
        self.assertEqual(g.NOW.strftime(g.LDAP_TIME_FORMAT), '20140825163831Z')
Exemplo n.º 16
0
    def test_090_test_sets_config_test_test(self, mock_run):
        rc = main([
            '-c',
            os.path.dirname(__file__) + "/password.conf", '--test',
            'foo@localhost'
        ])
        self.assertEqual(rc, 0)
        self.assertTrue(mock_run.called)

        config = mock_run.call_args[0][0]
        self.assertTrue(config.test.enabled)
        self.assertEqual(config.test.to_address, 'foo@localhost')
Exemplo n.º 17
0
    def test_100_restrict_sets_config_test_restrict_to_users(self, mock_run):
        rc = main([
            '-c',
            os.path.dirname(__file__) + "/password.conf", '--restrict',
            ' foo1;foo2 ;cn=foo3,ou=users,dc=localhost;;;'
        ])
        self.assertEqual(rc, 0)
        self.assertTrue(mock_run.called)

        config = mock_run.call_args[0][0]
        self.assertEqual(
            config.restrict_to_users,
            set(['foo1', 'foo2', 'cn=foo3,ou=users,dc=localhost']))
Exemplo n.º 18
0
 def test_115_print_conf_config_can_be_read_again_and_is_the_same(self, mock_run, mock_stderr, mock_stdout):
     # call
     rc = main(['--dry', '--print-conf'])
     self.assertEqual(rc, 0)
     self.assertEqual(mock_stderr.getvalue(), '')
     self.assertFalse(mock_run.called)
     
     # write config into file
     config_string = mock_stdout.getvalue()
     import tempfile
     f = tempfile.NamedTemporaryFile(delete=False)
     f.write(config_string)
     f.close()
     
     try:
         with patch('sys.stdout', new_callable=StringIO) as mock_stdout:    
             # use temp file as config
             rc = main(['-c', f.name, '--print-conf'])
             self.assertEqual(rc, 0)
             self.assertEqual(mock_stderr.getvalue(), '')
             self.assertFalse(mock_run.called)
             self.assertEqual(config_string, mock_stdout.getvalue())
     finally:
         os.remove(f.name)
Exemplo n.º 19
0
    def test_110_ldap_error_is_displayed(self, mock_stderr, mock_stdout):
        rc = main(['-c', os.path.dirname(__file__) + "/password.conf"])
        self.assertEqual(rc, 1)

        self.assertTrue(
            mock_stderr.getvalue().startswith("LDAP error: Mock LDAP Error\n"))
Exemplo n.º 20
0
 def test_030_main_reject_non_option_args(self, mock_run):
     rc = main(['foo'])
     self.assertEqual(rc, 2)
     self.assertFalse(mock_run.called)
Exemplo n.º 21
0
 def test_035_main_does_not_run_without_config(self, mock_run):
     rc = main([])
     self.assertEqual(rc, 2)
     self.assertFalse(mock_run.called)
Exemplo n.º 22
0
 def test_050_debug_increase_g_debug(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '-d', '--debug', '-d'])
     self.assertEqual(rc, 0)
     
     self.assertTrue(mock_run.called)
     self.assertEqual(g.DEBUG, 3)
Exemplo n.º 23
0
 def test_020_reject_unknown_parameters(self):
     rc = main(['--foo'])
     self.assertEqual(rc, 2)
Exemplo n.º 24
0
 def test_010_shows_help(self, mock_stderr, mock_stdout):
     rc = main(['--help'])
     self.assertTrue(mock_stdout.getvalue().startswith('Usage: ldap-notify [OPTION]...'), [mock_stdout.getvalue()[:40]])
     self.assertEqual(rc, 0)
Exemplo n.º 25
0
 def test_070_time_sets_now_timestamp(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '--time', '20140825163831Z' ])
     self.assertEqual(rc, 0)
     
     self.assertTrue(mock_run.called)
     self.assertEqual(g.NOW.strftime(g.LDAP_TIME_FORMAT), '20140825163831Z')
Exemplo n.º 26
0
 def test_035_main_does_not_run_without_config(self, mock_run):
     rc = main([])
     self.assertEqual(rc, 2)
     self.assertFalse(mock_run.called)
Exemplo n.º 27
0
 def test_110_ldap_error_is_displayed(self, mock_stderr, mock_stdout):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf" ])
     self.assertEqual(rc, 1)
     
     self.assertTrue(mock_stderr.getvalue().startswith("LDAP error: Mock LDAP Error\n"))
Exemplo n.º 28
0
 def test_030_main_reject_non_option_args(self, mock_run):
     rc = main(['foo'])
     self.assertEqual(rc, 2)
     self.assertFalse(mock_run.called)
Exemplo n.º 29
0
    def test_060_verbose_sets_g_verbose(self, mock_run):
        rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '-v'])
        self.assertEqual(rc, 0)

        self.assertTrue(mock_run.called)
        self.assertTrue(g.VERBOSE)
Exemplo n.º 30
0
 def test_020_reject_unknown_parameters(self):
     rc = main(['--foo'])
     self.assertEqual(rc, 2)
Exemplo n.º 31
0
 def test_020_shows_help_even_after_other_arguments(self, mock_stderr, mock_stdout):
     rc = main(['-v', '--test', 'foo@localhost', '--help', '-d'])
     self.assertTrue(mock_stdout.getvalue().startswith('Usage: ldap-notify [OPTION]...'), [mock_stdout.getvalue()[:40]])
     self.assertEqual(rc, 0)
Exemplo n.º 32
0
 def test_060_verbose_sets_g_verbose(self, mock_run):
     rc = main(['-c', os.path.dirname(__file__) + "/password.conf", '-v'])
     self.assertEqual(rc, 0)
     
     self.assertTrue(mock_run.called)
     self.assertTrue(g.VERBOSE)