|
1
|
|
|
import random |
|
2
|
|
|
|
|
3
|
|
|
from nextcloud.base import Permission, QUOTA_UNLIMITED |
|
4
|
|
|
|
|
5
|
|
|
from .base import BaseTestCase |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class TestGroupFolders(BaseTestCase): |
|
9
|
|
|
|
|
10
|
|
|
def setUp(self): |
|
11
|
|
|
super(TestGroupFolders, self).setUp() |
|
12
|
|
|
self.nxc.enable_app('groupfolders') |
|
13
|
|
|
|
|
14
|
|
|
def test_crud_group_folder(self): |
|
15
|
|
|
# create new group folder |
|
16
|
|
|
folder_mount_point = "test_group_folders_" + self.get_random_string(length=4) |
|
17
|
|
|
res = self.nxc.create_group_folder(folder_mount_point) |
|
18
|
|
|
assert res.is_ok |
|
19
|
|
|
group_folder_id = res.data['id'] |
|
20
|
|
|
|
|
21
|
|
|
# get all group folders and check if just created folder is in the list |
|
22
|
|
|
res = self.nxc.get_group_folders() |
|
23
|
|
|
assert res.is_ok |
|
24
|
|
|
group_folders = res.data |
|
25
|
|
|
assert str(group_folder_id) in group_folders |
|
26
|
|
|
assert group_folders[str(group_folder_id)]['mount_point'] == folder_mount_point |
|
27
|
|
|
|
|
28
|
|
|
# retrieve single folder |
|
29
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
30
|
|
|
assert res.is_ok |
|
31
|
|
|
assert str(res.data['id']) == str(group_folder_id) |
|
32
|
|
|
assert res.data['mount_point'] == folder_mount_point |
|
33
|
|
|
|
|
34
|
|
|
# rename group folder |
|
35
|
|
|
new_folder_mount_point = folder_mount_point + '_new' |
|
36
|
|
|
res = self.nxc.rename_group_folder(group_folder_id, new_folder_mount_point) |
|
37
|
|
|
assert res.is_ok and res.data is True |
|
38
|
|
|
# check if name was changed |
|
39
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
40
|
|
|
assert res.data['mount_point'] == new_folder_mount_point |
|
41
|
|
|
|
|
42
|
|
|
# delete group folder |
|
43
|
|
|
res = self.nxc.delete_group_folder(group_folder_id) |
|
44
|
|
|
assert res.is_ok |
|
45
|
|
|
assert res.data is True |
|
46
|
|
|
# check that deleted folder isn't retrieved |
|
47
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
48
|
|
|
assert res.is_ok |
|
49
|
|
|
assert res.data is False |
|
50
|
|
|
|
|
51
|
|
|
def test_group_folder_search(self): |
|
52
|
|
|
# create new group folder |
|
53
|
|
|
group_folders = {} |
|
54
|
|
|
folder_mount_point_base = "test_group_folders_search" |
|
55
|
|
|
for i in range(5): |
|
56
|
|
|
folder_mount_point = "{}_{}".format(folder_mount_point_base, i) |
|
57
|
|
|
res = self.nxc.create_group_folder(folder_mount_point) |
|
58
|
|
|
assert res.is_ok |
|
59
|
|
|
group_folders[str(res.data['id'])] = folder_mount_point |
|
|
|
|
|
|
60
|
|
|
folder_to_search_id = random.choice(list(group_folders.keys())) |
|
61
|
|
|
folder_to_search_mount = group_folders[folder_to_search_id] |
|
62
|
|
|
res = self.nxc.get_group_folders(mount_point=folder_to_search_mount) |
|
63
|
|
|
assert len(res.data) == 1 |
|
64
|
|
|
assert list(res.data.keys())[0] == folder_to_search_id |
|
65
|
|
|
assert res.data[folder_to_search_id]['mount_point'] == folder_to_search_mount |
|
66
|
|
|
|
|
67
|
|
|
def test_grant_revoke_access_to_group_folder(self): |
|
68
|
|
|
# create group to share with |
|
69
|
|
|
group_id = 'test_folders_' + self.get_random_string(length=4) |
|
70
|
|
|
self.nxc.add_group(group_id) |
|
71
|
|
|
|
|
72
|
|
|
# create new group folder |
|
73
|
|
|
folder_mount_point = "test_access_" + self.get_random_string(length=4) |
|
74
|
|
|
res = self.nxc.create_group_folder(folder_mount_point) |
|
75
|
|
|
group_folder_id = res.data['id'] |
|
76
|
|
|
|
|
77
|
|
|
# assert that no groups have access to just created folder |
|
78
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
79
|
|
|
assert len(res.data['groups']) == 0 |
|
80
|
|
|
|
|
81
|
|
|
# grant access to group |
|
82
|
|
|
res = self.nxc.grant_access_to_group_folder(group_folder_id, group_id) |
|
83
|
|
|
assert res.is_ok |
|
84
|
|
|
assert res.data is True |
|
85
|
|
|
|
|
86
|
|
|
# check that folder has this group |
|
87
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
88
|
|
|
assert res.data['groups'] == {group_id: str(Permission.ALL.value)} |
|
89
|
|
|
|
|
90
|
|
|
# revoke access |
|
91
|
|
|
res = self.nxc.revoke_access_to_group_folder(group_folder_id, group_id) |
|
92
|
|
|
assert res.is_ok |
|
93
|
|
|
assert res.data is True |
|
94
|
|
|
|
|
95
|
|
|
# check that folder has no groups again |
|
96
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
97
|
|
|
assert len(res.data['groups']) == 0 |
|
98
|
|
|
|
|
99
|
|
|
# clear |
|
100
|
|
|
self.clear(nxc=self.nxc, group_ids=[group_id], group_folder_ids=[group_folder_id]) |
|
101
|
|
|
|
|
102
|
|
|
def test_setting_folder_quotas(self): |
|
103
|
|
|
# create new group folder |
|
104
|
|
|
folder_mount_point = "test_folder_quotas_" + self.get_random_string(length=4) |
|
105
|
|
|
res = self.nxc.create_group_folder(folder_mount_point) |
|
106
|
|
|
group_folder_id = res.data['id'] |
|
107
|
|
|
|
|
108
|
|
|
# assert quota is unlimited by default |
|
109
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
110
|
|
|
assert int(res.data['quota']) == QUOTA_UNLIMITED |
|
111
|
|
|
|
|
112
|
|
|
# set quota |
|
113
|
|
|
QUOTA_ONE_GB = 1024 * 1024 * 1024 |
|
114
|
|
|
res = self.nxc.set_quota_of_group_folder(group_folder_id, QUOTA_ONE_GB) |
|
115
|
|
|
assert res.is_ok and res.data is True |
|
116
|
|
|
# check if quota changed |
|
117
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
118
|
|
|
assert str(res.data['quota']) == str(QUOTA_ONE_GB) |
|
119
|
|
|
|
|
120
|
|
|
# clear |
|
121
|
|
|
self.clear(group_folder_ids=[group_folder_id]) |
|
122
|
|
|
|
|
123
|
|
|
def test_setting_folder_permissions(self): |
|
124
|
|
|
# create group to share with |
|
125
|
|
|
group_id = 'test_folders_' + self.get_random_string(length=4) |
|
126
|
|
|
self.nxc.add_group(group_id) |
|
127
|
|
|
|
|
128
|
|
|
# create new group folder |
|
129
|
|
|
folder_mount_point = "test_folder_permissions_" + self.get_random_string(length=4) |
|
130
|
|
|
res = self.nxc.create_group_folder(folder_mount_point) |
|
131
|
|
|
group_folder_id = res.data['id'] |
|
132
|
|
|
|
|
133
|
|
|
# add new group to folder |
|
134
|
|
|
self.nxc.grant_access_to_group_folder(group_folder_id, group_id) |
|
135
|
|
|
# assert permissions is ALL by default |
|
136
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
137
|
|
|
assert int(res.data['quota']) == QUOTA_UNLIMITED |
|
138
|
|
|
|
|
139
|
|
|
# set permissions |
|
140
|
|
|
new_permission = Permission.READ + Permission.CREATE |
|
141
|
|
|
res = self.nxc.set_permissions_to_group_folder(group_folder_id, group_id, new_permission) |
|
142
|
|
|
assert res.is_ok |
|
143
|
|
|
assert res.data is True |
|
144
|
|
|
# check if permissions changed |
|
145
|
|
|
res = self.nxc.get_group_folder(group_folder_id) |
|
146
|
|
|
assert str(res.data['groups'][group_id]) == str(new_permission) |
|
147
|
|
|
|
|
148
|
|
|
# clear |
|
149
|
|
|
self.clear(nxc=self.nxc, group_ids=[group_id], group_folder_ids=[group_folder_id]) |
|
150
|
|
|
|