|
| 1 | + |
| 2 | +__doc__ = """ |
| 3 | +
|
| 4 | +Test basic file remote-sharing between users. |
| 5 | +
|
| 6 | ++-----------+----------------------+------------------+----------------------------+ |
| 7 | +| Step | Sharer | Sharee One | Sharee Two | |
| 8 | +| Number | | | | |
| 9 | ++===========+======================+==================+============================| |
| 10 | +| 2 | create work dir | create work dir | create work dir | |
| 11 | ++-----------+----------------------+------------------+----------------------------+ |
| 12 | +| 3 | Create test files | | | |
| 13 | ++-----------+----------------------+------------------+----------------------------+ |
| 14 | +| 4 | Shares files with | | | |
| 15 | +| | Sharee One | | | |
| 16 | ++-----------+----------------------+------------------+----------------------------+ |
| 17 | +| 5 | | Syncs and | | |
| 18 | +| | | validates files | | |
| 19 | ++-----------+----------------------+------------------+----------------------------+ |
| 20 | +| 6 | | modifies one | | |
| 21 | +| | | files, if | | |
| 22 | +| | | permitted | | |
| 23 | ++-----------+----------------------+------------------+----------------------------+ |
| 24 | +| 7 | Validates modified | | | |
| 25 | +| | file or not, based | | | |
| 26 | +| | on permissions | | | |
| 27 | ++-----------+----------------------+------------------+----------------------------+ |
| 28 | +| 8 | | Shares a file | | |
| 29 | +| | | with sharee two | | |
| 30 | +| | | if permitted | | |
| 31 | ++-----------+----------------------+------------------+----------------------------+ |
| 32 | +| 9 | | | Syncs and validates | |
| 33 | +| | | |file is shared if permitted | |
| 34 | ++-----------+----------------------+------------------+----------------------------+ |
| 35 | +| 10 | Sharer unshares a | | | |
| 36 | +| | file | | | |
| 37 | ++-----------+----------------------+------------------+----------------------------+ |
| 38 | +| 11 | | Syncs and | Syncs and validates | |
| 39 | +| | | validates file | file not present | |
| 40 | +| | | not present | | |
| 41 | ++-----------+----------------------+------------------+----------------------------+ |
| 42 | +| 12 | Sharer deletes a | | | |
| 43 | +| | file | | | |
| 44 | ++-----------+----------------------+------------------+----------------------------+ |
| 45 | +| 13 | | Syncs and | | |
| 46 | +| | | validates file | | |
| 47 | +| | | not present | | |
| 48 | ++-----------+----------------------+------------------+----------------------------+ |
| 49 | +| 14 | Final step | Final step | Final Step | |
| 50 | ++-----------+----------------------+------------------+----------------------------+ |
| 51 | +
|
| 52 | +
|
| 53 | +Data Providers: |
| 54 | +
|
| 55 | + test_sharePermissions: Permissions to be applied to the share |
| 56 | +
|
| 57 | +""" |
| 58 | + |
| 59 | +from smashbox.utilities import * |
| 60 | +from smashbox.owncloudorg.remote_sharing import * |
| 61 | + |
| 62 | +OCS_PERMISSION_READ = 1 |
| 63 | +OCS_PERMISSION_UPDATE = 2 |
| 64 | +OCS_PERMISSION_CREATE = 4 |
| 65 | +OCS_PERMISSION_DELETE = 8 |
| 66 | +OCS_PERMISSION_SHARE = 16 |
| 67 | +OCS_PERMISSION_ALL = 31 |
| 68 | + |
| 69 | +filesizeKB = int(config.get('share_filesizeKB', 10)) |
| 70 | +sharePermissions = int(config.get('test_sharePermissions', OCS_PERMISSION_ALL)) |
| 71 | + |
| 72 | +testsets = [ |
| 73 | + { |
| 74 | + 'test_sharePermissions': OCS_PERMISSION_ALL |
| 75 | + }, |
| 76 | + { |
| 77 | + 'test_sharePermissions': OCS_PERMISSION_READ | OCS_PERMISSION_UPDATE |
| 78 | + }, |
| 79 | + { |
| 80 | + 'test_sharePermissions': OCS_PERMISSION_READ | OCS_PERMISSION_SHARE |
| 81 | + } |
| 82 | +] |
| 83 | + |
| 84 | + |
| 85 | +@add_worker |
| 86 | +def sharer(step): |
| 87 | + |
| 88 | + step(2, 'Create workdir') |
| 89 | + d = make_workdir() |
| 90 | + |
| 91 | + step(3, 'Create initial test files and directories') |
| 92 | + |
| 93 | + createfile(os.path.join(d, 'TEST_FILE_USER_SHARE.dat'), '0', count=1000, bs=filesizeKB) |
| 94 | + createfile(os.path.join(d, 'TEST_FILE_USER_RESHARE.dat'), '0', count=1000, bs=filesizeKB) |
| 95 | + createfile(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat'), '0', count=1000, bs=filesizeKB) |
| 96 | + |
| 97 | + shared = reflection.getSharedObject() |
| 98 | + shared['md5_sharer'] = md5sum(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat')) |
| 99 | + logger.info('md5_sharer: %s', shared['md5_sharer']) |
| 100 | + |
| 101 | + list_files(d) |
| 102 | + run_ocsync(d, user_num=1) |
| 103 | + list_files(d) |
| 104 | + |
| 105 | + step(4, 'Sharer shares files') |
| 106 | + |
| 107 | + user1 = "%s%i" % (config.oc_account_name, 1) |
| 108 | + user2 = "%s%i" % (config.oc_account_name, 2) |
| 109 | + |
| 110 | + kwargs = {'perms': sharePermissions} |
| 111 | + shared['TEST_FILE_USER_SHARE'] = remote_share_file_with_user( |
| 112 | + 'TEST_FILE_USER_SHARE.dat', user1, user2, **kwargs |
| 113 | + ) |
| 114 | + shared['TEST_FILE_USER_RESHARE'] = remote_share_file_with_user( |
| 115 | + 'TEST_FILE_USER_RESHARE.dat', user1, user2, **kwargs |
| 116 | + ) |
| 117 | + shared['TEST_FILE_MODIFIED_USER_SHARE'] = remote_share_file_with_user( |
| 118 | + 'TEST_FILE_MODIFIED_USER_SHARE.dat', user1, user2, **kwargs |
| 119 | + ) |
| 120 | + shared['sharer.TEST_FILE_MODIFIED_USER_SHARE'] = os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat') |
| 121 | + |
| 122 | + step(7, 'Sharer validates modified file') |
| 123 | + run_ocsync(d, user_num=1) |
| 124 | + |
| 125 | + if not sharePermissions & OCS_PERMISSION_UPDATE: |
| 126 | + expect_not_modified(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat'), shared['md5_sharer']) |
| 127 | + else: |
| 128 | + expect_modified(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat'), shared['md5_sharer']) |
| 129 | + |
| 130 | + step(10, 'Sharer unshares a file') |
| 131 | + delete_share(user1, shared['TEST_FILE_USER_RESHARE']) |
| 132 | + |
| 133 | + step(12, 'Sharer deletes file') |
| 134 | + |
| 135 | + list_files(d) |
| 136 | + remove_file(os.path.join(d, 'TEST_FILE_USER_SHARE.dat')) |
| 137 | + run_ocsync(d, user_num=1) |
| 138 | + list_files(d) |
| 139 | + |
| 140 | + step(14, 'Sharer final step') |
| 141 | + |
| 142 | + |
| 143 | +@add_worker |
| 144 | +def sharee_one(step): |
| 145 | + |
| 146 | + step(2, 'Sharee One creates workdir') |
| 147 | + d = make_workdir() |
| 148 | + |
| 149 | + step(5, 'Sharee One syncs and validate files exist') |
| 150 | + |
| 151 | + run_ocsync(d, user_num=2) |
| 152 | + list_files(d) |
| 153 | + |
| 154 | + # Accept the remote shares for user2 |
| 155 | + user2 = "%s%i" % (config.oc_account_name, 2) |
| 156 | + openShares = list_open_remote_share(user2) |
| 157 | + for share in openShares: |
| 158 | + accept_remote_share(user2, int(share['id'])) |
| 159 | + sleep(5) |
| 160 | + |
| 161 | + run_ocsync(d, user_num=2) |
| 162 | + list_files(d) |
| 163 | + |
| 164 | + shared_file = os.path.join(d, 'TEST_FILE_USER_SHARE.dat') |
| 165 | + logger.info('Checking that %s is present in local directory for Sharee One', shared_file) |
| 166 | + expect_exists(shared_file) |
| 167 | + |
| 168 | + shared_file = os.path.join(d, 'TEST_FILE_USER_RESHARE.dat') |
| 169 | + logger.info('Checking that %s is present in local directory for Sharee One', shared_file) |
| 170 | + expect_exists(shared_file) |
| 171 | + |
| 172 | + shared_file = os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat') |
| 173 | + logger.info('Checking that %s is present in local directory for Sharee One', shared_file) |
| 174 | + expect_exists(shared_file) |
| 175 | + |
| 176 | + step(6, 'Sharee One modifies TEST_FILE_MODIFIED_USER_SHARE.dat') |
| 177 | + |
| 178 | + modify_file(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat'), '1', count=10, bs=filesizeKB) |
| 179 | + run_ocsync(d, user_num=2) |
| 180 | + list_files(d) |
| 181 | + |
| 182 | + shared = reflection.getSharedObject() |
| 183 | + if not sharePermissions & OCS_PERMISSION_UPDATE: |
| 184 | + # local file is modified, but not synced so the owner still has the right file |
| 185 | + list_files(d) |
| 186 | + expect_modified(os.path.join(d, 'TEST_FILE_MODIFIED_USER_SHARE.dat'), shared['md5_sharer']) |
| 187 | + expect_not_modified(shared['sharer.TEST_FILE_MODIFIED_USER_SHARE'], shared['md5_sharer']) |
| 188 | + |
| 189 | + step(8, 'Sharee One share files with user 3') |
| 190 | + |
| 191 | + user2 = "%s%i" % (config.oc_account_name, 2) |
| 192 | + user3 = "%s%i" % (config.oc_account_name, 3) |
| 193 | + kwargs = {'perms': sharePermissions} |
| 194 | + result = remote_share_file_with_user('TEST_FILE_USER_RESHARE.dat', user2, user3, **kwargs) |
| 195 | + |
| 196 | + # FIXME Remote sharing ignores the share permission for now, so sharing should always work: |
| 197 | + # FIXME https://github.com/owncloud/core/issues/22495 |
| 198 | + # if not sharePermissions & OCS_PERMISSION_SHARE: |
| 199 | + # error_check(result != -1, "An error should have occurred while sharing the file, but it worked") |
| 200 | + # else: |
| 201 | + # error_check(result != -1, "An error occurred while sharing the file") |
| 202 | + error_check(result != -1, "An error occurred while sharing the file") |
| 203 | + |
| 204 | + step(11, 'Sharee one validates file does not exist after unsharing') |
| 205 | + |
| 206 | + run_ocsync(d, user_num=2) |
| 207 | + list_files(d) |
| 208 | + |
| 209 | + shared_file = os.path.join(d, 'TEST_FILE_USER_RESHARE.dat') |
| 210 | + logger.info('Checking that %s is not present in sharee local directory', shared_file) |
| 211 | + expect_does_not_exist(shared_file) |
| 212 | + |
| 213 | + step(13, 'Sharee syncs and validates file does not exist') |
| 214 | + |
| 215 | + run_ocsync(d, user_num=2) |
| 216 | + list_files(d) |
| 217 | + |
| 218 | + # May seem weird, but that is the current behaviour. The file is still there locally, |
| 219 | + # but on the server the entry is a StorageNotAvailable exception, so webdav exists should not pass. |
| 220 | + shared_file = os.path.join(d, 'TEST_FILE_USER_SHARE.dat') |
| 221 | + logger.info('Checking that %s is present in sharee locally but not on webdav directory', shared_file) |
| 222 | + expect_exists(shared_file) |
| 223 | + expect_webdav_does_not_exist(shared_file, user_num=2) |
| 224 | + |
| 225 | + step(14, 'Sharee One final step') |
| 226 | + |
| 227 | + |
| 228 | +@add_worker |
| 229 | +def sharee_two(step): |
| 230 | + |
| 231 | + step(2, 'Sharee Two creates workdir') |
| 232 | + d = make_workdir() |
| 233 | + |
| 234 | + step(9, 'Sharee two validates share file') |
| 235 | + |
| 236 | + run_ocsync(d, user_num=3) |
| 237 | + list_files(d) |
| 238 | + |
| 239 | + # Accept the remote shares for user3 |
| 240 | + user3 = "%s%i" % (config.oc_account_name, 3) |
| 241 | + openShares = list_open_remote_share(user3) |
| 242 | + for share in openShares: |
| 243 | + accept_remote_share(user3, int(share['id'])) |
| 244 | + |
| 245 | + run_ocsync(d, user_num=3) |
| 246 | + list_files(d) |
| 247 | + |
| 248 | + shared_file = os.path.join(d, 'TEST_FILE_USER_RESHARE.dat') |
| 249 | + |
| 250 | + # FIXME Remote sharing ignores the share permission for now, so sharing should always work: |
| 251 | + # FIXME https://github.com/owncloud/core/issues/22495 |
| 252 | + # if not sharePermissions & OCS_PERMISSION_SHARE: |
| 253 | + # logger.info('Checking that %s is not present in local directory for Sharee Two', shared_file) |
| 254 | + # expect_does_not_exist(shared_file) |
| 255 | + # else: |
| 256 | + # logger.info('Checking that %s is present in local directory for Sharee Two', shared_file) |
| 257 | + # expect_exists(shared_file) |
| 258 | + logger.info('Checking that %s is present in local directory for Sharee Two', shared_file) |
| 259 | + expect_exists(shared_file) |
| 260 | + |
| 261 | + step(11, 'Sharee two validates file does not exist after unsharing') |
| 262 | + |
| 263 | + run_ocsync(d, user_num=3) |
| 264 | + list_files(d) |
| 265 | + |
| 266 | + shared_file = os.path.join(d, 'TEST_FILE_USER_RESHARE.dat') |
| 267 | + |
| 268 | + # FIXME Remote sharing ignores the share permission for now, so sharing should always work: |
| 269 | + # FIXME https://github.com/owncloud/core/issues/22495 |
| 270 | + # if not sharePermissions & OCS_PERMISSION_SHARE: |
| 271 | + # logger.info('Checking that %s is not present in sharee locally or the webdav directory', shared_file) |
| 272 | + # expect_does_not_exist(shared_file) |
| 273 | + # expect_webdav_does_not_exist(shared_file, user_num=3) |
| 274 | + # else: |
| 275 | + # # May seem weird, but that is the current behaviour. The file is still there locally, |
| 276 | + # # but on the server the entry is a StorageNotAvailable exception, so webdav exists should not pass. |
| 277 | + # logger.info('Checking that %s is present in sharee locally but not on webdav directory', shared_file) |
| 278 | + # expect_exists(shared_file) |
| 279 | + # expect_webdav_does_not_exist(shared_file, user_num=3) |
| 280 | + logger.info('Checking that %s is present in sharee locally but not on webdav directory', shared_file) |
| 281 | + expect_exists(shared_file) |
| 282 | + expect_webdav_does_not_exist(shared_file, user_num=3) |
| 283 | + |
| 284 | + step(14, 'Sharee Two final step') |
0 commit comments