2
# Author: Manuel de la Pena <manuel@canonical.com>
4
# Copyright 2011 Canonical Ltd.
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Specific tests for the os_helper on Windows."""
21
from win32api import GetUserName
23
from ntsecuritycon import (
28
from ubuntuone.platform.windows.os_helper import (
33
from contrib.testing.testcase import BaseTwistedTestCase
35
class OSWrapperTests(BaseTwistedTestCase):
36
"""Test specific windows implementation details."""
39
"""Setup for the tests."""
40
super(OSWrapperTests, self).setUp()
41
self.basedir = self.mktemp('test_root')
42
self.testfile = os.path.join(self.basedir, "test_file")
43
self.fd = open(self.testfile, 'w')
46
"""Clean the env for the next test."""
48
self.rmtree(self.basedir)
49
super(OSWrapperTests, self).tearDown()
51
def test_access_no_rights(self):
52
"""Test when the sid is not present."""
53
# remove all the rights from the test file so that
54
# we cannot read or write
55
set_no_rights(self.testfile)
56
self.assertFalse(access(self.testfile))
58
def test_access_read_write_user(self):
59
"""Test when the user sid has rw rights."""
60
# set the file to be read and write just by the user
62
groups[GetUserName()] = FILE_GENERIC_READ | FILE_GENERIC_WRITE
63
_set_file_attributes(self.testfile, groups)
64
self.assertTrue(access(self.testfile))
66
def test_access_read_write_everyone(self):
67
"""Test when the everyone sid has rw rights."""
69
groups['Everyone'] = FILE_GENERIC_READ | FILE_GENERIC_WRITE
70
_set_file_attributes(self.testfile, groups)
71
self.assertTrue(access(self.testfile))
73
def test_access_write_user_everyone_read(self):
74
"""Test when the user sid has w rights."""
76
groups[GetUserName()] = FILE_GENERIC_WRITE
77
groups['Everyone'] = FILE_GENERIC_READ
78
_set_file_attributes(self.testfile, groups)
79
self.assertTrue(access(self.testfile))
81
def test_access_write_everyone_user_read(self):
82
"""Test when the everyone sid has w rights"""
84
groups[GetUserName()] = FILE_GENERIC_READ
85
groups['Everyone'] = FILE_GENERIC_WRITE
86
_set_file_attributes(self.testfile, groups)
87
self.assertTrue(access(self.testfile))
89
def test_access_write_user_everyone(self):
90
"""Test when everyone and user have w rights."""
92
groups[GetUserName()] = FILE_GENERIC_WRITE
93
groups['Everyone'] = FILE_GENERIC_WRITE
94
_set_file_attributes(self.testfile, groups)
95
self.assertFalse(access(self.testfile))
97
def test_access_read_user(self):
98
"""Test when the sid has r rights."""
100
groups[GetUserName()] = FILE_GENERIC_READ
101
_set_file_attributes(self.testfile, groups)
102
self.assertTrue(access(self.testfile))
104
def test_access_read_everyone(self):
105
"""Test when everyone has r rights."""
107
groups['Everyone'] = FILE_GENERIC_READ
108
_set_file_attributes(self.testfile, groups)
109
self.assertTrue(access(self.testfile))
111
def test_access_read_user_everyone(self):
112
"""Test when user and everyone have r rights."""
114
groups[GetUserName()] = FILE_GENERIC_READ
115
groups['Everyone'] = FILE_GENERIC_READ
116
_set_file_attributes(self.testfile, groups)
117
self.assertTrue(access(self.testfile))
119
def test_access_full_user(self):
120
"""Test when the sid has full control."""
122
groups[GetUserName()] = FILE_ALL_ACCESS
123
_set_file_attributes(self.testfile, groups)
124
self.assertTrue(access(self.testfile))
126
def test_access_full_everyone(self):
127
"""test when everyone has full control."""
129
groups['Everyone'] = FILE_ALL_ACCESS
130
_set_file_attributes(self.testfile, groups)
131
self.assertTrue(access(self.testfile))