Skip to content
Merged
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
5 changes: 2 additions & 3 deletions lib/SampleService/core/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ def expire_data_link(self, user: UserID, duid: DataUnitID, as_admin: bool = Fals

def get_links_from_sample(
self,
user: UserID,
user: Optional[UserID],
sample: SampleAddress,
timestamp: datetime.datetime = None,
as_admin: bool = False) -> Tuple[List[DataLink], datetime.datetime]:
'''
Get a set of data links originating from a sample at a particular time.

:param user: the user requesting the links.
:param user: the user requesting the links or None if the user is anonymous.
:param sample: the sample from which the links originate.
:param timestamp: the timestamp during which the links should be active, defaulting to
the current time.
Expand All @@ -378,7 +378,6 @@ def get_links_from_sample(
:raises NoSuchSampleVersionError: if the sample version does not exist.
:raises NoSuchUserError: if the user does not exist.
'''
_not_falsy(user, 'user')
_not_falsy(sample, 'sample')
timestamp = self._resolve_timestamp(timestamp)
self._check_perms(sample.sampleid, user, _SampleAccessType.READ, as_admin=as_admin)
Expand Down
14 changes: 10 additions & 4 deletions test/core/samples_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ def test_get_links_from_sample():
_get_links_from_sample(UserID('ur mum'))
_get_links_from_sample(UserID('x'))
_get_links_from_sample(UserID('noaccess'), True)
_get_links_from_sample(None, True)


def _get_links_from_sample(user, public_read=False):
Expand Down Expand Up @@ -1270,15 +1271,20 @@ def test_get_links_from_sample_fail_bad_args():
sa = SampleAddress(UUID('1234567890abcdef1234567890abcdee'), 3)
bt = datetime.datetime.fromtimestamp(1)

_get_links_from_sample_fail(s, None, sa, None, ValueError(
'user cannot be a value that evaluates to false'))
_get_links_from_sample_fail(s, u, None, None, ValueError(
'sample cannot be a value that evaluates to false'))
_get_links_from_sample_fail(s, u, sa, bt, ValueError(
'timestamp cannot be a naive datetime'))


def test_get_links_from_sample_fail_unauthorized():
_get_links_from_sample_fail_unauthorized(UserID('z'), UnauthorizedError(
'User z cannot read sample 12345678-90ab-cdef-1234-567890abcdee'))
_get_links_from_sample_fail_unauthorized(None, UnauthorizedError(
'Anonymous users cannot read sample 12345678-90ab-cdef-1234-567890abcdee'))


def _get_links_from_sample_fail_unauthorized(user, expected):
storage = create_autospec(ArangoSampleStorage, spec_set=True, instance=True)
lu = create_autospec(KBaseUserLookup, spec_set=True, instance=True)
meta = create_autospec(MetadataValidatorSet, spec_set=True, instance=True)
Expand All @@ -1294,10 +1300,10 @@ def test_get_links_from_sample_fail_unauthorized():

_get_links_from_sample_fail(
s,
UserID('z'),
user,
SampleAddress(UUID('1234567890abcdef1234567890abcdee'), 3),
None,
UnauthorizedError('User z cannot read sample 12345678-90ab-cdef-1234-567890abcdee'))
expected)

storage.get_sample_acls.assert_called_once_with(UUID('1234567890abcdef1234567890abcdee'))

Expand Down