Skip to content

Commit 90759dd

Browse files
author
Bartek Kwiecien
committed
Set filelink security when uploading from url
1 parent 673658e commit 90759dd

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

filestack/models/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ def upload_url(self, url, store_params=None, security=None):
119119
Returns:
120120
:class:`filestack.Filelink`: new Filelink object
121121
"""
122-
handle = upload_external_url(url, self.apikey, store_params, security=security or self.security)
123-
return filestack.models.Filelink(handle=handle)
122+
sec = security or self.security
123+
handle = upload_external_url(url, self.apikey, store_params, security=sec)
124+
return filestack.models.Filelink(handle=handle, security=sec)
124125

125126
def upload(self, *, filepath=None, file_obj=None, store_params=None, intelligent=False, security=None):
126127
"""

tests/client_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from httmock import urlmatch, HTTMock, response
77

88
import filestack.models
9-
from filestack import Client, Filelink, Transformation
9+
from filestack import Client, Filelink, Transformation, Security
1010
from tests.helpers import DummyHttpResponse
1111

1212

@@ -50,6 +50,24 @@ def test_store_filepath(upload_mock, client):
5050
upload_mock.assert_called_once_with('APIKEY', 'path/to/image.jpg', None, 'S3', params=None, security=None)
5151

5252

53+
@patch('filestack.models.client.multipart_upload')
54+
@patch('filestack.models.client.upload_external_url')
55+
def test_security_inheritance(upload_external_mock, multipart_mock):
56+
upload_external_mock.return_value = 'URL_HANDLE'
57+
multipart_mock.return_value = {'handle': 'FILE_HANDLE'}
58+
59+
policy = {'expiry': 1900}
60+
cli = Client(APIKEY, security=Security(policy, 'SECRET'))
61+
62+
flink_from_url = cli.upload_url('https://just.some/url')
63+
assert flink_from_url.handle == 'URL_HANDLE'
64+
assert flink_from_url.security.policy == policy
65+
66+
flink = cli.upload(filepath='/dummy/path')
67+
assert flink.handle == 'FILE_HANDLE'
68+
assert flink.security.policy == policy
69+
70+
5371
def test_url_screenshot(client):
5472
external_url = 'https//www.someexternalurl'
5573
transform = client.urlscreenshot(external_url)

0 commit comments

Comments
 (0)