Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions lib/share-tests/test_filesharebylinkintegrity
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

__doc__ = """

Test public file sharing after updating file.
With this test we want to check that after updating a file we still get the lastest version via the shared link and not a previous one.

Steps:
- 1) Create workdir
- 2) Upload file
- 3) Share file by link
- 4) Download file shared via the link and check ifit has the same contents as the original
- 5) Upload new version of a file (the fileid changes)
- 6) Re-download file shared and check that the contents are the same as the updated file and not to the original (now a version)

"""

from smashbox.utilities import *
import smashbox.curl
import time
import os
import owncloud

# The name of the file to upload
filename = "shared_file.txt"

# The contents of the file
file_data = "some data"

# The contents to update the file, please be sure this is different from file_data
file_data_updated = "other data"

# The name of the local file created after download the file via the shared link
filename_step4 = filename + "_step4"

# The name of the local file created after re-download the file via shared link
filename_step6 = filename + "_step6"

# The block size to generate random file
filesizeKB = int(config.get('share_filesizeKB',10))



@add_worker
def checker(step):

# Create workdir
step(1)
d = make_workdir()
fullpath = os.path.join(d,filename)
createfile(fullpath, file_data, count=1000, bs=filesizeKB)
original_sum = md5sum(fullpath)

# Upload file
step(2)
client = smashbox.curl.Client()
r = client.PUT(fullpath, os.path.join(oc_webdav_url(), filename))
fatal_check(r.rc == 201, "we should get 201 uploading the file")


# Share file by link
step(3)
share_info = share_file_with_link(filename, verify_certs = False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need verfy_certs=False here?

shared_link = share_info.link + '&download' # the download query params is to go directly to the file and not to the webpage showing the file
logger.info("You can access the shared file via this link: " + shared_link)

# Download file shared via the link and check ifit has the same contents as the original
step(4)
client = smashbox.curl.Client()
r = client.GET(shared_link, os.path.join(d,filename_step4))
sum = md5sum(os.path.join(d,filename_step4))
fatal_check(sum == original_sum, "the file downloaded by link is corrupted")

# Upload new version of a file (the fileid changes)
step(5)
createfile(fullpath, file_data_updated, count=1000, bs=filesizeKB)
updated_sum = md5sum(fullpath)
client = smashbox.curl.Client()
r = client.PUT(fullpath, os.path.join(oc_webdav_url(), filename))
fatal_check(r.rc == 201, "we shoudl get 201 uploading the file")

# Re-download file shared and check that the contents are the same as the updated file and not to the original (now a version)
step(6)
client = smashbox.curl.Client()
r = client.GET(shared_link, os.path.join(d,filename_step6))
sum = md5sum(os.path.join(d,filename_step6))
fatal_check(sum == updated_sum, "the shared link is pointing to a previous version")
logger.info('SUCCESS')
24 changes: 23 additions & 1 deletion python/smashbox/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def scrape_log_file(d):

# ###### API Calls ############

def get_oc_api():
def get_oc_api(**kwargs):
""" Returns an instance of the Client class

:returns: Client instance
Expand Down Expand Up @@ -581,6 +581,28 @@ def share_file_with_user(filename, sharer, sharee, **kwargs):
else:
return -2

def share_file_with_link(filename,**kwargs):
""" Shares a file by link

:param filename: name of the file being shared
:param kwargs: key words args to be passed into the api, usually for share permissions
:returns: PublicShare instance

"""
oc_api = get_oc_api(**kwargs)
oc_api.login(config.oc_account_name, config.oc_account_password)
try:
share_info = oc_api.share_file_with_link(filename)
return share_info
except Exception as err:

# TODO: this code is not the best - the goal is to trap a share not allowed error and return that error code

logger.info('Share failed with %s', str(err))
if "not allowed to share" in str(err):
return -1
else:
return -2

def delete_share(sharer, share_id):
""" Deletes a share
Expand Down