Skip to content

[TT-10104] JS middleware + ignore auth test and fix for panic#6180

Merged
titpetric merged 7 commits into
masterfrom
fix/tt-10104/replicate-panic-with-test
Mar 26, 2024
Merged

[TT-10104] JS middleware + ignore auth test and fix for panic#6180
titpetric merged 7 commits into
masterfrom
fix/tt-10104/replicate-panic-with-test

Conversation

@titpetric

@titpetric titpetric commented Mar 23, 2024

Copy link
Copy Markdown
Contributor

User description

  • add regression test suite to replicate panic with supplied apidef/scripts
  • fixes panic due to missing session data in JS middleware

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


Type

bug_fix, tests


Description

  • Fixed a panic issue in the JS middleware by adding a nil check for the session object.
  • Added a comprehensive regression test suite for issue TT-10104 to prevent future occurrences.
  • Introduced utility functions and documentation to aid in the setup and understanding of regression tests.
  • Included a Taskfile for streamlined execution of regression tests.

Changes walkthrough

Relevant files
Bug fix
mw_js_plugin.go
Fix panic due to nil session in JS middleware                       

gateway/mw_js_plugin.go

  • Added a nil check for session before accessing session.MetaData to
    prevent panic.
  • +1/-1     
    Tests
    issue_10104_test.go
    Add regression test for issue TT-10104                                     

    tests/regression/issue_10104_test.go

  • Introduced a regression test for issue TT-10104 to ensure no panic
    occurs with JS middleware.
  • +22/-0   
    regression_test.go
    Utility functions for regression tests setup                         

    tests/regression/regression_test.go

  • Added utility functions for loading API specifications and files
    within regression tests.
  • +40/-0   
    issue-10104-script.js
    JS script for replicating panic scenario in tests               

    tests/regression/testdata/issue-10104-script.js

  • Added a JS script to replicate the scenario causing the panic for
    testing purposes.
  • +7/-0     
    issue-10104-apidef.json
    API definition for regression test of issue TT-10104         

    tests/regression/testdata/issue-10104-apidef.json

  • Included an API definition JSON file used by the regression test for
    issue TT-10104.
  • +469/-0 
    Documentation
    README.md
    Documentation for regression tests structure and conventions

    tests/regression/README.md

  • Provided documentation on the structure and conventions for adding
    regression tests.
  • +10/-0   
    Configuration changes
    Taskfile.yml
    Taskfile for managing regression tests execution                 

    tests/regression/Taskfile.yml

  • Added a Taskfile for running regression tests with specific commands
    and environment variables.
  • +42/-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 Mar 23, 2024

    Copy link
    Copy Markdown
    Contributor

    API Changes

    --- prev.txt	2024-03-26 10:14:31.813098767 +0000
    +++ current.txt	2024-03-26 10:14:28.801073492 +0000
    @@ -11352,6 +11352,8 @@
         manipulate
     
     func MyPluginReturningError(rw http.ResponseWriter, r *http.Request)
    +# Package: ./tests/regression
    +
     # Package: ./trace
     
     package trace // import "github.com/TykTechnologies/tyk/trace"

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Description updated to latest commit (af880fd)

    @github-actions

    Copy link
    Copy Markdown
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized, but require understanding of the context and potential side effects, especially the nil check in the middleware and the structure of the regression tests.

    🧪 Relevant tests

    Yes

    🔍 Possible issues

    Possible Bug: The nil check in mw_js_plugin.go fixes a panic, but it's important to ensure that the absence of a session is handled correctly elsewhere in the code. If a session is expected but not present, this could indicate a deeper logic issue that might need addressing.

    🔒 Security concerns

    No

    Code feedback:
    relevant filegateway/mw_js_plugin.go
    suggestion      

    Consider logging a warning or error when session is nil. This could help in debugging and understanding why a session might be missing in scenarios where it's expected. [important]

    relevant lineif session != nil && !reflect.DeepEqual(session.MetaData, newMeta) {

    relevant filetests/regression/issue_10104_test.go
    suggestion      

    It's good practice to assert more specific outcomes in tests beyond just HTTP status codes. Consider verifying the response body or specific headers to ensure the middleware behaves as expected. [medium]

    relevant line{Path: "/test/", Method: http.MethodGet, Code: http.StatusOK},

    relevant filetests/regression/regression_test.go
    suggestion      

    For better modularity and reusability, consider moving loadAPISpec and loadFile functions to a shared package if they are or will be used across different test suites. [medium]

    relevant linefunc loadAPISpec(tb testing.TB, filename string) *gateway.APISpec {

    relevant filetests/regression/testdata/issue-10104-apidef.json
    suggestion      

    Ensure sensitive information like org_id and api_id in the test data is anonymized or generic to avoid potential exposure of real environment details. [important]

    relevant line"org_id": "64f5dde7cc8ab1000125978d",


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, require_can_be_split_review, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    @github-actions

    github-actions Bot commented Mar 23, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Possible issue
    Add nil check for session.MetaData before using reflect.DeepEqual.

    Consider checking if session.MetaData is nil before calling reflect.DeepEqual to avoid
    potential panics when session.MetaData is nil.

    gateway/mw_js_plugin.go [270]

    -if session != nil && !reflect.DeepEqual(session.MetaData, newMeta) {
    +if session != nil && session.MetaData != nil && !reflect.DeepEqual(session.MetaData, newMeta) {
     
    Enhancement
    Add more diverse test cases to the regression test.

    To ensure the test is robust, consider adding more test cases with different request
    methods or body content to fully cover the functionality related to the issue.

    tests/regression/issue_10104_test.go [19-20]

     ts.Run(t, []test.TestCase{
         {Path: "/test/", Method: http.MethodGet, Code: http.StatusOK},
    +    {Path: "/test/", Method: http.MethodPost, Body: "{\"key\":\"value\"}", Code: http.StatusOK},
    +    // Add more test cases as needed
     }...)
     
    Improve error messages by including the filename.

    For better error handling, consider logging the filename when require.NoError fails, to
    make it easier to identify which file caused the error.

    tests/regression/regression_test.go [22]

    -require.NoError(tb, err)
    +require.NoError(tb, err, "Error reading file: "+filename)
     
    Add a linting task to the Taskfile.

    Consider adding a task for linting to encourage code quality and consistency across the
    project.

    tests/regression/Taskfile.yml [18]

    +- task: lint
     - task: fmt
     
    Best practice
    Use console.log for logging.

    It's recommended to use console.log for logging in JavaScript instead of log, unless log
    is a custom function defined elsewhere for specific logging purposes.

    tests/regression/testdata/issue-10104-script.js [5]

    -log('just some logging')
    +console.log('just some logging')
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    @TykTechnologies TykTechnologies deleted a comment from github-actions Bot Mar 23, 2024
    @titpetric
    titpetric requested a review from a team as a code owner March 26, 2024 08:53
    @titpetric
    titpetric force-pushed the fix/tt-10104/replicate-panic-with-test branch from f576f81 to 070c917 Compare March 26, 2024 10:12
    @titpetric
    titpetric force-pushed the fix/tt-10104/replicate-panic-with-test branch from 070c917 to 2d7ce18 Compare March 26, 2024 10:13
    @github-actions

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @sonarqubecloud

    Copy link
    Copy Markdown

    @titpetric
    titpetric merged commit e723d10 into master Mar 26, 2024
    @titpetric
    titpetric deleted the fix/tt-10104/replicate-panic-with-test branch March 26, 2024 10:45
    @titpetric

    Copy link
    Copy Markdown
    Contributor Author

    /release to release-5.3

    @tykbot

    tykbot Bot commented Mar 26, 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 Mar 26, 2024
    ## **User description**
    - add regression test suite to replicate panic with supplied
    apidef/scripts
    - fixes panic due to missing session data in JS middleware
    
    https://tyktech.atlassian.net/browse/TT-10104
    
    
    ___
    
    ## **Type**
    bug_fix, tests
    
    
    ___
    
    ## **Description**
    - Fixed a panic issue in the JS middleware by adding a nil check for the
    session object.
    - Added a comprehensive regression test suite for issue TT-10104 to
    prevent future occurrences.
    - Introduced utility functions and documentation to aid in the setup and
    understanding of regression tests.
    - Included a Taskfile for streamlined execution of regression tests.
    
    
    ___
    
    
    
    ## **Changes walkthrough**
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Bug
    fix</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_js_plugin.go</strong><dd><code>Fix panic due to nil
    session in JS middleware</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/mw_js_plugin.go
    <li>Added a nil check for session before accessing session.MetaData to
    <br>prevent panic.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-78cd278aba997558b7daa7897051a794ef860076d45c93be792791db39381ca0">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>issue_10104_test.go</strong><dd><code>Add regression
    test for issue TT-10104</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_10104_test.go
    <li>Introduced a regression test for issue TT-10104 to ensure no panic
    <br>occurs with JS middleware.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-fc9eecfe93848b08071a184af53473165b641230bccba931e8abbed89ac03d82">+22/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>regression_test.go</strong><dd><code>Utility functions
    for regression tests setup</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/regression_test.go
    <li>Added utility functions for loading API specifications and files
    <br>within regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-24d0ac1f4eb4bb6e33d0db26aca8ef96aef2b67fd2730fcde6e952ce3d894696">+40/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-script.js</strong><dd><code>JS script for
    replicating panic scenario in tests</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-script.js
    <li>Added a JS script to replicate the scenario causing the panic for
    <br>testing purposes.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-651e25aaab23d941e1c4153852448530cc72876f62332a4d46ef619a85dc4bbb">+7/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-apidef.json</strong><dd><code>API
    definition for regression test of issue TT-10104</code>&nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-apidef.json
    <li>Included an API definition JSON file used by the regression test for
    <br>issue TT-10104.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-7e34a83291fc3017307d4734f586656cc80364a1d89cf286e9acd8d34e9c738e">+469/-0</a>&nbsp;
    </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Documentation</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>README.md</strong><dd><code>Documentation for
    regression tests structure and conventions</code></dd></summary>
    <hr>
    
    tests/regression/README.md
    <li>Provided documentation on the structure and conventions for adding
    <br>regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-ca1649dd4084b45ff660ae7552d4fcd49f45a52e0e3c96991751e63452020a8f">+10/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Configuration
    changes</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>Taskfile.yml</strong><dd><code>Taskfile for managing
    regression tests execution</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/Taskfile.yml
    <li>Added a Taskfile for running regression tests with specific commands
    <br>and environment variables.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-32da89368e3551ec281e80af08b54c3410bcea3257e75af6bac113a51d822a55">+42/-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 e723d10)
    buger added a commit that referenced this pull request Mar 26, 2024
    …nd fix for panic (#6180)
    
    [TT-10104] JS middleware + ignore auth test and fix for panic (#6180)
    
    ## **User description**
    - add regression test suite to replicate panic with supplied
    apidef/scripts
    - fixes panic due to missing session data in JS middleware
    
    https://tyktech.atlassian.net/browse/TT-10104
    
    
    ___
    
    ## **Type**
    bug_fix, tests
    
    
    ___
    
    ## **Description**
    - Fixed a panic issue in the JS middleware by adding a nil check for the
    session object.
    - Added a comprehensive regression test suite for issue TT-10104 to
    prevent future occurrences.
    - Introduced utility functions and documentation to aid in the setup and
    understanding of regression tests.
    - Included a Taskfile for streamlined execution of regression tests.
    
    
    ___
    
    
    
    ## **Changes walkthrough**
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Bug
    fix</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_js_plugin.go</strong><dd><code>Fix panic due to nil
    session in JS middleware</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/mw_js_plugin.go
    <li>Added a nil check for session before accessing session.MetaData to
    <br>prevent panic.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-78cd278aba997558b7daa7897051a794ef860076d45c93be792791db39381ca0">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>issue_10104_test.go</strong><dd><code>Add regression
    test for issue TT-10104</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_10104_test.go
    <li>Introduced a regression test for issue TT-10104 to ensure no panic
    <br>occurs with JS middleware.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-fc9eecfe93848b08071a184af53473165b641230bccba931e8abbed89ac03d82">+22/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>regression_test.go</strong><dd><code>Utility functions
    for regression tests setup</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/regression_test.go
    <li>Added utility functions for loading API specifications and files
    <br>within regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-24d0ac1f4eb4bb6e33d0db26aca8ef96aef2b67fd2730fcde6e952ce3d894696">+40/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-script.js</strong><dd><code>JS script for
    replicating panic scenario in tests</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-script.js
    <li>Added a JS script to replicate the scenario causing the panic for
    <br>testing purposes.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-651e25aaab23d941e1c4153852448530cc72876f62332a4d46ef619a85dc4bbb">+7/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-apidef.json</strong><dd><code>API
    definition for regression test of issue TT-10104</code>&nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-apidef.json
    <li>Included an API definition JSON file used by the regression test for
    <br>issue TT-10104.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-7e34a83291fc3017307d4734f586656cc80364a1d89cf286e9acd8d34e9c738e">+469/-0</a>&nbsp;
    </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Documentation</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>README.md</strong><dd><code>Documentation for
    regression tests structure and conventions</code></dd></summary>
    <hr>
    
    tests/regression/README.md
    <li>Provided documentation on the structure and conventions for adding
    <br>regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-ca1649dd4084b45ff660ae7552d4fcd49f45a52e0e3c96991751e63452020a8f">+10/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Configuration
    changes</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>Taskfile.yml</strong><dd><code>Taskfile for managing
    regression tests execution</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/Taskfile.yml
    <li>Added a Taskfile for running regression tests with specific commands
    <br>and environment variables.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-32da89368e3551ec281e80af08b54c3410bcea3257e75af6bac113a51d822a55">+42/-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]>
    @tykbot

    tykbot Bot commented Mar 26, 2024

    Copy link
    Copy Markdown

    @titpetric Succesfully merged PR

    @titpetric

    Copy link
    Copy Markdown
    Contributor Author

    /release to release-5-lts

    @tykbot

    tykbot Bot commented Mar 26, 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 Mar 26, 2024
    ## **User description**
    - add regression test suite to replicate panic with supplied
    apidef/scripts
    - fixes panic due to missing session data in JS middleware
    
    https://tyktech.atlassian.net/browse/TT-10104
    
    
    ___
    
    ## **Type**
    bug_fix, tests
    
    
    ___
    
    ## **Description**
    - Fixed a panic issue in the JS middleware by adding a nil check for the
    session object.
    - Added a comprehensive regression test suite for issue TT-10104 to
    prevent future occurrences.
    - Introduced utility functions and documentation to aid in the setup and
    understanding of regression tests.
    - Included a Taskfile for streamlined execution of regression tests.
    
    
    ___
    
    
    
    ## **Changes walkthrough**
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Bug
    fix</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_js_plugin.go</strong><dd><code>Fix panic due to nil
    session in JS middleware</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/mw_js_plugin.go
    <li>Added a nil check for session before accessing session.MetaData to
    <br>prevent panic.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-78cd278aba997558b7daa7897051a794ef860076d45c93be792791db39381ca0">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>issue_10104_test.go</strong><dd><code>Add regression
    test for issue TT-10104</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_10104_test.go
    <li>Introduced a regression test for issue TT-10104 to ensure no panic
    <br>occurs with JS middleware.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-fc9eecfe93848b08071a184af53473165b641230bccba931e8abbed89ac03d82">+22/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>regression_test.go</strong><dd><code>Utility functions
    for regression tests setup</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/regression_test.go
    <li>Added utility functions for loading API specifications and files
    <br>within regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-24d0ac1f4eb4bb6e33d0db26aca8ef96aef2b67fd2730fcde6e952ce3d894696">+40/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-script.js</strong><dd><code>JS script for
    replicating panic scenario in tests</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-script.js
    <li>Added a JS script to replicate the scenario causing the panic for
    <br>testing purposes.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-651e25aaab23d941e1c4153852448530cc72876f62332a4d46ef619a85dc4bbb">+7/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-apidef.json</strong><dd><code>API
    definition for regression test of issue TT-10104</code>&nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-apidef.json
    <li>Included an API definition JSON file used by the regression test for
    <br>issue TT-10104.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-7e34a83291fc3017307d4734f586656cc80364a1d89cf286e9acd8d34e9c738e">+469/-0</a>&nbsp;
    </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Documentation</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>README.md</strong><dd><code>Documentation for
    regression tests structure and conventions</code></dd></summary>
    <hr>
    
    tests/regression/README.md
    <li>Provided documentation on the structure and conventions for adding
    <br>regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-ca1649dd4084b45ff660ae7552d4fcd49f45a52e0e3c96991751e63452020a8f">+10/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Configuration
    changes</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>Taskfile.yml</strong><dd><code>Taskfile for managing
    regression tests execution</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/Taskfile.yml
    <li>Added a Taskfile for running regression tests with specific commands
    <br>and environment variables.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-32da89368e3551ec281e80af08b54c3410bcea3257e75af6bac113a51d822a55">+42/-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 e723d10)
    @tykbot

    tykbot Bot commented Mar 26, 2024

    Copy link
    Copy Markdown

    @titpetric Succesfully merged PR

    buger added a commit that referenced this pull request Mar 26, 2024
    … and fix for panic (#6180)
    
    [TT-10104] JS middleware + ignore auth test and fix for panic (#6180)
    
    ## **User description**
    - add regression test suite to replicate panic with supplied
    apidef/scripts
    - fixes panic due to missing session data in JS middleware
    
    https://tyktech.atlassian.net/browse/TT-10104
    
    
    ___
    
    ## **Type**
    bug_fix, tests
    
    
    ___
    
    ## **Description**
    - Fixed a panic issue in the JS middleware by adding a nil check for the
    session object.
    - Added a comprehensive regression test suite for issue TT-10104 to
    prevent future occurrences.
    - Introduced utility functions and documentation to aid in the setup and
    understanding of regression tests.
    - Included a Taskfile for streamlined execution of regression tests.
    
    
    ___
    
    
    
    ## **Changes walkthrough**
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Bug
    fix</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>mw_js_plugin.go</strong><dd><code>Fix panic due to nil
    session in JS middleware</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    gateway/mw_js_plugin.go
    <li>Added a nil check for session before accessing session.MetaData to
    <br>prevent panic.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-78cd278aba997558b7daa7897051a794ef860076d45c93be792791db39381ca0">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Tests</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>issue_10104_test.go</strong><dd><code>Add regression
    test for issue TT-10104</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/issue_10104_test.go
    <li>Introduced a regression test for issue TT-10104 to ensure no panic
    <br>occurs with JS middleware.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-fc9eecfe93848b08071a184af53473165b641230bccba931e8abbed89ac03d82">+22/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>regression_test.go</strong><dd><code>Utility functions
    for regression tests setup</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/regression_test.go
    <li>Added utility functions for loading API specifications and files
    <br>within regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-24d0ac1f4eb4bb6e33d0db26aca8ef96aef2b67fd2730fcde6e952ce3d894696">+40/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-script.js</strong><dd><code>JS script for
    replicating panic scenario in tests</code>&nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-script.js
    <li>Added a JS script to replicate the scenario causing the panic for
    <br>testing purposes.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-651e25aaab23d941e1c4153852448530cc72876f62332a4d46ef619a85dc4bbb">+7/-0</a>&nbsp;
    &nbsp; &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>issue-10104-apidef.json</strong><dd><code>API
    definition for regression test of issue TT-10104</code>&nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/testdata/issue-10104-apidef.json
    <li>Included an API definition JSON file used by the regression test for
    <br>issue TT-10104.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-7e34a83291fc3017307d4734f586656cc80364a1d89cf286e9acd8d34e9c738e">+469/-0</a>&nbsp;
    </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Documentation</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>README.md</strong><dd><code>Documentation for
    regression tests structure and conventions</code></dd></summary>
    <hr>
    
    tests/regression/README.md
    <li>Provided documentation on the structure and conventions for adding
    <br>regression tests.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-ca1649dd4084b45ff660ae7552d4fcd49f45a52e0e3c96991751e63452020a8f">+10/-0</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    </table></td></tr><tr><td><strong>Configuration
    changes</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>Taskfile.yml</strong><dd><code>Taskfile for managing
    regression tests execution</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    tests/regression/Taskfile.yml
    <li>Added a Taskfile for running regression tests with specific commands
    <br>and environment variables.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6180/files#diff-32da89368e3551ec281e80af08b54c3410bcea3257e75af6bac113a51d822a55">+42/-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.

    2 participants