|
| 1 | +from smashbox.utilities import * |
| 2 | + |
| 3 | +__doc__ = """ |
| 4 | +
|
| 5 | +Test basic file sharing by link |
| 6 | +
|
| 7 | +Covers: |
| 8 | + * Single file share: https://github.com/owncloud/core/pull/19619 |
| 9 | + * Folder share, single file direct download (click on file list) |
| 10 | + * Folder share, select single file and download (checkbox) |
| 11 | + * Folder share, select multiple files and download (checkbox) |
| 12 | + * Folder share, download full folder |
| 13 | +
|
| 14 | +""" |
| 15 | + |
| 16 | + |
| 17 | +filesize_kb = int(config.get('share_filesizeKB', 10)) |
| 18 | + |
| 19 | +test_downloader = config.get('test_downloader', 'full_folder') |
| 20 | + |
| 21 | +testsets = [ |
| 22 | + { |
| 23 | + 'test_downloader': 'single_file' |
| 24 | + }, |
| 25 | + { |
| 26 | + 'test_downloader': 'direct_single_files' |
| 27 | + }, |
| 28 | + { |
| 29 | + 'test_downloader': 'selected_single_files' |
| 30 | + }, |
| 31 | + { |
| 32 | + 'test_downloader': 'full_folder' |
| 33 | + }, |
| 34 | + { |
| 35 | + 'test_downloader': 'full_subfolder' |
| 36 | + }, |
| 37 | + { |
| 38 | + 'test_downloader': 'selected_files' |
| 39 | + } |
| 40 | +] |
| 41 | + |
| 42 | + |
| 43 | +@add_worker |
| 44 | +def setup(step): |
| 45 | + |
| 46 | + step(1, 'create test users') |
| 47 | + reset_owncloud_account(num_test_users=2) |
| 48 | + check_users(2) |
| 49 | + |
| 50 | + reset_rundir() |
| 51 | + reset_server_log_file() |
| 52 | + |
| 53 | + step(6, 'Validate server log file is clean') |
| 54 | + |
| 55 | + d = make_workdir() |
| 56 | + scrape_log_file(d) |
| 57 | + |
| 58 | + |
| 59 | +@add_worker |
| 60 | +def sharer(step): |
| 61 | + |
| 62 | + step(2, 'Create workdir') |
| 63 | + d = make_workdir() |
| 64 | + |
| 65 | + step(3, 'Create initial test files and directories') |
| 66 | + |
| 67 | + proc_name = reflection.getProcessName() |
| 68 | + dir_name = os.path.join(proc_name, 'localShareDir') |
| 69 | + local_dir = make_workdir(dir_name) |
| 70 | + subdir_dir = make_workdir(os.path.join(dir_name, 'subdir')) |
| 71 | + |
| 72 | + createfile(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE1.txt'), '1', count=1000, bs=filesize_kb) |
| 73 | + createfile(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE2.txt'), '2', count=1000, bs=filesize_kb) |
| 74 | + createfile(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE3.txt'), '3', count=1000, bs=filesize_kb) |
| 75 | + createfile(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE4.txt'), '4', count=1000, bs=filesize_kb) |
| 76 | + createfile(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE5.txt'), '5', count=1000, bs=filesize_kb) |
| 77 | + createfile(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE6.txt'), '6', count=1000, bs=filesize_kb) |
| 78 | + shared = reflection.getSharedObject() |
| 79 | + shared['MD5_TEST_FILE_LINK_SHARE1'] = md5sum(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE1.txt')) |
| 80 | + shared['MD5_TEST_FILE_LINK_SHARE2'] = md5sum(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE2.txt')) |
| 81 | + shared['MD5_TEST_FILE_LINK_SHARE3'] = md5sum(os.path.join(local_dir, 'TEST_FILE_LINK_SHARE3.txt')) |
| 82 | + shared['MD5_TEST_FILE_LINK_SHARE4'] = md5sum(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE4.txt')) |
| 83 | + shared['MD5_TEST_FILE_LINK_SHARE5'] = md5sum(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE5.txt')) |
| 84 | + shared['MD5_TEST_FILE_LINK_SHARE6'] = md5sum(os.path.join(subdir_dir, 'TEST_FILE_LINK_SHARE6.txt')) |
| 85 | + |
| 86 | + list_files(d) |
| 87 | + run_ocsync(d, user_num=1) |
| 88 | + list_files(d) |
| 89 | + |
| 90 | + step(4, 'Sharer shares file as link') |
| 91 | + |
| 92 | + oc_api = get_oc_api() |
| 93 | + oc_api.login("%s%i" % (config.oc_account_name, 1), config.oc_account_password) |
| 94 | + |
| 95 | + kwargs = {'perms': 31} |
| 96 | + share = oc_api.share_file_with_link(os.path.join('localShareDir', 'TEST_FILE_LINK_SHARE1.txt'), **kwargs) |
| 97 | + shared['SHARE_LINK_TOKEN_TEST_FILE_LINK_SHARE1'] = share.token |
| 98 | + share = oc_api.share_file_with_link('localShareDir', **kwargs) |
| 99 | + shared['SHARE_LINK_TOKEN_TEST_DIR'] = share.token |
| 100 | + |
| 101 | + |
| 102 | +def public_downloader_single_file(step): |
| 103 | + |
| 104 | + step(2, 'Create workdir') |
| 105 | + d = make_workdir() |
| 106 | + |
| 107 | + step(5, 'Downloads and validate') |
| 108 | + |
| 109 | + shared = reflection.getSharedObject() |
| 110 | + url = oc_webdav_url( |
| 111 | + remote_folder=os.path.join('index.php', 's', shared['SHARE_LINK_TOKEN_TEST_FILE_LINK_SHARE1'], 'download'), |
| 112 | + webdav_endpoint=config.oc_root |
| 113 | + ) |
| 114 | + |
| 115 | + download_target = os.path.join(d, 'TEST_FILE_LINK_SHARE1.txt') |
| 116 | + runcmd('curl -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 117 | + expect_not_modified(download_target, shared['MD5_TEST_FILE_LINK_SHARE1']) |
| 118 | + |
| 119 | + |
| 120 | +def public_downloader_direct_single_files(step): |
| 121 | + |
| 122 | + step(2, 'Create workdir') |
| 123 | + d = make_workdir() |
| 124 | + |
| 125 | + step(5, 'Downloads and validate') |
| 126 | + |
| 127 | + shared = reflection.getSharedObject() |
| 128 | + url = oc_webdav_url( |
| 129 | + remote_folder=os.path.join( |
| 130 | + 'index.php', 's', |
| 131 | + shared['SHARE_LINK_TOKEN_TEST_DIR'], |
| 132 | + 'download?path=%2F&files=TEST_FILE_LINK_SHARE1.txt' |
| 133 | + ), |
| 134 | + webdav_endpoint=config.oc_root |
| 135 | + ) |
| 136 | + |
| 137 | + download_target = os.path.join(d, 'TEST_FILE_LINK_SHARE1.txt') |
| 138 | + runcmd('curl -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 139 | + expect_not_modified(download_target, shared['MD5_TEST_FILE_LINK_SHARE1']) |
| 140 | + |
| 141 | + |
| 142 | +def public_downloader_selected_single_files(step): |
| 143 | + |
| 144 | + step(2, 'Create workdir') |
| 145 | + d = make_workdir() |
| 146 | + |
| 147 | + step(5, 'Downloads and validate') |
| 148 | + |
| 149 | + shared = reflection.getSharedObject() |
| 150 | + url = oc_webdav_url( |
| 151 | + remote_folder=os.path.join( |
| 152 | + 'index.php', 's', |
| 153 | + shared['SHARE_LINK_TOKEN_TEST_DIR'], |
| 154 | + 'download?path=%2F&files=%5B%22TEST_FILE_LINK_SHARE1.txt%22%5D' |
| 155 | + ), |
| 156 | + webdav_endpoint=config.oc_root |
| 157 | + ) |
| 158 | + |
| 159 | + download_target = os.path.join(d, 'TEST_FILE_LINK_SHARE1.txt') |
| 160 | + runcmd('curl -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 161 | + expect_not_modified(download_target, shared['MD5_TEST_FILE_LINK_SHARE1']) |
| 162 | + |
| 163 | + |
| 164 | +def public_downloader_full_folder(step): |
| 165 | + |
| 166 | + step(2, 'Create workdir') |
| 167 | + d = make_workdir() |
| 168 | + |
| 169 | + step(5, 'Downloads and validate') |
| 170 | + |
| 171 | + shared = reflection.getSharedObject() |
| 172 | + url = oc_webdav_url( |
| 173 | + remote_folder=os.path.join('index.php', 's', shared['SHARE_LINK_TOKEN_TEST_DIR'], 'download'), |
| 174 | + webdav_endpoint=config.oc_root |
| 175 | + ) |
| 176 | + |
| 177 | + download_target = os.path.join(d, '%s%s' % (shared['SHARE_LINK_TOKEN_TEST_DIR'], '.zip')) |
| 178 | + unzip_target = os.path.join(d, 'unzip') |
| 179 | + runcmd('curl -v -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 180 | + runcmd('unzip -d %s %s' % (unzip_target, download_target)) |
| 181 | + |
| 182 | + list_files(d, recursive=True) |
| 183 | + |
| 184 | + expect_exists(os.path.join(unzip_target, 'localShareDir')) |
| 185 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE1.txt')) |
| 186 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE2.txt')) |
| 187 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE3.txt')) |
| 188 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'subdir')) |
| 189 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE4.txt')) |
| 190 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE5.txt')) |
| 191 | + expect_exists(os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE6.txt')) |
| 192 | + |
| 193 | + expect_not_modified( |
| 194 | + os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE1.txt'), |
| 195 | + shared['MD5_TEST_FILE_LINK_SHARE1'] |
| 196 | + ) |
| 197 | + expect_not_modified( |
| 198 | + os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE2.txt'), |
| 199 | + shared['MD5_TEST_FILE_LINK_SHARE2'] |
| 200 | + ) |
| 201 | + expect_not_modified( |
| 202 | + os.path.join(unzip_target, 'localShareDir', 'TEST_FILE_LINK_SHARE3.txt'), |
| 203 | + shared['MD5_TEST_FILE_LINK_SHARE3'] |
| 204 | + ) |
| 205 | + expect_not_modified( |
| 206 | + os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE4.txt'), |
| 207 | + shared['MD5_TEST_FILE_LINK_SHARE4'] |
| 208 | + ) |
| 209 | + expect_not_modified( |
| 210 | + os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE5.txt'), |
| 211 | + shared['MD5_TEST_FILE_LINK_SHARE5'] |
| 212 | + ) |
| 213 | + expect_not_modified( |
| 214 | + os.path.join(unzip_target, 'localShareDir', 'subdir', 'TEST_FILE_LINK_SHARE6.txt'), |
| 215 | + shared['MD5_TEST_FILE_LINK_SHARE6'] |
| 216 | + ) |
| 217 | + |
| 218 | + |
| 219 | +def public_downloader_full_subfolder(step): |
| 220 | + |
| 221 | + step(2, 'Create workdir') |
| 222 | + d = make_workdir() |
| 223 | + |
| 224 | + step(5, 'Downloads and validate') |
| 225 | + |
| 226 | + shared = reflection.getSharedObject() |
| 227 | + url = oc_webdav_url( |
| 228 | + remote_folder=os.path.join( |
| 229 | + 'index.php', |
| 230 | + 's', |
| 231 | + shared['SHARE_LINK_TOKEN_TEST_DIR'], |
| 232 | + 'download?path=%2F&files=subdir' |
| 233 | + ), |
| 234 | + webdav_endpoint=config.oc_root |
| 235 | + ) |
| 236 | + |
| 237 | + download_target = os.path.join(d, '%s%s' % (shared['SHARE_LINK_TOKEN_TEST_DIR'], '.zip')) |
| 238 | + unzip_target = os.path.join(d, 'unzip') |
| 239 | + runcmd('curl -v -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 240 | + runcmd('unzip -d %s %s' % (unzip_target, download_target)) |
| 241 | + |
| 242 | + list_files(d, recursive=True) |
| 243 | + |
| 244 | + expect_exists(os.path.join(unzip_target, 'subdir')) |
| 245 | + expect_exists(os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE4.txt')) |
| 246 | + expect_exists(os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE5.txt')) |
| 247 | + expect_exists(os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE6.txt')) |
| 248 | + |
| 249 | + expect_not_modified( |
| 250 | + os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE4.txt'), |
| 251 | + shared['MD5_TEST_FILE_LINK_SHARE4'] |
| 252 | + ) |
| 253 | + expect_not_modified( |
| 254 | + os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE5.txt'), |
| 255 | + shared['MD5_TEST_FILE_LINK_SHARE5'] |
| 256 | + ) |
| 257 | + expect_not_modified( |
| 258 | + os.path.join(unzip_target, 'subdir', 'TEST_FILE_LINK_SHARE6.txt'), |
| 259 | + shared['MD5_TEST_FILE_LINK_SHARE6'] |
| 260 | + ) |
| 261 | + |
| 262 | + |
| 263 | +def public_downloader_selected_files(step): |
| 264 | + |
| 265 | + step(2, 'Create workdir') |
| 266 | + d = make_workdir() |
| 267 | + |
| 268 | + step(5, 'Downloads and validate') |
| 269 | + |
| 270 | + shared = reflection.getSharedObject() |
| 271 | + url = oc_webdav_url( |
| 272 | + remote_folder=os.path.join( |
| 273 | + 'index.php', 's', |
| 274 | + shared['SHARE_LINK_TOKEN_TEST_DIR'], |
| 275 | + 'download?path=%2F&files=%5B%22TEST_FILE_LINK_SHARE1.txt%22%2C%22TEST_FILE_LINK_SHARE2.txt%22%5D' |
| 276 | + ), |
| 277 | + webdav_endpoint=config.oc_root |
| 278 | + ) |
| 279 | + |
| 280 | + download_target = os.path.join(d, '%s%s' % (shared['SHARE_LINK_TOKEN_TEST_DIR'], '.zip')) |
| 281 | + unzip_target = os.path.join(d, 'unzip') |
| 282 | + runcmd('curl -v -k %s -o \'%s\' \'%s\'' % (config.get('curl_opts', ''), download_target, url)) |
| 283 | + runcmd('unzip -d %s %s' % (unzip_target, download_target)) |
| 284 | + |
| 285 | + list_files(d, recursive=True) |
| 286 | + |
| 287 | + expect_does_not_exist(os.path.join(unzip_target, 'localShareDir')) |
| 288 | + expect_exists(os.path.join(unzip_target, 'TEST_FILE_LINK_SHARE1.txt')) |
| 289 | + expect_exists(os.path.join(unzip_target, 'TEST_FILE_LINK_SHARE2.txt')) |
| 290 | + expect_does_not_exist(os.path.join(unzip_target, 'TEST_FILE_LINK_SHARE3.txt')) |
| 291 | + |
| 292 | + expect_not_modified( |
| 293 | + os.path.join(unzip_target, 'TEST_FILE_LINK_SHARE1.txt'), |
| 294 | + shared['MD5_TEST_FILE_LINK_SHARE1'] |
| 295 | + ) |
| 296 | + expect_not_modified( |
| 297 | + os.path.join(unzip_target, 'TEST_FILE_LINK_SHARE2.txt'), |
| 298 | + shared['MD5_TEST_FILE_LINK_SHARE2'] |
| 299 | + ) |
| 300 | + |
| 301 | + |
| 302 | +if test_downloader == 'single_file': |
| 303 | + add_worker(public_downloader_single_file, name=test_downloader) |
| 304 | +elif test_downloader == 'direct_single_files': |
| 305 | + add_worker(public_downloader_direct_single_files, name=test_downloader) |
| 306 | +elif test_downloader == 'selected_single_files': |
| 307 | + add_worker(public_downloader_selected_single_files, name=test_downloader) |
| 308 | +elif test_downloader == 'full_folder': |
| 309 | + add_worker(public_downloader_full_folder, name=test_downloader) |
| 310 | +elif test_downloader == 'full_subfolder': |
| 311 | + add_worker(public_downloader_full_subfolder, name=test_downloader) |
| 312 | +elif test_downloader == 'selected_files': |
| 313 | + add_worker(public_downloader_selected_files, name=test_downloader) |
0 commit comments