Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fix: scopes should not be filtered in search use cases #79

Merged
merged 4 commits into from
Mar 11, 2022

Conversation

ssvegaraju
Copy link
Contributor

Issue #78 , if available:

Description of changes:
Updated the function checking valid operations for scope to process search use cases similar to transactions/batches. This means that searches running include will contain all expected resources and not drop scopes to limit search results since they are not directly requested.

Testing
To test that the functionality was working as intended, I deployed on SMART and created a DocumentReference with a reference to a Patient resource, and searched with the example scopes (system/DocumentReference.read, system/Patient.read) to reproduce the issue. I then implemented the fix as well as an additional unit test, and made sure that the Patient resource was included in the search results.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ssvegaraju ssvegaraju requested a review from a team as a code owner March 3, 2022 08:44
@github-actions github-actions bot added the size/s label Mar 3, 2022
const clonedScopeRule = emptyScopeRule();
clonedScopeRule.system.read = ['search-type'];
expect(
filterOutUnusableScope(
Copy link
Contributor

Choose a reason for hiding this comment

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

In the situation mentioned in the issue, reqResourceType should be Patient right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might have misunderstood, but I think the situation was that the Patient resource was a reference in the DocumentReference, and needed to be included in the results with the _include parameter. This test is making sure that neither scope is filtered out from a search, so that resources of both DocumentReference and Patient can be read by the search query. Additionally, if the reqResourceType parameter is provided, the route is different and won't actually hit the change made to fix the bug: https://github.com/awslabs/fhir-works-on-aws-authz-smart/pull/79/files#diff-9539c459709b0437ecf87b68dce629addd51e10c3c4f7af6ab3fdfcc171a312aL57

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah for the test case we need to ensure: reqResourceType?: string, is set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, after running tests searches do indeed provide the reqResourceType parameter, whereas batch and transaction do not. So I moved the change into the correct place to reflect that. I also updated the test to set reqResourceType and it correctly returns both scopes as valid.

@rsmayda rsmayda requested a review from Bingjiling March 10, 2022 19:35
Copy link
Contributor

@rsmayda rsmayda left a comment

Choose a reason for hiding this comment

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

Great research!

@ssvegaraju ssvegaraju merged commit 67af26d into mainline Mar 11, 2022
@ssvegaraju ssvegaraju deleted the fix-SysScopeOnInclude branch March 11, 2022 04:53
@liquid36
Copy link

liquid36 commented Apr 1, 2022

Hi! I'm having an issue with this change.
This is my use case:

        const clonedScopeRule = emptyScopeRule();
        clonedScopeRule.system.read = ['search-type'];
        expect(
            filterOutUnusableScope(
                ['system/DocumentReference.read', 'system/Patient.read'],
                clonedScopeRule,
                'search-type',
                false,
                'Procedure',
            ),
        ).toEqual([]);

If the user claims for this scope system/DocumentReference.read system/Patient.read but ask for a Procedure resource, the filterOutUnusableScope mark both scope as usable and then the operation is allowed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants