/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
email=Erik B\u00e5gfors <erik@bagfors.nu>
177
177
editor=vim
178
178
change_editor=vimdiff -of @new_path @old_path
179
 
gpg_signing_command=gnome-gpg
180
179
gpg_signing_key=DD4D5088
181
180
log_format=short
182
181
validate_signatures_in_log=true
232
231
# test trailing / matching with no children
233
232
[/a/]
234
233
check_signatures=check-available
235
 
gpg_signing_command=false
236
234
gpg_signing_key=default
237
235
user_local_option=local
238
236
# test trailing / matching
656
654
 
657
655
    def test_unknown_ref(self):
658
656
        c = self.get_config('')
659
 
        self.assertRaises(errors.ExpandingUnknownOption,
 
657
        self.assertRaises(config.ExpandingUnknownOption,
660
658
                          c.expand_options, '{foo}')
661
659
 
662
660
    def test_indirect_ref(self):
675
673
 
676
674
    def test_simple_loop(self):
677
675
        c = self.get_config('foo={foo}')
678
 
        self.assertRaises(errors.OptionExpansionLoop, c.expand_options, '{foo}')
 
676
        self.assertRaises(config.OptionExpansionLoop, c.expand_options,
 
677
                          '{foo}')
679
678
 
680
679
    def test_indirect_loop(self):
681
680
        c = self.get_config('''
682
681
foo={bar}
683
682
bar={baz}
684
683
baz={foo}''')
685
 
        e = self.assertRaises(errors.OptionExpansionLoop,
 
684
        e = self.assertRaises(config.OptionExpansionLoop,
686
685
                              c.expand_options, '{foo}')
687
686
        self.assertEqual('foo->bar->baz', e.refs)
688
687
        self.assertEqual('{foo}', e.string)
741
740
[/another/branch/path]
742
741
bar = {foo}/2
743
742
''')
744
 
        self.assertRaises(errors.ExpandingUnknownOption,
 
743
        self.assertRaises(config.ExpandingUnknownOption,
745
744
                          c.get_user_option, 'bar', expand=True)
746
745
 
747
746
    def test_cross_related_sections(self):
956
955
        self.assertEqual(True, suppress_warning('b'))
957
956
 
958
957
 
959
 
class TestGetConfig(tests.TestCase):
 
958
class TestGetConfig(tests.TestCaseInTempDir):
960
959
 
961
960
    def test_constructs(self):
962
961
        config.GlobalConfig()
1536
1535
    def test_extract_email_address(self):
1537
1536
        self.assertEqual('jane@test.com',
1538
1537
                         config.extract_email_address('Jane <jane@test.com>'))
1539
 
        self.assertRaises(errors.NoEmailInUsername,
 
1538
        self.assertRaises(config.NoEmailInUsername,
1540
1539
                          config.extract_email_address, 'Jane Tester')
1541
1540
 
1542
1541
    def test_parse_username(self):
1597
1596
        t = self.get_transport()
1598
1597
        t.put_bytes('foo.conf', 'user=foo\n#\xff\n')
1599
1598
        conf = config.TransportConfig(t, 'foo.conf')
1600
 
        self.assertRaises(errors.ConfigContentError, conf._get_configobj)
 
1599
        self.assertRaises(config.ConfigContentError, conf._get_configobj)
1601
1600
 
1602
1601
    def test_load_erroneous_content(self):
1603
1602
        """Ensure we display a proper error on content that can't be parsed."""
1604
1603
        t = self.get_transport()
1605
1604
        t.put_bytes('foo.conf', '[open_section\n')
1606
1605
        conf = config.TransportConfig(t, 'foo.conf')
1607
 
        self.assertRaises(errors.ParseConfigError, conf._get_configobj)
 
1606
        self.assertRaises(config.ParseConfigError, conf._get_configobj)
1608
1607
 
1609
1608
    def test_load_permission_denied(self):
1610
1609
        """Ensure we get an empty config file if the file is inaccessible."""
2014
2013
            warnings[0])
2015
2014
 
2016
2015
    def assertCallsError(self, opt, value):
2017
 
        self.assertRaises(errors.ConfigOptionValueError,
 
2016
        self.assertRaises(config.ConfigOptionValueError,
2018
2017
                          opt.convert_from_unicode, None, value)
2019
2018
 
2020
2019
    def assertConvertInvalid(self, opt, invalid_value):
2181
2180
        self.assertEqual('A simple option', self.registry.get_help('foo'))
2182
2181
 
2183
2182
    def test_dont_register_illegal_name(self):
2184
 
        self.assertRaises(errors.IllegalOptionName,
 
2183
        self.assertRaises(config.IllegalOptionName,
2185
2184
                          self.registry.register, config.Option(' foo'))
2186
 
        self.assertRaises(errors.IllegalOptionName,
 
2185
        self.assertRaises(config.IllegalOptionName,
2187
2186
                          self.registry.register, config.Option('bar,'))
2188
2187
 
2189
2188
    lazy_option = config.Option('lazy_foo', help='Lazy help')
2204
2203
        # the option name which indirectly requires that the option name is a
2205
2204
        # valid python identifier. We violate that rule here (using a key that
2206
2205
        # doesn't match the option name) to test the option name checking.
2207
 
        self.assertRaises(errors.IllegalOptionName,
 
2206
        self.assertRaises(config.IllegalOptionName,
2208
2207
                          self.registry.register_lazy, ' foo', self.__module__,
2209
2208
                          'TestOptionRegistry.lazy_option')
2210
 
        self.assertRaises(errors.IllegalOptionName,
 
2209
        self.assertRaises(config.IllegalOptionName,
2211
2210
                          self.registry.register_lazy, '1,2', self.__module__,
2212
2211
                          'TestOptionRegistry.lazy_option')
2213
2212
 
2521
2520
        t = self.get_transport()
2522
2521
        t.put_bytes('foo.conf', 'user=foo\n#%s\n' % (self.invalid_utf8_char,))
2523
2522
        store = config.TransportIniFileStore(t, 'foo.conf')
2524
 
        self.assertRaises(errors.ConfigContentError, store.load)
 
2523
        self.assertRaises(config.ConfigContentError, store.load)
2525
2524
 
2526
2525
    def test_load_erroneous_content(self):
2527
2526
        """Ensure we display a proper error on content that can't be parsed."""
2528
2527
        t = self.get_transport()
2529
2528
        t.put_bytes('foo.conf', '[open_section\n')
2530
2529
        store = config.TransportIniFileStore(t, 'foo.conf')
2531
 
        self.assertRaises(errors.ParseConfigError, store.load)
 
2530
        self.assertRaises(config.ParseConfigError, store.load)
2532
2531
 
2533
2532
    def test_load_permission_denied(self):
2534
2533
        """Ensure we get warned when trying to load an inaccessible file."""
2578
2577
        with open('foo.conf', 'wb') as f:
2579
2578
            f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,))
2580
2579
        conf = config.IniBasedConfig(file_name='foo.conf')
2581
 
        self.assertRaises(errors.ConfigContentError, conf._get_parser)
 
2580
        self.assertRaises(config.ConfigContentError, conf._get_parser)
2582
2581
 
2583
2582
    def test_load_erroneous_content(self):
2584
2583
        """Ensure we display a proper error on content that can't be parsed."""
2585
2584
        with open('foo.conf', 'wb') as f:
2586
2585
            f.write('[open_section\n')
2587
2586
        conf = config.IniBasedConfig(file_name='foo.conf')
2588
 
        self.assertRaises(errors.ParseConfigError, conf._get_parser)
 
2587
        self.assertRaises(config.ParseConfigError, conf._get_parser)
2589
2588
 
2590
2589
 
2591
2590
class TestMutableStore(TestStore):
2870
2869
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
2871
2870
        self.assertEqual(False, store.is_loaded())
2872
2871
        exc = self.assertRaises(
2873
 
            errors.ParseConfigError, store._load_from_string,
 
2872
            config.ParseConfigError, store._load_from_string,
2874
2873
            'this is invalid !')
2875
2874
        self.assertEndsWith(exc.filename, 'foo.conf')
2876
2875
        # And the load failed
3670
3669
        self.assertExpansion('xxx', '{foo}')
3671
3670
 
3672
3671
    def test_unknown_ref(self):
3673
 
        self.assertRaises(errors.ExpandingUnknownOption,
 
3672
        self.assertRaises(config.ExpandingUnknownOption,
3674
3673
                          self.conf.expand_options, '{foo}')
3675
3674
 
3676
3675
    def test_illegal_def_is_ignored(self):
3694
3693
 
3695
3694
    def test_simple_loop(self):
3696
3695
        self.conf.store._load_from_string('foo={foo}')
3697
 
        self.assertRaises(errors.OptionExpansionLoop,
 
3696
        self.assertRaises(config.OptionExpansionLoop,
3698
3697
                          self.conf.expand_options, '{foo}')
3699
3698
 
3700
3699
    def test_indirect_loop(self):
3702
3701
foo={bar}
3703
3702
bar={baz}
3704
3703
baz={foo}''')
3705
 
        e = self.assertRaises(errors.OptionExpansionLoop,
 
3704
        e = self.assertRaises(config.OptionExpansionLoop,
3706
3705
                              self.conf.expand_options, '{foo}')
3707
3706
        self.assertEqual('foo->bar->baz', e.refs)
3708
3707
        self.assertEqual('{foo}', e.string)
3773
3772
[/another/branch/path]
3774
3773
bar = {foo}/2
3775
3774
''')
3776
 
        self.assertRaises(errors.ExpandingUnknownOption,
 
3775
        self.assertRaises(config.ExpandingUnknownOption,
3777
3776
                          c.get, 'bar', expand=True)
3778
3777
 
3779
3778
    def test_cross_related_sections(self):
3861
3860
''')
3862
3861
        g_store.save()
3863
3862
        stack = config.LocationStack('/home/user/project/branch')
3864
 
        self.assertRaises(errors.ExpandingUnknownOption,
 
3863
        self.assertRaises(config.ExpandingUnknownOption,
3865
3864
                          stack.get, 'gfoo', expand=True)
3866
3865
 
3867
3866
    def test_expand_local_option_locally(self):
4114
4113
        self.assertIs(g1.store, g2.store)
4115
4114
 
4116
4115
 
 
4116
class TestAuthenticationConfigFilePermissions(tests.TestCaseInTempDir):
 
4117
    """Test warning for permissions of authentication.conf."""
 
4118
 
 
4119
    def setUp(self):
 
4120
        super(TestAuthenticationConfigFilePermissions, self).setUp()
 
4121
        self.path = osutils.pathjoin(self.test_dir, 'authentication.conf')
 
4122
        with open(self.path, 'w') as f:
 
4123
            f.write(b"""[broken]
 
4124
scheme=ftp
 
4125
user=joe
 
4126
port=port # Error: Not an int
 
4127
""")
 
4128
        self.overrideAttr(config, 'authentication_config_filename',
 
4129
            lambda: self.path)
 
4130
        osutils.chmod_if_possible(self.path, 0o755)
 
4131
 
 
4132
    def test_check_warning(self):
 
4133
        conf = config.AuthenticationConfig()
 
4134
        self.assertEqual(conf._filename, self.path)
 
4135
        self.assertContainsRe(self.get_log(),
 
4136
            'Saved passwords may be accessible by other users.')
 
4137
 
 
4138
    def test_check_suppressed_warning(self):
 
4139
        global_config = config.GlobalConfig()
 
4140
        global_config.set_user_option('suppress_warnings',
 
4141
            'insecure_permissions')
 
4142
        conf = config.AuthenticationConfig()
 
4143
        self.assertEqual(conf._filename, self.path)
 
4144
        self.assertNotContainsRe(self.get_log(),
 
4145
            'Saved passwords may be accessible by other users.')
 
4146
 
 
4147
 
4117
4148
class TestAuthenticationConfigFile(tests.TestCase):
4118
4149
    """Test the authentication.conf file matching"""
4119
4150
 
4136
4167
 
4137
4168
    def test_non_utf8_config(self):
4138
4169
        conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar\xff'))
4139
 
        self.assertRaises(errors.ConfigContentError, conf._get_config)
 
4170
        self.assertRaises(config.ConfigContentError, conf._get_config)
4140
4171
 
4141
4172
    def test_missing_auth_section_header(self):
4142
4173
        conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar'))
4144
4175
 
4145
4176
    def test_auth_section_header_not_closed(self):
4146
4177
        conf = config.AuthenticationConfig(_file=BytesIO(b'[DEF'))
4147
 
        self.assertRaises(errors.ParseConfigError, conf._get_config)
 
4178
        self.assertRaises(config.ParseConfigError, conf._get_config)
4148
4179
 
4149
4180
    def test_auth_value_not_boolean(self):
4150
4181
        conf = config.AuthenticationConfig(_file=BytesIO(b"""\
4350
4381
        self.assertEqual(CREDENTIALS, credentials)
4351
4382
 
4352
4383
 
4353
 
class TestAuthenticationConfig(tests.TestCase):
 
4384
class TestAuthenticationConfig(tests.TestCaseInTempDir):
4354
4385
    """Test AuthenticationConfig behaviour"""
4355
4386
 
4356
4387
    def _check_default_password_prompt(self, expected_prompt_format, scheme,
4735
4766
 
4736
4767
    def test_unknown(self):
4737
4768
        conf = config.MemoryStack('mail_client=firebird')
4738
 
        self.assertRaises(errors.ConfigOptionValueError, conf.get,
 
4769
        self.assertRaises(config.ConfigOptionValueError, conf.get,
4739
4770
                'mail_client')