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
[TT-5790] Update EnsureTransport and related tests #6243
[TT-5790] Update EnsureTransport and related tests #6243
Conversation
API Changes --- prev.txt 2024-05-14 11:46:26.886532924 +0000
+++ current.txt 2024-05-14 11:46:23.658522169 +0000
@@ -7199,6 +7199,8 @@
it to base64 and store it in an Event object
func EnsureTransport(host, protocol string) string
+ EnsureTransport sanitizes host/protocol pairs and returns a valid URL.
+
func GenerateTestBinaryData() (buf *bytes.Buffer)
func GetAccessDefinitionByAPIIDOrSession(currentSession *user.SessionState, api *APISpec) (accessDef *user.AccessDefinition, allowanceScope string, err error)
func GetTLSClient(cert *tls.Certificate, caCert []byte) *http.Client |
PR Description updated to latest commit (5478721) |
PR Review
Code feedback:
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
5478721
to
0e86433
Compare
0e86433
to
1a53c1b
Compare
Quality Gate passedIssues Measures |
/release to release-5.3 |
Working on it! Note that it can take a few minutes. |
## **User description** Several tests encountered parsing errors where the URL parser complained that "the first path segment in URL cannot contain colon". This occurred because the URLs were missing the scheme (e.g., `http://`) and couldn't be parsed. This PR improves EnsureTransport to better construct a valid URL from the `host` and `protocol` parameters. - Improves test with more test cases for IP:port and protocol pairs - Verifies intended behaviour with h2c URL parsing (coalescing to http scheme) with a unit test ___ ## **Type** enhancement, tests ___ ## **Description** - Refactored `EnsureTransport` to automatically handle missing protocols by defaulting to "http" and to prepend the protocol if it's missing in the host string. - Removed outdated switch-case logic in `EnsureTransport`, simplifying the URL scheme handling. - Expanded unit tests in `reverse_proxy_test.go` to cover new scenarios including IP addresses with ports, and protocol handling. - Improved test assertions to use `assert.Equal` and added checks to ensure URLs are parsable after processing. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>reverse_proxy.go</strong><dd><code>Refactor EnsureTransport to handle URL schemes more robustly</code></dd></summary> <hr> gateway/reverse_proxy.go <li>Added logic to <code>EnsureTransport</code> to handle missing protocols by <br>defaulting to "http".<br> <li> Amended the function to prepend protocol if missing in the host <br>string.<br> <li> Replaced specific scheme handling with a more generic approach.<br> <li> Removed old switch-case logic that handled schemes. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6243/files#diff-e6e07722257f7e41691e471185ad6d84fd56dc9e5459526ea32e9a5e8fa1a01b">+14/-9</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>reverse_proxy_test.go</strong><dd><code>Extend tests for EnsureTransport with more scenarios</code> </dd></summary> <hr> gateway/reverse_proxy_test.go <li>Expanded test cases for <code>EnsureTransport</code> to cover scenarios with IP <br>addresses and ports.<br> <li> Added tests for default protocol handling and h2c to http conversion.<br> <li> Replaced error checks with <code>assert.Equal</code> and added URL parse <br>verification. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6243/files#diff-ce040f6555143f760fba6059744bc600b6954f0966dfb0fa2832b5eabf7a3c3f">+22/-3</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > ✨ **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io> (cherry picked from commit 9ee0598)
@titpetric Succesfully merged PR |
…tests (#6243) [TT-5790] Update EnsureTransport and related tests (#6243) ## **User description** Several tests encountered parsing errors where the URL parser complained that "the first path segment in URL cannot contain colon". This occurred because the URLs were missing the scheme (e.g., `http://`) and couldn't be parsed. This PR improves EnsureTransport to better construct a valid URL from the `host` and `protocol` parameters. - Improves test with more test cases for IP:port and protocol pairs - Verifies intended behaviour with h2c URL parsing (coalescing to http scheme) with a unit test ___ ## **Type** enhancement, tests ___ ## **Description** - Refactored `EnsureTransport` to automatically handle missing protocols by defaulting to "http" and to prepend the protocol if it's missing in the host string. - Removed outdated switch-case logic in `EnsureTransport`, simplifying the URL scheme handling. - Expanded unit tests in `reverse_proxy_test.go` to cover new scenarios including IP addresses with ports, and protocol handling. - Improved test assertions to use `assert.Equal` and added checks to ensure URLs are parsable after processing. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>reverse_proxy.go</strong><dd><code>Refactor EnsureTransport to handle URL schemes more robustly</code></dd></summary> <hr> gateway/reverse_proxy.go <li>Added logic to <code>EnsureTransport</code> to handle missing protocols by <br>defaulting to "http".<br> <li> Amended the function to prepend protocol if missing in the host <br>string.<br> <li> Replaced specific scheme handling with a more generic approach.<br> <li> Removed old switch-case logic that handled schemes. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6243/files#diff-e6e07722257f7e41691e471185ad6d84fd56dc9e5459526ea32e9a5e8fa1a01b">+14/-9</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>reverse_proxy_test.go</strong><dd><code>Extend tests for EnsureTransport with more scenarios</code> </dd></summary> <hr> gateway/reverse_proxy_test.go <li>Expanded test cases for <code>EnsureTransport</code> to cover scenarios with IP <br>addresses and ports.<br> <li> Added tests for default protocol handling and h2c to http conversion.<br> <li> Replaced error checks with <code>assert.Equal</code> and added URL parse <br>verification. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6243/files#diff-ce040f6555143f760fba6059744bc600b6954f0966dfb0fa2832b5eabf7a3c3f">+22/-3</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > ✨ **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <tit@tyk.io>
User description
Several tests encountered parsing errors where the URL parser complained that "the first path segment in URL cannot contain colon". This occurred because the URLs were missing the scheme (e.g.,
http://
) and couldn't be parsed.This PR improves EnsureTransport to better construct a valid URL from the
host
andprotocol
parameters.https://tyktech.atlassian.net/browse/TT-5790
Type
enhancement, tests
Description
EnsureTransport
to automatically handle missing protocols by defaulting to "http" and to prepend the protocol if it's missing in the host string.EnsureTransport
, simplifying the URL scheme handling.reverse_proxy_test.go
to cover new scenarios including IP addresses with ports, and protocol handling.assert.Equal
and added checks to ensure URLs are parsable after processing.Changes walkthrough
reverse_proxy.go
Refactor EnsureTransport to handle URL schemes more robustly
gateway/reverse_proxy.go
EnsureTransport
to handle missing protocols bydefaulting to "http".
string.
reverse_proxy_test.go
Extend tests for EnsureTransport with more scenarios
gateway/reverse_proxy_test.go
EnsureTransport
to cover scenarios with IPaddresses and ports.
assert.Equal
and added URL parseverification.