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

fix(event-uri): resolve uri with any existing context path #212

Closed

Conversation

msafari
Copy link

@msafari msafari commented Sep 23, 2020

Requirements

  • [x ] I have added test coverage for new or changed functionality
  • [ x] I have followed the repository's pull request submission guidelines
  • [ x] I have validated my changes against all supported platform versions

Related issues
The way the URL is currently being resolved, it'd drop existing context paths if the uri didn't have a trailing /
Here's a sample unit tests that proves this bug
Screen Shot 2020-09-23 at 12 27 33 PM

Describe the solution you've provided

if the URI doesn't have a trailing slash, still respect any existing context paths.

Describe alternatives you've considered
I tried providing a baseUri with trailing slash. But then another endpoint: /all, was attempting to add its own slash and failed since the baseuri already had one.
So it seemed reasonable to me that this would just respect the context path provided to it regardless of it having trailing slash or not.

Additional context

I've added additional unit tests to cover the following scenarios:

  • base uri has no context path of its own and has no trailing slash
  • base uri has no context path of its own and has a trailing slash
  • base uri has context path of its own and has no trailing slash
  • base uri has context path of its own and has a trailing slash

Assert.assertEquals(
"https://www.example.com/diagnostic",
uri.toString()
);
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be preferable to test this in more of an end-to-end way, as the other HTTP-related tests in this file do. That is, instead of verifying that this low-level method appendPathToBaseURI does what it should, we would want to verify that DefaultEventSender, when configured with such-and-such a base URL, actually sends a request with the expected URL path to the target server. Look for instance at analyticsDataIsDelivered().

The reason we strongly prefer this approach is not just to avoid having to expose low-level helper methods to the tests. It's because even if you can prove that the helper method behaves properly when called with certain parameters, that does not prove that the higher-level code is using the helper method properly (or at all). Ultimately we don't care whether it is using that helper method or doing some equivalent computation of its own, what we care about is that the component works. And we definitely don't want to have a situation where we could accidentally introduce a regression in the higher-level component logic and have it not show up as a test failure because what we were testing was an implementation detail we assume it is using.

@eli-darkly
Copy link
Contributor

I'm assuming the intention here is to support custom base URIs that are going through some kind of proxy with URL rewriting, or a custom build of the Relay Proxy with different routing, since neither the actual LaunchDarkly service endpoints nor the standard Relay Proxy have a base context path.

If so, I think a more general solution would be appropriate. The proposed fix is only for the events endpoint, but it's also possible to customize the base URI for the streaming and polling data sources and I think there are likely to be similar issues there.

Whether you want to rework the PR to address this (and the unit testing issue I commented on) is up to you. I'd be happy to take care of those details and treat this as a bug report with a suggested fix, and we would credit you with a thank-you in the release note regardless of whether we accept this PR.

@msafari
Copy link
Author

msafari commented Sep 23, 2020

I'm assuming the intention here is to support custom base URIs that are going through some kind of proxy with URL rewriting, or a custom build of the Relay Proxy with different routing, since neither the actual LaunchDarkly service endpoints nor the standard Relay Proxy have a base context path.

If so, I think a more general solution would be appropriate. The proposed fix is only for the events endpoint, but it's also possible to customize the base URI for the streaming and polling data sources and I think there are likely to be similar issues there.

Whether you want to rework the PR to address this (and the unit testing issue I commented on) is up to you. I'd be happy to take care of those details and treat this as a bug report with a suggested fix, and we would credit you with a thank-you in the release note regardless of whether we accept this PR.

Thanks for the quick response. You are absolutely correct. We use our own proxy with different routing. The context paths of the custom routes are getting completely dropped here and causing 404s.
I only noticed this happening for /bulk and /diagnosis. However, if this may be a problem elsewhere too, you can definitely take this as an issue report and apply a more general fix.

@eli-darkly
Copy link
Contributor

We've released version 5.1.1, which includes an extended version of this fix (there were similar issues with the other base URL settings).

@eli-darkly eli-darkly closed this Oct 1, 2020
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.

None yet

3 participants