Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data-management-api: validate query parameters #1258

Merged
merged 3 commits into from
May 10, 2022
Merged

data-management-api: validate query parameters #1258

merged 3 commits into from
May 10, 2022

Conversation

ndr-brt
Copy link
Member

@ndr-brt ndr-brt commented May 4, 2022

What this PR changes/adds

Adds validation on query params before building the QuerySpec object.
To do that introduces a QuerySpecDto object that is valued through the @BeanParam annotation.

Why it does that

To better validate input on query call

Further notes

  • Bump some dependencies

Linked Issue(s)

Closes #1235

Checklist

  • added appropriate tests?
  • performed checkstyle check locally?
  • added/updated copyright headers?
  • documented public classes/methods?
  • added/updated relevant documentation?
  • added relevant details to the changelog? (skip with label no-changelog)
  • formatted title correctly? (take a look at the CONTRIBUTING and styleguide for details)

return sortField;
}

@AssertTrue
Copy link
Member

@paullatzelsperger paullatzelsperger May 5, 2022

Choose a reason for hiding this comment

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

This needs to have the @JsonIgnore annotation, otherwise Jackson will look for a valid field. A serialization test would have surfaced that. Mind adding one?

For example:

    @Test
    void verifySerialization() throws JsonProcessingException {

        var dto = QuerySpecDto.Builder.newInstance()
                .filter("some filter")
                .limit(10)
                .offset(2)
                .build();

        var mapper = new ObjectMapper();
        var json = mapper.writeValueAsString(dto);

        assertThat(json).isNotNull();
        var d = mapper.readValue(json, QuerySpecDto.class);
        assertThat(d).usingRecursiveComparison().isEqualTo(dto);
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

This class is never serialized to/deserialized from json, so it's not needed

Copy link
Member

Choose a reason for hiding this comment

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

I haven't checked, but what about tests (integration, e2e)?

Copy link
Member Author

@ndr-brt ndr-brt May 9, 2022

Choose a reason for hiding this comment

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

tests are working just fine without touching them, I just add a "failing query" test for every controller

Copy link
Member

Choose a reason for hiding this comment

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

sure, that'll work, but as far as I'm aware @algattik has plans to generate a java API client from our own OpenAPI spec and use that in tests. If that is the case we'd indeed have to serialize the QuerySpecDto.

Copy link
Member Author

Choose a reason for hiding this comment

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

@paullatzelsperger I'm not sure about that, however I would leave this for that issue, if it's needed it will be done

Copy link
Member

Choose a reason for hiding this comment

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

ok, fine for me.

@ndr-brt ndr-brt requested a review from ronjaquensel May 5, 2022 06:46
@bscholtes1A
Copy link
Contributor

Hi @ndr-brt
looks good!
Not related to this PR but we have in the backlog the input validation for Data Plane API #1163
The different is that the public API of the DPF takes random path/query params and body (they are forwarded to the backend data source).

Will the approach you introduce in this PR also applicable in the context of the Data Plane API?

@ndr-brt
Copy link
Member Author

ndr-brt commented May 9, 2022

hey @bscholtes1A I don't think the same approach could be used there because, as you said, there isn't the possibility to know what parameters will be passed upfront.
Probably the simplest (and good enough?) validation there could be just a size limit for body and query

@bscholtes1A bscholtes1A merged commit 508b591 into eclipse-edc:main May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataManagement API: query parameters validation
4 participants