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

test: refactor CorsFilterSpec as a black box #8473

Merged
merged 1 commit into from Dec 9, 2022
Merged

Conversation

sdelamo
Copy link
Collaborator

@sdelamo sdelamo commented Dec 9, 2022

This refactors the CorsFilterSpec to test it as a black box instead of testing internal methods such as handleRequest. I will send a separate PR to refactor CorsFilter.

This refactors the CORS filter tests to verify its behavior from the outside, and it does not rely on calling the internal methods.
@sdelamo sdelamo added the type: improvement A minor improvement to an existing feature label Dec 9, 2022
@sonarcloud
Copy link

sonarcloud bot commented Dec 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

request.getHeaders() >> headers
def config = new HttpServerConfiguration.CorsConfiguration()
String origin = 'http://www.foo.com'
HttpHeaders headers = Stub(HttpHeaders) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need a mock here, or is there an implementation we can use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In other places, we use MockHttpHeaders but I think in this test the Stub is ok.

@sdelamo sdelamo merged commit 50dc946 into 3.8.x Dec 9, 2022
@sdelamo sdelamo deleted the refactor-cors-tests branch December 9, 2022 14:23
yawkat added a commit that referenced this pull request Dec 10, 2022
micronaut-function-aws-api-proxy requests include the host in getUri. This leads to no match with findAny. This causes the AVAILABLE_HTTP_METHODS to be empty, which causes a test failure with CorsFilter in the aws module.

Unfortunately I can't test this using CorsFilterSpec in this repo, because CorsFilterSpec calls findAny directly instead of using the findRouteMatch code path. There is also a PR for refactoring CorsFilterSpec (#8473) but it does not get rid of the mocking either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants