~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

 * The internal storage of history, and logical branch identity have now
   been split into Branch, and Repository. The common locking and file 
   management routines are now in bzrlib.lockablefiles. 
   (Aaron Bentley, Robert Collins, Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
In the future, when we have Repository/Branch/Checkout information, the
25
25
permissions should be inherited individually, rather than all be the same.
26
 
 
27
 
TODO: jam 20051215 There are no tests for ftp yet, because we have no ftp server
28
 
TODO: jam 20051215 Currently the default behavior for 'bzr branch' is just 
29
 
                   defined by the local umask. This isn't terrible, is it
30
 
                   the truly desired behavior?
31
26
"""
32
27
 
 
28
# TODO: jam 20051215 There are no tests for ftp yet, because we have no ftp server
 
29
# TODO: jam 20051215 Currently the default behavior for 'bzr branch' is just 
 
30
#                    defined by the local umask. This isn't terrible, is it
 
31
#                    the truly desired behavior?
 
32
 
33
33
import os
34
34
import sys
35
35
import stat
 
36
from StringIO import StringIO
36
37
 
37
38
from bzrlib.branch import Branch
 
39
from bzrlib.lockable_files import LockableFiles
38
40
from bzrlib.tests import TestCaseInTempDir, TestSkipped
 
41
from bzrlib.transport import get_transport
 
42
 
39
43
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
44
from bzrlib.transport import get_transport
41
45
 
99
103
 
100
104
        b = Branch.open('.')
101
105
        t = b.working_tree()
102
 
        assertEqualMode(self, 0755, b._dir_mode)
103
 
        assertEqualMode(self, 0644, b._file_mode)
 
106
        assertEqualMode(self, 0755, b.control_files._dir_mode)
 
107
        assertEqualMode(self, 0644, b.control_files._file_mode)
104
108
 
105
109
        # Modifying a file shouldn't break the permissions
106
110
        open('a', 'wb').write('foo2\n')
120
124
        check_mode_r(self, '.bzr', 0664, 0775)
121
125
        b = Branch.open('.')
122
126
        t = b.working_tree()
123
 
        assertEqualMode(self, 0775, b._dir_mode)
124
 
        assertEqualMode(self, 0664, b._file_mode)
 
127
        assertEqualMode(self, 0775, b.control_files._dir_mode)
 
128
        assertEqualMode(self, 0664, b.control_files._file_mode)
125
129
 
126
130
        open('a', 'wb').write('foo3\n')
127
131
        t.commit('foo3')
139
143
        check_mode_r(self, '.bzr', 0664, 02775)
140
144
        b = Branch.open('.')
141
145
        t = b.working_tree()
142
 
        assertEqualMode(self, 02775, b._dir_mode)
143
 
        assertEqualMode(self, 0664, b._file_mode)
 
146
        assertEqualMode(self, 02775, b.control_files._dir_mode)
 
147
        assertEqualMode(self, 0664, b.control_files._file_mode)
144
148
 
145
149
        open('a', 'wb').write('foo4\n')
146
150
        t.commit('foo4')
154
158
    def test_disable_set_mode(self):
155
159
        # TODO: jam 20051215 Ultimately, this test should probably test that
156
160
        #                    extra chmod calls aren't being made
157
 
        import bzrlib.branch
158
161
        try:
159
 
            b = Branch.initialize(u'.')
160
 
            self.assertNotEqual(None, b._dir_mode)
161
 
            self.assertNotEqual(None, b._file_mode)
162
 
 
163
 
            bzrlib.branch.BzrBranch._set_dir_mode = False
164
 
            b = Branch.open(u'.')
165
 
            self.assertEqual(None, b._dir_mode)
166
 
            self.assertNotEqual(None, b._file_mode)
167
 
 
168
 
            bzrlib.branch.BzrBranch._set_file_mode = False
169
 
            b = Branch.open(u'.')
170
 
            self.assertEqual(None, b._dir_mode)
171
 
            self.assertEqual(None, b._file_mode)
172
 
 
173
 
            bzrlib.branch.BzrBranch._set_dir_mode = True
174
 
            b = Branch.open(u'.')
175
 
            self.assertNotEqual(None, b._dir_mode)
176
 
            self.assertEqual(None, b._file_mode)
177
 
 
178
 
            bzrlib.branch.BzrBranch._set_file_mode = True
179
 
            b = Branch.open(u'.')
180
 
            self.assertNotEqual(None, b._dir_mode)
181
 
            self.assertNotEqual(None, b._file_mode)
 
162
            transport = get_transport('.')
 
163
            transport.put('my-lock', StringIO(''))
 
164
            lockable = LockableFiles(transport, 'my-lock')
 
165
            self.assertNotEqual(None, lockable._dir_mode)
 
166
            self.assertNotEqual(None, lockable._file_mode)
 
167
 
 
168
            LockableFiles._set_dir_mode = False
 
169
            transport = get_transport('.')
 
170
            lockable = LockableFiles(transport, 'my-lock')
 
171
            self.assertEqual(None, lockable._dir_mode)
 
172
            self.assertNotEqual(None, lockable._file_mode)
 
173
 
 
174
            LockableFiles._set_file_mode = False
 
175
            transport = get_transport('.')
 
176
            lockable = LockableFiles(transport, 'my-lock')
 
177
            self.assertEqual(None, lockable._dir_mode)
 
178
            self.assertEqual(None, lockable._file_mode)
 
179
 
 
180
            LockableFiles._set_dir_mode = True
 
181
            transport = get_transport('.')
 
182
            lockable = LockableFiles(transport, 'my-lock')
 
183
            self.assertNotEqual(None, lockable._dir_mode)
 
184
            self.assertEqual(None, lockable._file_mode)
 
185
 
 
186
            LockableFiles._set_file_mode = True
 
187
            transport = get_transport('.')
 
188
            lockable = LockableFiles(transport, 'my-lock')
 
189
            self.assertNotEqual(None, lockable._dir_mode)
 
190
            self.assertNotEqual(None, lockable._file_mode)
182
191
        finally:
183
 
            bzrlib.branch.BzrBranch._set_dir_mode = True
184
 
            bzrlib.branch.BzrBranch._set_file_mode = True
 
192
            LockableFiles._set_dir_mode = True
 
193
            LockableFiles._set_file_mode = True
185
194
 
186
195
    def test_new_branch(self):
187
196
        if sys.platform == 'win32':
188
197
            raise TestSkipped('chmod has no effect on win32')
189
 
 
 
198
        #FIXME RBC 20060105 should test branch and repository 
 
199
        # permissions ? 
 
200
        # also, these are BzrBranch format specific things..
190
201
        os.mkdir('a')
191
202
        mode = stat.S_IMODE(os.stat('a').st_mode)
192
203
        b = Branch.initialize('a')
193
 
        assertEqualMode(self, mode, b._dir_mode)
194
 
        assertEqualMode(self, mode & ~07111, b._file_mode)
 
204
        assertEqualMode(self, mode, b.control_files._dir_mode)
 
205
        assertEqualMode(self, mode & ~07111, b.control_files._file_mode)
195
206
 
196
207
        os.mkdir('b')
197
208
        os.chmod('b', 02777)
198
209
        b = Branch.initialize('b')
199
 
        assertEqualMode(self, 02777, b._dir_mode)
200
 
        assertEqualMode(self, 00666, b._file_mode)
 
210
        assertEqualMode(self, 02777, b.control_files._dir_mode)
 
211
        assertEqualMode(self, 00666, b.control_files._file_mode)
201
212
        check_mode_r(self, 'b/.bzr', 00666, 02777)
202
213
 
203
214
        os.mkdir('c')
204
215
        os.chmod('c', 02750)
205
216
        b = Branch.initialize('c')
206
 
        assertEqualMode(self, 02750, b._dir_mode)
207
 
        assertEqualMode(self, 00640, b._file_mode)
 
217
        assertEqualMode(self, 02750, b.control_files._dir_mode)
 
218
        assertEqualMode(self, 00640, b.control_files._file_mode)
208
219
        check_mode_r(self, 'c/.bzr', 00640, 02750)
209
220
 
210
221
        os.mkdir('d')
211
222
        os.chmod('d', 0700)
212
223
        b = Branch.initialize('d')
213
 
        assertEqualMode(self, 0700, b._dir_mode)
214
 
        assertEqualMode(self, 0600, b._file_mode)
 
224
        assertEqualMode(self, 0700, b.control_files._dir_mode)
 
225
        assertEqualMode(self, 0600, b.control_files._file_mode)
215
226
        check_mode_r(self, 'd/.bzr', 00600, 0700)
216
227
 
217
228
 
244
255
 
245
256
        b_local = Branch.open(u'local')
246
257
        t_local = b_local.working_tree()
247
 
        assertEqualMode(self, 0755, b_local._dir_mode)
248
 
        assertEqualMode(self, 0644, b_local._file_mode)
 
258
        assertEqualMode(self, 0755, b_local.control_files._dir_mode)
 
259
        assertEqualMode(self, 0644, b_local.control_files._file_mode)
249
260
 
250
261
        os.mkdir('sftp')
251
262
        sftp_url = self.get_remote_url('sftp')
257
268
        check_mode_r(self, 'sftp/.bzr', 0644, 0755)
258
269
 
259
270
        b_sftp = Branch.open(sftp_url)
260
 
        assertEqualMode(self, 0755, b_sftp._dir_mode)
261
 
        assertEqualMode(self, 0644, b_sftp._file_mode)
 
271
        assertEqualMode(self, 0755, b_sftp.control_files._dir_mode)
 
272
        assertEqualMode(self, 0644, b_sftp.control_files._file_mode)
262
273
 
263
274
        open('local/a', 'wb').write('foo2\n')
264
275
        t_local.commit('foo2')
278
289
        check_mode_r(self, 'sftp/.bzr', 0664, 0775)
279
290
 
280
291
        b_sftp = Branch.open(sftp_url)
281
 
        assertEqualMode(self, 0775, b_sftp._dir_mode)
282
 
        assertEqualMode(self, 0664, b_sftp._file_mode)
 
292
        assertEqualMode(self, 0775, b_sftp.control_files._dir_mode)
 
293
        assertEqualMode(self, 0664, b_sftp.control_files._file_mode)
283
294
 
284
295
        open('local/a', 'wb').write('foo3\n')
285
296
        t_local.commit('foo3')