~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Aaron Bentley
  • Date: 2007-06-15 11:27:17 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: aaron.bentley@utoronto.ca-20070615112717-zchc59doyk2sfmqt
Add signature support

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
from bzrlib.repofmt import knitrepo
43
43
from bzrlib.osutils import has_symlinks, sha_file
44
44
from bzrlib.tests import (TestCaseInTempDir, TestCaseWithTransport,
45
 
                          TestCase, TestSkipped)
 
45
                          TestCase, TestSkipped, test_commit)
46
46
from bzrlib.transform import TreeTransform
47
47
from bzrlib.workingtree import WorkingTree
48
48
 
1137
1137
 
1138
1138
        return bundle
1139
1139
 
 
1140
    def get_invalid_bundle(self, base_rev_id, rev_id):
 
1141
        """Create a bundle from base_rev_id -> rev_id in built-in branch.
 
1142
        Munge the text so that it's invalid.
 
1143
 
 
1144
        :return: The in-memory bundle
 
1145
        """
 
1146
        from bzrlib.bundle import serializer
 
1147
        bundle_txt, rev_ids = self.create_bundle_text(base_rev_id, rev_id)
 
1148
        new_text = self.get_raw(StringIO(''.join(bundle_txt)))
 
1149
        new_text = new_text.replace('<file file_id="exe-1"',
 
1150
                                    '<file executable="y" file_id="exe-1"')
 
1151
        new_text = new_text.replace('B418', 'B433')
 
1152
        bundle_txt = StringIO()
 
1153
        bundle_txt.write(serializer._get_bundle_header('1.0alpha'))
 
1154
        bundle_txt.write('\n')
 
1155
        bundle_txt.write(new_text.encode('bz2').encode('base-64'))
 
1156
        bundle_txt.seek(0)
 
1157
        bundle = read_bundle(bundle_txt)
 
1158
        self.valid_apply_bundle(base_rev_id, bundle)
 
1159
        return bundle
 
1160
 
1140
1161
    def create_bundle_text(self, base_rev_id, rev_id):
1141
1162
        bundle_txt = StringIO()
1142
1163
        rev_ids = write_bundle(self.b1.repository, rev_id, base_rev_id, 
1196
1217
        lines = bundle_file.readlines()
1197
1218
        return ''.join(lines).decode('base-64').decode('bz2')
1198
1219
 
 
1220
    def test_copy_signatures(self):
 
1221
        tree_a = self.make_branch_and_tree('tree_a')
 
1222
        import bzrlib.gpg
 
1223
        import bzrlib.commit as commit
 
1224
        oldstrategy = bzrlib.gpg.GPGStrategy
 
1225
        branch = tree_a.branch
 
1226
        repo_a = branch.repository
 
1227
        tree_a.commit("base", allow_pointless=True, rev_id='A')
 
1228
        self.failIf(branch.repository.has_signature_for_revision_id('A'))
 
1229
        try:
 
1230
            from bzrlib.testament import Testament
 
1231
            # monkey patch gpg signing mechanism
 
1232
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
 
1233
            new_config = test_commit.MustSignConfig(branch)
 
1234
            commit.Commit(config=new_config).commit(message="base",
 
1235
                                                    allow_pointless=True,
 
1236
                                                    rev_id='B',
 
1237
                                                    working_tree=tree_a)
 
1238
            def sign(text):
 
1239
                return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
 
1240
            self.assertTrue(repo_a.has_signature_for_revision_id('B'))
 
1241
        finally:
 
1242
            bzrlib.gpg.GPGStrategy = oldstrategy
 
1243
        tree_b = self.make_branch_and_tree('tree_b')
 
1244
        repo_b = tree_b.branch.repository
 
1245
        s = StringIO()
 
1246
        serializer = BundleSerializerV10('1.0')
 
1247
        serializer.write(tree_a.branch.repository, ['A', 'B'], {}, s)
 
1248
        s.seek(0)
 
1249
        install_bundle(repo_b, serializer.read(s))
 
1250
        self.assertTrue(repo_b.has_signature_for_revision_id('B'))
 
1251
        self.assertEqual(repo_b.get_signature_text('B'),
 
1252
                         repo_a.get_signature_text('B'))
 
1253
 
1199
1254
 
1200
1255
class MungedBundleTester(TestCaseWithTransport):
1201
1256
 
1280
1335
 
1281
1336
        bundle = read_bundle(bundle_txt)
1282
1337
        self.check_valid(bundle)
1283