Closed titpetric closed 1 month ago
Let's make that PR title a ๐ฏ shall we? ๐ช
<p>
Your <em>PR title</em> and <em>story title</em> look <strong>slightly different</strong>. Just checking in to know if it was intentional!
</p>
<table>
<tr>
<th>Story Title</th>
<td>[Security]Path-Based Permissions permissions in policies are not preserved when policies are combined</td>
</tr>
<tr>
<th>PR Title</th>
<td>[TT-12897/TT-13284] Add additional partitioned test case, fix ordering issue</td>
</tr>
</table>
<p>
Check out this <a href="https://www.atlassian.com/blog/git/written-unwritten-guide-pull-requests">guide</a> to learn more about PR best-practices.
</p>
Here are some key observations to aid the review process:
โฑ๏ธ Estimated effort to review: 3 ๐ต๐ต๐ตโชโช |
๐งช PR contains tests |
๐ No security concerns identified |
โก Recommended focus areas for review Code Redundancy The logic for merging field access rights, restricted types, and allowed types is repetitive and could be refactored into a more generic function to improve maintainability and reduce code duplication. Error Handling The new code does not handle potential errors from the `intersection` function used in merging types fields. This could lead to runtime panics if the function fails. |
API Changes
no api changes detected
Explore these optional code suggestions:
Category | Suggestion | Score |
Best practice |
Add validation for
___
**Validate the | 8 |
Possible issue |
Avoid potential concurrent map write issues by using a temporary map for updates___ **Ensure that therights map is not modified directly within the loop to avoid potential concurrent map write issues. Consider using a temporary map to store updates and merge them back to rights after the loop.**
[internal/policy/apply.go [358-362]](https://github.com/TykTechnologies/tyk/pull/6635/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1R358-R362)
```diff
+tempRights := make(map[string]user.AccessDefinition)
for k := range policy.AccessRights {
if _, ok := rights[k]; ok {
continue
}
- rights[k] = user.AccessDefinition{}
+ tempRights[k] = user.AccessDefinition{}
+}
+for k, v := range tempRights {
+ rights[k] = v
}
```
Suggestion importance[1-10]: 7Why: This suggestion addresses potential concurrent map write issues by using a temporary map for updates, which is a valid concern in concurrent programming. It enhances the robustness of the code, making it safer for concurrent execution. | 7 |
Enhancement |
Improve the efficiency and readability of merging type fields___ **Refactor the nested loops that mergeRestrictedTypes and AllowedTypes to improve efficiency and readability. Consider using a map to track types and reduce the complexity of the operation.** [internal/policy/apply.go [385-389]](https://github.com/TykTechnologies/tyk/pull/6635/files#diff-59b92e9d31f142f1d99b746eb3ff7db4e26bf6c3044c9b87b58034a947ee04d1R385-R389) ```diff +restrictedTypeMap := make(map[string]int) +for i, rt := range r.RestrictedTypes { + restrictedTypeMap[rt.Name] = i +} for _, t := range v.RestrictedTypes { - for ri, rt := range r.RestrictedTypes { - if t.Name == rt.Name { - r.RestrictedTypes[ri].Fields = intersection(rt.Fields, t.Fields) - } + if i, exists := restrictedTypeMap[t.Name]; exists { + r.RestrictedTypes[i].Fields = intersection(r.RestrictedTypes[i].Fields, t.Fields) } } ``` Suggestion importance[1-10]: 6Why: The suggestion improves the efficiency and readability of the code by using a map to track types, reducing the complexity of nested loops. This is a beneficial enhancement for maintainability and performance. | 6 |
Failed conditions
0.0% Coverage on New Code (required โฅ 80%)
/release to release-5.3
Working on it! Note that it can take a few minutes.
@titpetric Succesfully merged PR
User description
TT-12897
Subtask: https://tyktech.atlassian.net/browse/TT-13284 Parent: https://tyktech.atlassian.net/browse/TT-12897
PR Type
Bug fix, Tests
Description
applyPartitions
function to ensurerights
map is filled with known APIs, ensuring policies with ACL rights are honored even if not first.RestrictedTypes
,AllowedTypes
, andFieldAccessRights
to handle empty cases and intersections correctly.Changes walkthrough ๐
apply.go
Fix policy merging and ordering issues in partitioned policies
internal/policy/apply.go
rights
map is filled with known APIs to honor policies.RestrictedTypes
,AllowedTypes
, andFieldAccessRights
.rights.
apply_test.go
Add test cases for ACL and rate limit application
internal/policy/apply_test.go