~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_permissions.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-07 07:52:50 UTC
  • mfrom: (3340.1.1 208418-1.4)
  • Revision ID: pqm@pqm.ubuntu.com-20080407075250-phs53xnslo8boaeo
Return the correct knit serialisation method in _StreamAccess.
        (Andrew Bennetts, Martin Pool, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
"""Tests for bzr setting permissions.
26
26
"""
27
27
 
28
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
 
29
# TODO: jam 20051215 Currently the default behavior for 'bzr branch' is just 
30
30
#                    defined by the local umask. This isn't terrible, is it
31
31
#                    the truly desired behavior?
32
 
 
 
32
 
33
33
import os
34
34
import sys
35
35
import stat
38
38
 
39
39
from bzrlib.branch import Branch
40
40
from bzrlib.bzrdir import BzrDir
 
41
from bzrlib.lockable_files import LockableFiles, TransportLock
41
42
from bzrlib.tests import TestCaseWithTransport, TestSkipped
42
43
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
43
44
from bzrlib.transport import get_transport
46
47
 
47
48
def chmod_r(base, file_mode, dir_mode):
48
49
    """Recursively chmod from a base directory"""
 
50
    assert os.path.isdir(base)
49
51
    os.chmod(base, dir_mode)
50
52
    for root, dirs, files in os.walk(base):
51
53
        for d in dirs:
65
67
    :param dir_mode: The mode for all directories
66
68
    :param include_base: If false, only check the subdirectories
67
69
    """
 
70
    assert os.path.isdir(base)
68
71
    t = get_transport(".")
69
72
    if include_base:
70
73
        test.assertTransportMode(t, base, dir_mode)
96
99
 
97
100
        # although we are modifying the filesystem
98
101
        # underneath the objects, they are not locked, and thus it must
99
 
        # be safe for most operations. But here we want to observe a
 
102
        # be safe for most operations. But here we want to observe a 
100
103
        # mode change in the control bits, which current do not refresh
101
104
        # when a new lock is taken out.
102
105
        t = WorkingTree.open('.')
103
106
        b = t.branch
104
107
        self.assertEqualMode(0755, b.control_files._dir_mode)
105
108
        self.assertEqualMode(0644, b.control_files._file_mode)
106
 
        self.assertEqualMode(0755, b.bzrdir._get_dir_mode())
107
 
        self.assertEqualMode(0644, b.bzrdir._get_file_mode())
108
109
 
109
110
        # Modifying a file shouldn't break the permissions
110
111
        open('a', 'wb').write('foo2\n')
125
126
        b = t.branch
126
127
        self.assertEqualMode(0775, b.control_files._dir_mode)
127
128
        self.assertEqualMode(0664, b.control_files._file_mode)
128
 
        self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
129
 
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
130
129
 
131
130
        open('a', 'wb').write('foo3\n')
132
131
        t.commit('foo3')
137
136
        t.commit('new c')
138
137
        check_mode_r(self, '.bzr', 0664, 0775)
139
138
 
140
 
    def test_new_files_group_sticky_bit(self):
141
 
        if sys.platform == 'win32':
142
 
            raise TestSkipped('chmod has no effect on win32')
143
 
        elif sys.platform == 'darwin' or sys.platform.startswith('freebsd'):
144
 
            # OS X (and FreeBSD) create temp dirs with the 'wheel' group, which
145
 
            # users are not likely to be in, and this prevents us from setting
146
 
            # the sgid bit
147
 
            os.chown(self.test_dir, os.getuid(), os.getgid())
148
 
 
149
 
        t = self.make_branch_and_tree('.')
150
 
        b = t.branch
151
 
 
152
139
        # Test the group sticky bit
153
140
        # Recursively update the modes of all files
154
141
        chmod_r('.bzr', 0664, 02775)
157
144
        b = t.branch
158
145
        self.assertEqualMode(02775, b.control_files._dir_mode)
159
146
        self.assertEqualMode(0664, b.control_files._file_mode)
160
 
        self.assertEqualMode(02775, b.bzrdir._get_dir_mode())
161
 
        self.assertEqualMode(0664, b.bzrdir._get_file_mode())
162
147
 
163
148
        open('a', 'wb').write('foo4\n')
164
149
        t.commit('foo4')
169
154
        t.commit('new d')
170
155
        check_mode_r(self, '.bzr', 0664, 02775)
171
156
 
 
157
    def test_disable_set_mode(self):
 
158
        # TODO: jam 20051215 Ultimately, this test should probably test that
 
159
        #                    extra chmod calls aren't being made
 
160
        try:
 
161
            transport = get_transport(self.get_url())
 
162
            transport.put_bytes('my-lock', '')
 
163
            lockable = LockableFiles(transport, 'my-lock', TransportLock)
 
164
            self.assertNotEqual(None, lockable._dir_mode)
 
165
            self.assertNotEqual(None, lockable._file_mode)
 
166
 
 
167
            LockableFiles._set_dir_mode = False
 
168
            transport = get_transport('.')
 
169
            lockable = LockableFiles(transport, 'my-lock', TransportLock)
 
170
            self.assertEqual(None, lockable._dir_mode)
 
171
            self.assertNotEqual(None, lockable._file_mode)
 
172
 
 
173
            LockableFiles._set_file_mode = False
 
174
            transport = get_transport('.')
 
175
            lockable = LockableFiles(transport, 'my-lock', TransportLock)
 
176
            self.assertEqual(None, lockable._dir_mode)
 
177
            self.assertEqual(None, lockable._file_mode)
 
178
 
 
179
            LockableFiles._set_dir_mode = True
 
180
            transport = get_transport('.')
 
181
            lockable = LockableFiles(transport, 'my-lock', TransportLock)
 
182
            self.assertNotEqual(None, lockable._dir_mode)
 
183
            self.assertEqual(None, lockable._file_mode)
 
184
 
 
185
            LockableFiles._set_file_mode = True
 
186
            transport = get_transport('.')
 
187
            lockable = LockableFiles(transport, 'my-lock', TransportLock)
 
188
            self.assertNotEqual(None, lockable._dir_mode)
 
189
            self.assertNotEqual(None, lockable._file_mode)
 
190
        finally:
 
191
            LockableFiles._set_dir_mode = True
 
192
            LockableFiles._set_file_mode = True
 
193
 
172
194
 
173
195
class TestSftpPermissions(TestCaseWithSFTPServer):
174
196
 
197
219
        b_local = t.branch
198
220
        self.assertEqualMode(0755, b_local.control_files._dir_mode)
199
221
        self.assertEqualMode(0644, b_local.control_files._file_mode)
200
 
        self.assertEqualMode(0755, b_local.bzrdir._get_dir_mode())
201
 
        self.assertEqualMode(0644, b_local.bzrdir._get_file_mode())
202
222
 
203
223
        os.mkdir('sftp')
204
224
        sftp_url = self.get_url('sftp')
212
232
        b_sftp = Branch.open(sftp_url)
213
233
        self.assertEqualMode(0755, b_sftp.control_files._dir_mode)
214
234
        self.assertEqualMode(0644, b_sftp.control_files._file_mode)
215
 
        self.assertEqualMode(0755, b_sftp.bzrdir._get_dir_mode())
216
 
        self.assertEqualMode(0644, b_sftp.bzrdir._get_file_mode())
217
235
 
218
236
        open('local/a', 'wb').write('foo2\n')
219
237
        t_local.commit('foo2')
235
253
        b_sftp = Branch.open(sftp_url)
236
254
        self.assertEqualMode(0775, b_sftp.control_files._dir_mode)
237
255
        self.assertEqualMode(0664, b_sftp.control_files._file_mode)
238
 
        self.assertEqualMode(0775, b_sftp.bzrdir._get_dir_mode())
239
 
        self.assertEqualMode(0664, b_sftp.bzrdir._get_file_mode())
240
256
 
241
257
        open('local/a', 'wb').write('foo3\n')
242
258
        t_local.commit('foo3')