TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.7k stars 1.09k forks source link

[TT-12865] [5.3.5 backport] Rename config parameter, update usage, support mux params on legacy #6510

Closed titpetric closed 1 month ago

titpetric commented 1 month ago

User description

TT-12865 Rename config parameter, update usage, support mux params on legacy (#6506)

enhancement



Relevant files
Enhancement
config.go
Rename configuration fields for path matching options       

config/config.go
  • Renamed EnablePrefixMatching to EnablePathPrefixMatching.
  • Renamed EnableSuffixMatching to EnablePathSuffixMatching.
  • Updated comments to reflect the new naming conventions.
  • +12/-12 
    api_definition.go
    Update API definition to use new path matching config       

    gateway/api_definition.go
  • Updated variable names to use new path matching configuration fields.
  • +2/-2     
    mw_granular_access.go
    Refactor middleware to use updated path matching config   

    gateway/mw_granular_access.go
  • Updated variable names to use new path matching configuration fields.
  • Refactored pattern preparation using PreparePathRegexp.
  • +3/-9     
    session_manager.go
    Update session manager for new path matching config           

    gateway/session_manager.go
  • Updated variable names to use new path matching configuration fields.
  • +2/-2     
    schema.json
    Update JSON schema for path matching configuration             

    cli/linter/schema.json - Renamed JSON schema fields for path matching options.
    +2/-2     
    Tests
    api_definition_test.go
    Update test configuration for path prefix matching             

    gateway/api_definition_test.go - Modified test configuration to use `EnablePathPrefixMatching`.
    +1/-1     
    mw_granular_access_test.go
    Update middleware test for path prefix matching                   

    gateway/mw_granular_access_test.go - Modified test configuration to use `EnablePathPrefixMatching`.
    +1/-1     

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


    TT-12865: https://tyktech.atlassian.net/browse/TT-12865?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ


    Enhancement, Tests



    Relevant files
    Enhancement
    6 files
    config.go
    Add configuration for path prefix and suffix matching       

    config/config.go
  • Added new configuration fields EnablePathPrefixMatching and
    EnablePathSuffixMatching.
  • Updated comments to explain the new path matching configuration.
  • +43/-0   
    api_definition.go
    Refactor URLSpec and update path matching logic                   

    gateway/api_definition.go
  • Refactored URLSpec to use private fields and methods.
  • Updated path matching logic to support new configuration.
  • Renamed several functions for clarity.
  • +47/-142
    model_apispec.go
    Refactor and deprecate CheckSpecMatchesStatus                       

    gateway/model_apispec.go
  • Moved CheckSpecMatchesStatus to a separate file and deprecated it.
  • Added FindSpecMatchesStatus for improved status checking.
  • +75/-0   
    model_urlspec.go
    Add path and method matching methods to URLSpec                   

    gateway/model_urlspec.go
  • Added new methods to URLSpec for matching paths and methods.
  • Deprecated modeSpecificSpec method.
  • +120/-0 
    mw_granular_access.go
    Update GranularAccessMiddleware for new path matching       

    gateway/mw_granular_access.go
  • Updated middleware to use new path matching configuration.
  • Improved logging and error handling in path matching.
  • +74/-20 
    mux.go
    Refactor path regex preparation and matching                         

    internal/httputil/mux.go
  • Refactored path regex preparation and matching functions.
  • Improved caching and handling of mux-style parameters.
  • +78/-18 
    Tests
    4 files
    api_definition_test.go
    Update and add test cases for path matching logic               

    gateway/api_definition_test.go
  • Updated test cases to reflect changes in path matching logic.
  • Added new test cases for path prefix matching.
  • +12/-12 
    mw_granular_access_test.go
    Add tests for GranularAccessMiddleware path matching         

    gateway/mw_granular_access_test.go
  • Added tests for new path matching logic in GranularAccessMiddleware.
  • Updated existing tests to use new configuration.
  • +50/-28 
    mux_test.go
    Add tests for path regex preparation and matching               

    internal/httputil/mux_test.go
  • Added tests for new path matching functions.
  • Updated existing tests to reflect changes in regex preparation.
  • +112/-14
    issue_12865_test.go
    Add regression tests for issue 12865                                         

    tests/regression/issue_12865_test.go
  • Added regression tests for issue 12865.
  • Tested various configurations of path prefix and suffix matching.
  • +171/-0 
    Configuration changes
    2 files
    test.yml
    Update test task configuration                                                     

    .taskfiles/test.yml
  • Updated test task to exclude the first package in the list.
  • Added a task to merge coverage reports.
  • +2/-1     
    schema.json
    Update schema for new path matching configuration               

    cli/linter/schema.json - Added new schema fields for path prefix and suffix matching.
    +6/-0     

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


    Description

    Related Issue

    Motivation and Context

    How This Has Been Tested

    Screenshots (if appropriate)

    Types of changes

    Checklist


    PR Type

    Enhancement, Tests


    Description


    Changes walkthrough ๐Ÿ“

    Relevant files
    Enhancement
    5 files
    config.go
    Add new configuration fields for path matching                     

    config/config.go
  • Introduced new configuration fields EnablePathPrefixMatching and
    EnablePathSuffixMatching.
  • Added detailed comments explaining the new path matching
    configurations.
  • +43/-0   
    api_definition.go
    Refactor URLSpec and enhance path matching logic                 

    gateway/api_definition.go
  • Refactored URLSpec to use a private field for regex.
  • Added logic to handle path prefix and suffix matching.
  • Improved error logging for regex compilation.
  • +55/-166
    mw_granular_access.go
    Enhance GranularAccessMiddleware with path matching options

    gateway/mw_granular_access.go
  • Enhanced GranularAccessMiddleware to support new path matching
    options.
  • Improved logging for access checks.
  • +79/-12 
    mux.go
    Add utility functions for path regex handling                       

    internal/httputil/mux.go
  • Introduced utility functions for path regex preparation and matching.
  • Implemented caching for path regex patterns.
  • +139/-0 
    strings.go
    Implement concurrency-safe string map                                       

    internal/maps/strings.go
  • Introduced a concurrency-safe map for string storage.
  • Provided methods for setting and getting values.
  • +34/-0   
    Tests
    5 files
    api_definition_test.go
    Update and add tests for path matching configurations       

    gateway/api_definition_test.go
  • Updated test cases to reflect new path matching configurations.
  • Added new tests for prefix and suffix matching.
  • +16/-33 
    mw_granular_access_test.go
    Add tests for GranularAccessMiddleware path matching         

    gateway/mw_granular_access_test.go
  • Added tests for GranularAccessMiddleware with new path matching
    configurations.
  • Ensured coverage for both prefix and suffix matching scenarios.
  • +50/-24 
    mux_test.go
    Add tests for path regex utilities                                             

    internal/httputil/mux_test.go
  • Added tests for path regex preparation and matching utilities.
  • Verified caching behavior for regex patterns.
  • +162/-0 
    issue_12865_test.go
    Add regression tests for issue 12865                                         

    tests/regression/issue_12865_test.go
  • Added regression tests for issue 12865.
  • Tested various path matching configurations.
  • +171/-0 
    regression_test.go
    Refactor and test API spec loading utilities                         

    tests/regression/regression_test.go
  • Refactored utility functions for loading API specs.
  • Added test for loading API specs with environment variable
    replacement.
  • +23/-3   

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

    github-actions[bot] commented 1 month ago

    API Changes

    --- prev.txt    2024-09-12 19:01:01.859261628 +0000
    +++ current.txt 2024-09-12 19:00:58.683242013 +0000
    @@ -5512,6 +5512,49 @@
        // Regular expressions and parameterized routes will be left alone regardless of this setting.
        EnableStrictRoutes bool `json:"enable_strict_routes"`
    
    +   // EnablePathPrefixMatching changes the URL matching from wildcard mode to prefix mode.
    +   // For example, `/json` matches `*/json*` by current default behaviour.
    +   // If prefix matching is enabled, the match will be performed as a prefix match (`/json*`).
    +   //
    +   // The `/json` url would be matched as `^/json` against the following paths:
    +   //
    +   // - Full listen path and versioning URL (`/listen-path/v4/json`)
    +   // - Stripped listen path URL (`/v4/json`)
    +   // - Stripped version information (`/json`) - match.
    +   //
    +   // If versioning is disabled then the following URLs are considered:
    +   //
    +   // - Full listen path and endpoint (`/listen-path/json`)
    +   // - Stripped listen path (`/json`) - match.
    +   //
    +   // For inputs that start with `/`, a prefix match is ensured by
    +   // prepending the start of string `^` caret.
    +   //
    +   // For all other cases, the pattern remains unmodified.
    +   //
    +   // Combine this option with `enable_path_suffix_matching` to achieve
    +   // exact url matching with `/json` being evaluated as `^/json$`.
    +   EnablePathPrefixMatching bool `json:"enable_path_prefix_matching"`
    +
    +   // EnablePathSuffixMatching changes the URL matching to match as a suffix.
    +   // For example: `/json` is matched as `/json$` against the following paths:
    +   //
    +   // - Full listen path and versioning URL (`/listen-path/v4/json`)
    +   // - Stripped listen path URL (`/v4/json`)
    +   // - Stripped version information (`/json`) - match.
    +   //
    +   // If versioning is disabled then the following URLs are considered:
    +   //
    +   // - Full listen path and endpoint (`/listen-path/json`)
    +   // - Stripped listen path (`/json`) - match.
    +   //
    +   // If the input pattern already ends with a `$` (`/json$`)
    +   // then the pattern remains unmodified.
    +   //
    +   // Combine this option with `enable_path_prefix_matching` to achieve
    +   // exact url matching with `/json` being evaluated as `^/json$`.
    +   EnablePathSuffixMatching bool `json:"enable_path_suffix_matching"`
    +
        // Disable TLS verification. Required if you are using self-signed certificates.
        SSLInsecureSkipVerify bool `json:"ssl_insecure_skip_verify"`
    
    @@ -7422,10 +7465,16 @@
     func CloneAPI(a *APISpec) *APISpec
    
     func (a *APISpec) CheckSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mode URLStatus) (bool, interface{})
    -    CheckSpecMatchesStatus checks if a url spec has a specific status
    +    CheckSpecMatchesStatus checks if a URL spec has a specific status.
    +    Deprecated: The function doesn't follow go return conventions (T, ok);
    +    use FindSpecMatchesStatus;
    
     func (a *APISpec) Expired() bool
    
    +func (a *APISpec) FindSpecMatchesStatus(r *http.Request, rxPaths []URLSpec, mode URLStatus) (*URLSpec, bool)
    +    FindSpecMatchesStatus checks if a URL spec has a specific status and returns
    +    the URLSpec for it.
    +
     func (s *APISpec) FireEvent(name apidef.TykEvent, meta interface{})
    
     func (a *APISpec) GetSessionLifetimeRespectsKeyExpiration() bool
    @@ -7447,7 +7496,13 @@
    
     func (a *APISpec) StopSessionManagerPool()
    
    -func (a *APISpec) StripListenPath(r *http.Request, path string) string
    +func (a *APISpec) StripListenPath(reqPath string) string
    +    StripListenPath will strip the listen path from the URL, keeping version in
    +    tact.
    +
    +func (a *APISpec) StripVersionPath(reqPath string) string
    +    StripVersionPath will strip the version from the URL. The input URL should
    +    already have listen path stripped.
    
     func (a *APISpec) URLAllowedAndIgnored(r *http.Request, rxPaths []URLSpec, whiteListStatus bool) (RequestStatus, interface{})
         URLAllowedAndIgnored checks if a url is allowed and ignored.
    @@ -10066,7 +10121,6 @@
         system, return an error to have the chain fail
    
     type URLSpec struct {
    -   Spec                      *regexp.Regexp
        Status                    URLStatus
        MethodActions             map[string]apidef.EndpointMethodMeta
        Whitelist                 apidef.EndPointMeta
    @@ -10094,6 +10148,7 @@
        PersistGraphQL            apidef.PersistGraphQLMeta
    
        IgnoreCase bool
    +   // Has unexported fields.
     }
         URLSpec represents a flattened specification for URLs, used to check if
         a proxy URL path is on any of the white, black or ignored lists. This is
    @@ -11424,6 +11479,9 @@
     func Cert(domain string) tls.Certificate
         Generate cert
    
    +func Exclusive(t *testing.T)
    +    Exclusive uses a lock to gate only a single test running.
    +
     func Flaky(t *testing.T, fake ...func() (bool, func(...interface{})))
         Flaky skips a flaky test in a CI environment
    
    github-actions[bot] commented 1 month ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช PR contains tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Code Refactor
    The `GranularAccessMiddleware` has been significantly refactored to support new matching configurations (`EnablePathPrefixMatching` and `EnablePathSuffixMatching`). Ensure that the new logic correctly handles URL path matching according to these settings, especially the combination of prefix and suffix matching which aims to achieve exact URL matching. New Utility Functions
    New utility functions `PreparePathRegexp`, `StripListenPath`, and `MatchPaths` have been added to handle URL path manipulations and matching. Review these for correct implementation of regex patterns and ensure they handle edge cases, especially in URL transformations and matching logic. Refactoring
    The API definition loading and URL spec compilation logic have been refactored. Review the changes to ensure that the new methods correctly compile and handle URL specs, particularly the changes involving the handling of virtual paths, Go plugins, and tracked endpoints.
    github-actions[bot] commented 1 month ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Ensure the StripListenPath method is called with the request object to maintain context ___ **The method StripListenPath should be called with the request object r as a parameter
    to ensure that the path is correctly stripped based on the request context.** [gateway/handler_error.go [196]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-d3b05530ad23401f3b8f33bb1a467cd807a29a6b09c7430d01d069f626b20f77R196-R196) ```diff -r.URL.Path = e.Spec.StripListenPath(r.URL.Path) +r.URL.Path = e.Spec.StripListenPath(r, r.URL.Path) ```
    Suggestion importance[1-10]: 10 Why: The suggestion correctly identifies a potential bug where the `StripListenPath` method should be called with the request object to ensure the path is stripped correctly based on the request context. This is crucial for maintaining the intended functionality.
    10
    Correct the method call to include all required parameters ___ **Ensure that the StripListenPath method is called with the correct number of
    parameters. The original method seems to require two parameters, but only one is
    provided in the new code.** [gateway/mw_request_signing.go [86]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-4930d7e23ba3866e7a220c1eacff5701bc59b3029b47226c55432db0615fb55aR86-R86) ```diff if s.Spec.Proxy.StripListenPath { - path = s.Spec.StripListenPath(path) + path = s.Spec.StripListenPath(r, path) // Assuming the original method requires the request object and path } ```
    Suggestion importance[1-10]: 10 Why: The suggestion correctly identifies a potential bug where the `StripListenPath` method is called with an incorrect number of parameters, which could lead to runtime errors.
    10
    Add error handling after regex compilation to ensure stability ___ **Ensure error handling after compiling the regex to prevent runtime panics or
    unexpected behavior if the regex compilation fails.** [gateway/api_definition.go [835-836]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8bR835-R836) ```diff asRegex, err := regexp.Compile(pattern) -log.WithError(err).Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) +if err != nil { + log.WithError(err).Error("Failed to compile regex") + return +} +log.Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) ```
    Suggestion importance[1-10]: 9 Why: The suggestion correctly adds error handling after regex compilation, which is crucial to prevent runtime panics or unexpected behavior if the regex compilation fails. This addresses a potential bug and improves the robustness of the code.
    9
    Best practice
    Improve error handling for regex compilation to ensure continued pattern checking ___ **The error handling for regex compilation in GranularAccessMiddleware should be
    improved to ensure that the loop continues to the next pattern if the current one
    fails to compile, rather than blocking access immediately.** [gateway/mw_granular_access.go [100-109]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-618f7d55751d572562a29506a13beba2da969436e974f8b51df7d9708c925436R100-R109) ```diff +asRegex, err := regexp.Compile(pattern) +if err != nil { + logger.WithError(err).Error("error compiling regex") + continue +} - ```
    Suggestion importance[1-10]: 9 Why: The suggestion addresses a best practice by ensuring that regex compilation errors do not block access immediately, allowing the loop to continue checking other patterns. This is important for robust error handling.
    9
    Performance
    Cache compiled regex patterns to enhance performance ___ **To improve the performance and reduce the overhead of regex operations, consider
    caching compiled regex patterns instead of compiling them every time in the
    MatchPath function.** [internal/httputil/mux.go [113-118]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-3d9ee5f5e946d72e6f2ae662ff03ee5253bbdc15203d2e4f6e9f46c13011ebf8R113-R118) ```diff -asRegex, err := regexp.Compile(pattern) -if err != nil { - return false, err +// Use a global cache to store compiled regex patterns +var regexCache = make(map[string]*regexp.Regexp) +asRegex, found := regexCache[pattern] +if !found { + var err error + asRegex, err = regexp.Compile(pattern) + if err != nil { + return false, err + } + regexCache[pattern] = asRegex } return asRegex.MatchString(endpoint), nil ```
    Suggestion importance[1-10]: 9 Why: Caching compiled regex patterns can significantly enhance performance by reducing the overhead of repeated compilations, especially in high-frequency operations like URL matching.
    9
    Enhancement
    Use error logging for regex compilation failures to improve error visibility ___ **Use a more specific log level than Debug for regex compilation errors to ensure
    visibility in production environments.** [gateway/api_definition.go [836]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8bR836-R836) ```diff -log.WithError(err).Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) +if err != nil { + log.WithError(err).Errorf("Failed to compile regex for URLSpec: %s", stringSpec) +} else { + log.Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) +} ```
    Suggestion importance[1-10]: 8 Why: Changing the log level to `Error` for regex compilation failures is a good enhancement for production environments, as it ensures that such critical issues are not overlooked.
    8
    Handle cases where accessSpec.Methods is empty to imply all methods are allowed ___ **The GranularAccessMiddleware should handle the case where the accessSpec.Methods
    slice is empty, which implies that all methods are allowed. This can be done by
    adding a condition to check if the slice is empty before checking if the method is
    contained in the slice.** [gateway/mw_granular_access.go [56-58]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-618f7d55751d572562a29506a13beba2da969436e974f8b51df7d9708c925436R56-R58) ```diff -if !slices.Contains(accessSpec.Methods, r.Method) { +if len(accessSpec.Methods) > 0 && !slices.Contains(accessSpec.Methods, r.Method) { continue } ```
    Suggestion importance[1-10]: 8 Why: The suggestion enhances the code by handling cases where `accessSpec.Methods` is empty, allowing all methods. This improves the flexibility and correctness of the middleware logic.
    8
    Possible issue
    Validate stringSpec to ensure it is not empty before processing ___ **Consider validating stringSpec before processing to ensure it's a valid input, which
    can prevent potential runtime errors.** [gateway/api_definition.go [828]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8bR828-R828) ```diff +if stringSpec == "" { + log.Error("stringSpec cannot be empty") + return +} pattern = httputil.PreparePathRegexp(stringSpec, isPrefixMatch, isSuffixMatch) ```
    Suggestion importance[1-10]: 8 Why: Validating `stringSpec` before processing is a good practice to prevent potential runtime errors, ensuring that the input is valid and reducing the likelihood of unexpected behavior.
    8
    Security
    Improve security by using more restrictive regex patterns in URL matching ___ **Consider using a more specific regex pattern to avoid potential security risks
    associated with overly permissive patterns. For example, change the wildcard
    replacement from .* to a more restrictive pattern.** [internal/httputil/mux.go [42-45]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-3d9ee5f5e946d72e6f2ae662ff03ee5253bbdc15203d2e4f6e9f46c13011ebf8R42-R45) ```diff if strings.Contains(pattern, "/*") { pattern = strings.ReplaceAll(pattern, "/*/", "/[^/]+/") - pattern = strings.ReplaceAll(pattern, "/*", "/.*") + pattern = strings.ReplaceAll(pattern, "/*", "/[^/]*") // Change to match any character except '/' } ```
    Suggestion importance[1-10]: 8 Why: The suggestion improves security by recommending a more restrictive regex pattern, reducing the risk of unintended matches, which is crucial for URL matching.
    8
    Maintainability
    Refactor generateRegex to improve code clarity and error handling ___ **Refactor the generateRegex function to separate concerns, improving readability and
    maintainability.** [gateway/api_definition.go [819-836]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-0cf80174bbafb36f6d4f4308ebbd971b2833b76a936bad568220aa1a4ba0ee8bR819-R836) ```diff -var ( - pattern string - err error -) -... +pattern, err := preparePattern(stringSpec, isPrefixMatch, isSuffixMatch, isIgnoreCase) +if err != nil { + log.WithError(err).Error("Failed to prepare regex pattern") + return +} asRegex, err := regexp.Compile(pattern) -log.WithError(err).Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) +if err != nil { + log.WithError(err).Error("Failed to compile regex") + return +} +log.Debugf("URLSpec: %s => %s type=%d", stringSpec, pattern, specType) ```
    Suggestion importance[1-10]: 7 Why: The refactoring suggestion improves code readability and maintainability by separating concerns and enhancing error handling, though it is not as critical as the previous suggestions.
    7
    Improve logging clarity and reduce redundancy in GranularAccessMiddleware ___ **Refactor the logging within the GranularAccessMiddleware to reduce redundancy and
    improve clarity. Specifically, consolidate the logging setup and use structured
    logging consistently.** [gateway/mw_granular_access.go [53-122]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-618f7d55751d572562a29506a13beba2da969436e974f8b51df7d9708c925436R53-R122) ```diff -logger := m.Logger().WithField("paths", urlPaths) +logger := m.Logger().WithFields(logrus.Fields{ + "paths": urlPaths, + "pattern": pattern, + "match": match +}) ... -logger = logger.WithError(err).WithField("pattern", pattern).WithField("match", match) +if err != nil { + logger.WithError(err).Error("error matching endpoint") +} else { + logger.Debug("matching endpoint") +} ... logger.Info("Attempted access to unauthorised endpoint (Granular).") ```
    Suggestion importance[1-10]: 6 Why: The suggestion improves code maintainability by consolidating logging setup and using structured logging consistently, which enhances readability and reduces redundancy.
    6
    Refactor repeated code blocks into a loop for setting AllowedURLs in API configurations ___ **Consider using a loop to avoid code duplication when setting up AllowedURLs for
    different API configurations. This will make the code more maintainable and less
    error-prone.** [gateway/mw_granular_access_test.go [24-41]](https://github.com/TykTechnologies/tyk/pull/6510/files#diff-8e0d7cfef26688edd7d08334d955039dab5deb3caf860d29eff6d09894eaba20R24-R41) ```diff allowedURLs := []user.AccessSpec{ { URL: "^/valid_path", Methods: []string{"GET"}, }, { URL: "^/test/try_valid_path", Methods: []string{"GET"}, }, } -_, directKey := g.CreateSession(func(s *user.SessionState) { - s.AccessRights = map[string]user.AccessDefinition{ - api.APIID: { - APIID: api.APIID, - APIName: api.Name, - AllowedURLs: allowedURLs, - }, - } -}) +apiConfigs := []string{api.APIID, anotherAPI.APIID} // Add other API IDs as needed +for _, apiID := range apiConfigs { + _, directKey := g.CreateSession(func(s *user.SessionState) { + s.AccessRights = map[string]user.AccessDefinition{ + apiID: { + APIID: api.APIID, + APIName: api.Name, + AllowedURLs: allowedURLs, + }, + } + }) +} ```
    Suggestion importance[1-10]: 5 Why: The suggestion to use a loop for setting up `AllowedURLs` can improve maintainability by reducing code duplication, but the current code is not overly complex, so the improvement is minor.
    5
    sonarcloud[bot] commented 1 month ago

    Quality Gate Failed Quality Gate failed

    Failed conditions
    78.9% Coverage on New Code (required โ‰ฅ 80%)
    C Reliability Rating on New Code (required โ‰ฅ A)

    See analysis details on SonarCloud

    Catch issues before they fail your Quality Gate with our IDE extension SonarLint