Skip to content

[TT-11806] Respect domain and listen path#6289

Merged
titpetric merged 7 commits into
masterfrom
fix/tt-11806/domain-and-listenPath
May 17, 2024
Merged

[TT-11806] Respect domain and listen path#6289
titpetric merged 7 commits into
masterfrom
fix/tt-11806/domain-and-listenPath

Conversation

@titpetric

@titpetric titpetric commented May 17, 2024

Copy link
Copy Markdown
Contributor

User description

PR reorders api specs with domains to be registered before fallback (no-domain) specs.

Adds:

  • Ability to set the host header for tests,
  • Regression test testing gorilla mux expectations
  • Moves a domain based api test out of gateway scope
  • Tests loading apis with/without domain in different order

https://tyktech.atlassian.net/browse/TT-11806


PR Type

enhancement, bug_fix, tests


Description

  • Enhanced domain handling in API spec loading by prioritizing domain length.
  • Fixed minor issues and typos in API loading logic.
  • Added support for setting the host header in HTTP tests.
  • Introduced comprehensive regression tests to ensure correct domain routing.
  • Added new test API specifications for testing domain and non-domain routes.

Changes walkthrough 📝

Relevant files
Enhancement
api_loader.go
Enhance API loading with domain prioritization and minor fixes

gateway/api_loader.go

  • Improved domain handling in API spec counting.
  • Fixed a typo in a comment.
  • Modified the sorting logic to prioritize domain length before listen
    path length.
  • +7/-5     
    http.go
    Support host header in HTTP tests                                               

    test/http.go

    • Added support for setting the host header in HTTP test cases.
    +5/-0     
    Tests
    api_test.go
    Remove redundant API loading order test                                   

    gateway/api_test.go

    • Removed a redundant test case for API loading order.
    +0/-50   
    issue_11806_test.go
    Add regression tests for domain routing                                   

    tests/regression/issue_11806_test.go

  • Added comprehensive regression tests for domain routing issues.
  • Included tests for mux router and gateway router behaviors.
  • +165/-0 
    issue-11806-api-no-domain.json
    Add test API spec without domain                                                 

    tests/regression/testdata/issue-11806-api-no-domain.json

    • Added a new test API spec without a domain.
    +24/-0   
    issue-11806-api-with-domain.json
    Add test API spec with domain                                                       

    tests/regression/testdata/issue-11806-api-with-domain.json

    • Added a new test API spec with a domain.
    +24/-0   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions

    github-actions Bot commented May 17, 2024

    Copy link
    Copy Markdown
    Contributor

    API Changes

    --- prev.txt	2024-05-17 13:23:45.317943174 +0000
    +++ current.txt	2024-05-17 13:23:42.333943951 +0000
    @@ -11542,6 +11542,7 @@
     func (r TCPTestRunner) Run(t testing.TB, testCases ...TCPTestCase) error
     
     type TestCase struct {
    +	Host    string `json:",omitempty"`
     	Method  string `json:",omitempty"`
     	Path    string `json:",omitempty"`
     	BaseURL string `json:",omitempty"`

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Description updated to latest commit (dcc6257)

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves multiple changes across several files including logic changes, new tests, and refactoring. The changes impact core functionality such as API loading and routing, which requires careful review to ensure no regressions or bugs are introduced.

    🧪 Relevant tests

    Yes

    ⚡ Possible issues

    Sorting Logic Concern: The new sorting logic in gateway/api_loader.go prioritizes domain length over listen path length. This might introduce issues where APIs with shorter domain names but longer listen paths might get incorrectly prioritized, affecting routing.

    🔒 Security concerns

    No

    Code feedback:
    relevant filegateway/api_loader.go
    suggestion      

    Consider adding a comment explaining why domain length is prioritized over listen path length in the sorting logic. This will help maintain the code in the future and understand the decision-making process behind this logic. [medium]

    relevant linereturn len(specs[i].Domain) > len(specs[j].Domain)

    relevant filegateway/api_loader.go
    suggestion      

    Ensure that the domain comparison in the sorting function is case-insensitive to avoid issues with domain name case variations. This can be achieved by converting both domains to lower case before comparing their lengths. [important]

    relevant lineif specs[i].Domain != specs[j].Domain {

    relevant filegateway/api_loader.go
    suggestion      

    Refactor the conditional logic that checks for an empty domain and assigns "(no host)" to a separate function. This improves code readability and maintainability. [medium]

    relevant lineif domain == "" {

    relevant filegateway/api_loader.go
    suggestion      

    Consider using a constant for the default domain placeholder "(no host)" to avoid magic strings and facilitate changes in the future. [medium]

    relevant linedomain = "(no host)"

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Security
    Add validation for the Host field to enhance security

    Ensure the Host field is properly sanitized or validated to prevent potential security
    risks such as Host Header Injection.

    test/http.go [288-290]

    -if tc.Host != "" {
    +if tc.Host != "" && isValidHost(tc.Host) {
         req.Host = tc.Host
     }
     
    Suggestion importance[1-10]: 9

    Why: Validating the Host field is essential to prevent security risks such as Host Header Injection, making this suggestion highly relevant and impactful for security.

    9
    Possible bug
    Add nil check for spec.Proxy to prevent runtime errors

    Consider checking for nil before accessing spec.Proxy to prevent potential nil pointer
    dereference.

    gateway/api_loader.go [90]

    -domainHash := generateDomainPath(domain, spec.Proxy.ListenPath)
    +if spec.Proxy != nil {
    +    domainHash := generateDomainPath(domain, spec.Proxy.ListenPath)
    +}
     
    Suggestion importance[1-10]: 8

    Why: Adding a nil check before accessing spec.Proxy is crucial to prevent runtime errors due to nil pointer dereference, which is a common issue in Go.

    8
    Ensure domain fields are not nil before comparing their lengths

    Add a check to ensure specs[i].Domain and specs[j].Domain are not nil before comparing
    their lengths to avoid potential runtime panics.

    gateway/api_loader.go [925-927]

    -if specs[i].Domain != specs[j].Domain {
    +if specs[i].Domain != nil && specs[j].Domain != nil && specs[i].Domain != specs[j].Domain {
         return len(specs[i].Domain) > len(specs[j].Domain)
     }
     
    Suggestion importance[1-10]: 8

    Why: This suggestion correctly identifies a potential runtime panic due to nil values in domain comparisons. Adding nil checks is crucial for robustness.

    8
    Enhancement
    Improve the placeholder for empty domain values in logging

    Use a more descriptive placeholder than "(no host)" for empty domains to enhance clarity
    in logs.

    gateway/api_loader.go [92-94]

     if domain == "" {
    -    domain = "(no host)"
    +    domain = "undefined-host"
     }
     
    Suggestion importance[1-10]: 4

    Why: While improving the placeholder text enhances clarity, it's a minor enhancement and does not impact functionality or prevent errors.

    4

    @titpetric
    titpetric requested a review from a team as a code owner May 17, 2024 12:37
    Comment thread tests/regression/issue_11806_test.go Outdated
    @sonarqubecloud

    Copy link
    Copy Markdown

    @titpetric
    titpetric merged commit 55254bc into master May 17, 2024
    @titpetric
    titpetric deleted the fix/tt-11806/domain-and-listenPath branch May 17, 2024 14:35
    @titpetric

    Copy link
    Copy Markdown
    Contributor Author

    /release to release-5.3

    @tykbot

    tykbot Bot commented May 17, 2024

    Copy link
    Copy Markdown

    Working on it! Note that it can take a few minutes.

    tykbot Bot pushed a commit that referenced this pull request May 17, 2024
    ### **User description**
    PR reorders api specs with domains to be registered before fallback
    (no-domain) specs.
    
    Adds:
    
    - Ability to set the host header for tests,
    - Regression test testing gorilla mux expectations
    - Moves a domain based api test out of gateway scope
    - Tests loading apis with/without domain in different order
    
    https://tyktech.atlassian.net/browse/TT-11806
    
    
    ___
    
    ### **PR Type**
    enhancement, bug_fix, tests
    
    
    ___
    
    ### **Description**
    - Enhanced domain handling in API spec loading by prioritizing domain
    length.
    - Fixed minor issues and typos in API loading logic.
    - Added support for setting the host header in HTTP tests.
    - Introduced comprehensive regression tests to ensure correct domain
    routing.
    - Added new test API specifications for testing domain and non-domain
    routes.
    
    
    ___
    
    
    
    ### **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>api_loader.go</strong><dd><code>Enhance API loading
    with domain prioritization and minor fixes</code></dd></summary>
    <hr>
    
    gateway/api_loader.go
    <li>Improved domain handling in API spec counting.<br> <li> Fixed a typo
    in a comment.<br> <li> Modified the sorting logic to prioritize domain
    length before listen <br>path length.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-cdf0b7f176c9d18e1a314b78ddefc2cb3a94b3de66f1f360174692c915734c68">+7/-5</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>http.go</strong><dd><code>Support host header in HTTP
    tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/http.go
    - Added support for setting the host header in HTTP test cases.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Remove redundant API
    loading order test</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/api_test.go
    - Removed a redundant test case for API loading order.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+0/-50</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue_11806_test.go</strong><dd><code>Add regression
    tests for domain routing</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_11806_test.go
    <li>Added comprehensive regression tests for domain routing issues.<br>
    <li> Included tests for mux router and gateway router behaviors.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-6414917e8c31f924c3a423765e285a34d988e923bd0f10d5cc56bacad99195d8">+165/-0</a>&nbsp;
    </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-no-domain.json</strong><dd><code>Add
    test API spec without domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-no-domain.json
    - Added a new test API spec without a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-e8d8e335343405ef0e02562a51b4f8966cc03fe429e2c4b987504c6147bc00a7">+24/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-with-domain.json</strong><dd><code>Add
    test API spec with domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-with-domain.json
    - Added a new test API spec with a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-f2b780fe118cacccbfe27e8784d7d2bae3cdc20f37c7bdccb4cf8146c9e6187b">+24/-0</a>&nbsp;
    &nbsp; </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 <[email protected]>
    
    (cherry picked from commit 55254bc)
    @tykbot

    tykbot Bot commented May 17, 2024

    Copy link
    Copy Markdown

    @titpetric Succesfully merged PR

    titpetric pushed a commit that referenced this pull request May 20, 2024
    ) (#6290)
    
    ### **User description**
    [TT-11806] Respect domain and listen path (#6289)
    
    ### **User description**
    PR reorders api specs with domains to be registered before fallback
    (no-domain) specs.
    
    Adds:
    
    - Ability to set the host header for tests,
    - Regression test testing gorilla mux expectations
    - Moves a domain based api test out of gateway scope
    - Tests loading apis with/without domain in different order
    
    https://tyktech.atlassian.net/browse/TT-11806
    
    
    ___
    
    ### **PR Type**
    enhancement, bug_fix, tests
    
    
    ___
    
    ### **Description**
    - Enhanced domain handling in API spec loading by prioritizing domain
    length.
    - Fixed minor issues and typos in API loading logic.
    - Added support for setting the host header in HTTP tests.
    - Introduced comprehensive regression tests to ensure correct domain
    routing.
    - Added new test API specifications for testing domain and non-domain
    routes.
    
    
    ___
    
    
    
    ### **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>api_loader.go</strong><dd><code>Enhance API loading
    with domain prioritization and minor fixes</code></dd></summary>
    <hr>
    
    gateway/api_loader.go
    <li>Improved domain handling in API spec counting.<br> <li> Fixed a typo
    in a comment.<br> <li> Modified the sorting logic to prioritize domain
    length before listen <br>path length.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-cdf0b7f176c9d18e1a314b78ddefc2cb3a94b3de66f1f360174692c915734c68">+7/-5</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>http.go</strong><dd><code>Support host header in HTTP
    tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/http.go
    - Added support for setting the host header in HTTP test cases.
    
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Remove redundant API
    loading order test</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/api_test.go
    - Removed a redundant test case for API loading order.
    
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+0/-50</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue_11806_test.go</strong><dd><code>Add regression
    tests for domain routing</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_11806_test.go
    <li>Added comprehensive regression tests for domain routing issues.<br>
    <li> Included tests for mux router and gateway router behaviors.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-6414917e8c31f924c3a423765e285a34d988e923bd0f10d5cc56bacad99195d8">+165/-0</a>&nbsp;
    </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-no-domain.json</strong><dd><code>Add
    test API spec without domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-no-domain.json
    - Added a new test API spec without a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-e8d8e335343405ef0e02562a51b4f8966cc03fe429e2c4b987504c6147bc00a7">+24/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-with-domain.json</strong><dd><code>Add
    test API spec with domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-with-domain.json
    - Added a new test API spec with a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-f2b780fe118cacccbfe27e8784d7d2bae3cdc20f37c7bdccb4cf8146c9e6187b">+24/-0</a>&nbsp;
    &nbsp; </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 <[email protected]>
    
    [TT-11806]:
    https://tyktech.atlassian.net/browse/TT-11806?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
    
    
    ___
    
    ### **PR Type**
    Enhancement, Bug fix, Tests
    
    
    ___
    
    ### **Description**
    - Enhanced domain handling in API spec loading by prioritizing domain
    length.
    - Fixed minor issues and typos in API loading logic.
    - Added support for setting the host header in HTTP tests.
    - Introduced comprehensive regression tests to ensure correct domain
    routing.
    - Added new test API specifications for testing domain and non-domain
    routes.
    
    
    ___
    
    
    
    ### **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>api_loader.go</strong><dd><code>Enhance API loading
    with domain prioritization and minor fixes</code></dd></summary>
    <hr>
    
    gateway/api_loader.go
    <li>Improved domain handling in API spec counting.<br> <li> Fixed a typo
    in a comment.<br> <li> Modified the sorting logic to prioritize domain
    length before listen <br>path length.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-cdf0b7f176c9d18e1a314b78ddefc2cb3a94b3de66f1f360174692c915734c68">+7/-5</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>http.go</strong><dd><code>Support host header in HTTP
    tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/http.go
    - Added support for setting the host header in HTTP tests.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Remove outdated API
    loader path order test</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    gateway/api_test.go
    <li>Removed a large block of test code related to API loader path
    <br>ordering.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+0/-50</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue_11806_test.go</strong><dd><code>Comprehensive
    regression tests for domain routing</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_11806_test.go
    <li>Added a comprehensive regression test suite for domain routing
    issues.<br> <li> Tests both loading orders of APIs with and without
    domains.<br> <li> Includes direct testing with gorilla/mux to ensure
    correct subrouter <br>behavior.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-6414917e8c31f924c3a423765e285a34d988e923bd0f10d5cc56bacad99195d8">+176/-0</a>&nbsp;
    </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-no-domain.json</strong><dd><code>New
    test API spec without domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-no-domain.json
    - Added a new test API specification without a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-e8d8e335343405ef0e02562a51b4f8966cc03fe429e2c4b987504c6147bc00a7">+24/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-with-domain.json</strong><dd><code>New
    test API spec with domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-with-domain.json
    - Added a new test API specification with a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-f2b780fe118cacccbfe27e8784d7d2bae3cdc20f37c7bdccb4cf8146c9e6187b">+24/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Configuration changes
    </strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>ci-tests.yml</strong><dd><code>Update CI configuration
    for test exclusions</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    .github/workflows/ci-tests.yml
    - Updated SonarQube test exclusions to include the 'test' directory.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6290/files#diff-03609cb60b0c6e92fb771eb8787d6722b8c31ca4c03eabc788e147acd8c6fb43">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </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 <[email protected]>
    nerdydread pushed a commit that referenced this pull request Sep 6, 2024
    ### **User description**
    PR reorders api specs with domains to be registered before fallback
    (no-domain) specs.
    
    Adds:
    
    - Ability to set the host header for tests,
    - Regression test testing gorilla mux expectations
    - Moves a domain based api test out of gateway scope
    - Tests loading apis with/without domain in different order
    
    https://tyktech.atlassian.net/browse/TT-11806
    
    
    ___
    
    ### **PR Type**
    enhancement, bug_fix, tests
    
    
    ___
    
    ### **Description**
    - Enhanced domain handling in API spec loading by prioritizing domain
    length.
    - Fixed minor issues and typos in API loading logic.
    - Added support for setting the host header in HTTP tests.
    - Introduced comprehensive regression tests to ensure correct domain
    routing.
    - Added new test API specifications for testing domain and non-domain
    routes.
    
    
    ___
    
    
    
    ### **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>api_loader.go</strong><dd><code>Enhance API loading
    with domain prioritization and minor fixes</code></dd></summary>
    <hr>
    
    gateway/api_loader.go
    <li>Improved domain handling in API spec counting.<br> <li> Fixed a typo
    in a comment.<br> <li> Modified the sorting logic to prioritize domain
    length before listen <br>path length.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-cdf0b7f176c9d18e1a314b78ddefc2cb3a94b3de66f1f360174692c915734c68">+7/-5</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>http.go</strong><dd><code>Support host header in HTTP
    tests</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    test/http.go
    - Added support for setting the host header in HTTP test cases.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+5/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests
    </strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>api_test.go</strong><dd><code>Remove redundant API
    loading order test</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/api_test.go
    - Removed a redundant test case for API loading order.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-10b4a3d7bdd8d98e48b288d27fd46d9ee436617806c46913fdf7942c0e4a992e">+0/-50</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue_11806_test.go</strong><dd><code>Add regression
    tests for domain routing</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_11806_test.go
    <li>Added comprehensive regression tests for domain routing issues.<br>
    <li> Included tests for mux router and gateway router behaviors.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-6414917e8c31f924c3a423765e285a34d988e923bd0f10d5cc56bacad99195d8">+165/-0</a>&nbsp;
    </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-no-domain.json</strong><dd><code>Add
    test API spec without domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-no-domain.json
    - Added a new test API spec without a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-e8d8e335343405ef0e02562a51b4f8966cc03fe429e2c4b987504c6147bc00a7">+24/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-11806-api-with-domain.json</strong><dd><code>Add
    test API spec with domain</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-11806-api-with-domain.json
    - Added a new test API spec with a domain.
    
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6289/files#diff-f2b780fe118cacccbfe27e8784d7d2bae3cdc20f37c7bdccb4cf8146c9e6187b">+24/-0</a>&nbsp;
    &nbsp; </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 <[email protected]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants