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

Update to Play 3.x. Drop Scala 2.12 support. #5

Merged
merged 5 commits into from
Dec 9, 2023

Conversation

OlegYch
Copy link
Collaborator

@OlegYch OlegYch commented Nov 30, 2023

No description provided.

@julienrf
Copy link
Member

julienrf commented Dec 4, 2023

I believe the CI failure is caused by this change in the test suite.

@OlegYch
Copy link
Collaborator Author

OlegYch commented Dec 4, 2023

@julienrf perhaps it needs new julienrf/endpoints4s-stubserver docker image?

@julienrf
Copy link
Member

julienrf commented Dec 4, 2023

In the commit I linked at least, the stub-server wasn’t changed, so it may not need an update. If you look at the commit it changed the behavior of the servers (and their test expectation), so I think you need to apply the same change here. Unfortunately, that part of the code is a bit complex, so feel free to ask any question if needed!

That being said, if you want to update the stub-server, I invite you to use the same approach as here, which does not go through the Docker hub (which does not contain up to date images): https://github.com/endpoints4s/xhr/blob/f309656a4186f04474f218b65fff5f7ae247a8fe/.github/workflows/ci.yml#L23

@OlegYch
Copy link
Collaborator Author

OlegYch commented Dec 4, 2023

@julienrf i fixed the test, but i'm not sure if that's the correct way - what happens if there are several endpoints with same method, but different urls and authentication? will the new implementation match the first endpoint it finds and return failure even if there are unauthenticated endpoints that should match?

Copy link

codecov bot commented Dec 4, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (9b60787) 58.25% compared to head (6752b82) 56.38%.

Files Patch % Lines
.../endpoints4s/play/server/BasicAuthentication.scala 14.28% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
- Coverage   58.25%   56.38%   -1.88%     
==========================================
  Files          21       22       +1     
  Lines         539     1050     +511     
  Branches       20       27       +7     
==========================================
+ Hits          314      592     +278     
- Misses        225      458     +233     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julienrf
Copy link
Member

julienrf commented Dec 4, 2023

what happens if there are several endpoints with same method, but different urls and authentication? will the new implementation match the first endpoint it finds and return failure even if there are unauthenticated endpoints that should match?

I am not sure I understand completely the part “different URLs”, because if they have different URLs then they may not match the same incoming request, right? But otherwise, yes, the first endpoint whose method + URL path match the incoming request will handle the request. If that endpoint requires authentication, it will return an Unauthorized response if the credentials are missing or invalid, without giving a chance to another endpoint to handle the request.

Left(
Results.Unauthorized
.withHeaders(HeaderNames.WWW_AUTHENTICATE -> "Basic realm=Realm")
if (method.matches(requestHeader)) {
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised that you don’t also need to match the URL path 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be possible to implement it by still calling matchRequestAndParseHeaders?

Copy link
Collaborator Author

@OlegYch OlegYch Dec 4, 2023

Choose a reason for hiding this comment

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

yeah, this is no good, i'll reimplement
can i suggest adding something to testkit that can check if endpoints clash?

like this

  "basic auth" should {
    "not prevent other endpoints from matching" in {
      val response = "Hello!"
      import serverApi._
      val protectedEndpointWithParameter = authenticatedEndpoint(
        Get,
        path / "users" / segment[Long]("id"),
        ok(textResponse)
      )
      val unprotectedEndpointWithParameter = endpoint(
        get(path / "users"),
        ok(textResponse)
      )

      serveRoutes(
        routesFromEndpoints(
          protectedEndpointWithParameter.implementedBy(_ => Some(response)),
          unprotectedEndpointWithParameter.implementedBy(_ => response),
        )
      ){ port =>
        val request = HttpRequest(uri = s"http://localhost:$port/users")
        whenReady(sendAndDecodeEntityAsText(request)) { case (_, entity) =>
          entity shouldBe response
          ()
        }
      }
    }
  }

Copy link
Member

@julienrf julienrf Dec 4, 2023

Choose a reason for hiding this comment

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

Yes, any addition to the test kit is welcome!

@julienrf
Copy link
Member

julienrf commented Dec 4, 2023

To fix the CI failure you need to relax the compatibility intention to Compatibility.None here (since I assume Play 3 is not binary compatible with Play 2.9):

versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,

@OlegYch
Copy link
Collaborator Author

OlegYch commented Dec 5, 2023

@julienrf hm actually it looks like current testkit is wrong endpoints4s/endpoints4s#1222 (the new test fails)

@OlegYch
Copy link
Collaborator Author

OlegYch commented Dec 5, 2023

hm, maybe it's just a problem with pekko implementation, as http4s passes the new test

@OlegYch
Copy link
Collaborator Author

OlegYch commented Dec 5, 2023

@julienrf i fixed pekko, can you please release new testkit?

@OlegYch OlegYch marked this pull request as ready for review December 8, 2023 18:43
Copy link
Member

@julienrf julienrf left a comment

Choose a reason for hiding this comment

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

This looks good to me apart from a couple of minor comments, thank you @OlegYch!

build.sbt Show resolved Hide resolved
@julienrf julienrf merged commit bf164c7 into endpoints4s:main Dec 9, 2023
1 of 3 checks passed
@julienrf julienrf changed the title Updating to play3 Update to Play 3.x. Drop Scala 2.12 support. Dec 9, 2023
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.

2 participants