Skip to content

Commit

Permalink
Revert "Merging to release-5.2: [TT-10109] Fix policy lookup map dist… (
Browse files Browse the repository at this point in the history
#5755)

…ortion (#5730)"

This reverts commit c6dc825.

<!-- Provide a general summary of your changes in the Title above -->

## Description

<!-- Describe your changes in detail -->

## Related Issue

<!-- This project only accepts pull requests related to open issues. -->
<!-- If suggesting a new feature or change, please discuss it in an
issue first. -->
<!-- If fixing a bug, there should be an issue describing it with steps
to reproduce. -->
<!-- OSS: Please link to the issue here. Tyk: please create/link the
JIRA ticket. -->

## Motivation and Context

<!-- Why is this change required? What problem does it solve? -->

## How This Has Been Tested

<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests -->
<!-- you ran to see how your change affects other areas of the code,
etc. -->
<!-- This information is helpful for reviewers and QA. -->

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why
  • Loading branch information
furkansenharputlu authored Nov 8, 2023
1 parent c6dc825 commit 9416376
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 92 deletions.
22 changes: 0 additions & 22 deletions gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ func (t BaseMiddleware) ApplyPolicies(session *user.SessionState) error {
if !usePartitions || policy.Partitions.Acl {
didACL[k] = true

ar.AllowedURLs = copyAllowedURLs(v.AllowedURLs)

// Merge ACLs for the same API
if r, ok := rights[k]; ok {
// If GQL introspection is disabled, keep that configuration.
Expand Down Expand Up @@ -762,26 +760,6 @@ func (t BaseMiddleware) ApplyPolicies(session *user.SessionState) error {
return nil
}

func copyAllowedURLs(input []user.AccessSpec) []user.AccessSpec {
if input == nil {
return nil
}

copied := make([]user.AccessSpec, len(input))

for i, as := range input {
copied[i] = user.AccessSpec{
URL: as.URL,
}
if as.Methods != nil {
copied[i].Methods = make([]string, len(as.Methods))
copy(copied[i].Methods, as.Methods)
}
}

return copied
}

// CheckSessionAndIdentityForValidKey will check first the Session store for a valid key, if not found, it will try
// the Auth Handler, if not found it will fail
func (t BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string, r *http.Request) (user.SessionState, bool) {
Expand Down
62 changes: 0 additions & 62 deletions gateway/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,65 +343,3 @@ func TestSessionLimiter_RedisQuotaExceeded_PerAPI(t *testing.T) {
sendReqAndCheckQuota(t, apis[2].APIID, 24, false)
sendReqAndCheckQuota(t, apis[2].APIID, 23, false)
}

func TestCopyAllowedURLs(t *testing.T) {
testCases := []struct {
name string
input []user.AccessSpec
}{
{
name: "Copy non-empty slice of AccessSpec with non-empty Methods",
input: []user.AccessSpec{
{
URL: "http://example.com",
Methods: []string{"GET", "POST"},
},
{
URL: "http://example.org",
Methods: []string{"GET"},
},
},
},
{
name: "Copy non-empty slice of AccessSpec with empty Methods",
input: []user.AccessSpec{
{
URL: "http://example.com",
Methods: []string{},
},
{
URL: "http://example.org",
Methods: []string{},
},
},
},
{
name: "Copy non-empty slice of AccessSpec with nil Methods",
input: []user.AccessSpec{
{
URL: "http://example.com",
Methods: nil,
},
{
URL: "http://example.org",
Methods: nil,
},
},
},
{
name: "Copy empty slice of AccessSpec",
input: []user.AccessSpec{},
},
{
name: "Copy nil slice of AccessSpec",
input: []user.AccessSpec(nil),
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
copied := copyAllowedURLs(tc.input)
assert.Equal(t, tc.input, copied)
})
}
}
12 changes: 4 additions & 8 deletions gateway/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (s *Test) TestPrepareApplyPolicies() (*BaseMiddleware, []testApplyPoliciesD
ID: "per_path_1",
AccessRights: map[string]user.AccessDefinition{"a": {
AllowedURLs: []user.AccessSpec{
{URL: "/user", Methods: []string{"GET", "POST"}},
{URL: "/user", Methods: []string{"GET"}},
},
}, "b": {
AllowedURLs: []user.AccessSpec{
Expand All @@ -316,7 +316,7 @@ func (s *Test) TestPrepareApplyPolicies() (*BaseMiddleware, []testApplyPoliciesD
ID: "per_path_2",
AccessRights: map[string]user.AccessDefinition{"a": {
AllowedURLs: []user.AccessSpec{
{URL: "/user", Methods: []string{"GET"}},
{URL: "/user", Methods: []string{"GET", "POST"}},
{URL: "/companies", Methods: []string{"GET", "POST"}},
},
}},
Expand Down Expand Up @@ -752,7 +752,7 @@ func (s *Test) TestPrepareApplyPolicies() (*BaseMiddleware, []testApplyPoliciesD
{
name: "Merge per path rules for the same API",
policies: []string{"per-path2", "per-path1"},
sessMatch: func(t *testing.T, sess *user.SessionState) {
sessMatch: func(t *testing.T, s *user.SessionState) {
want := map[string]user.AccessDefinition{
"a": {
AllowedURLs: []user.AccessSpec{
Expand All @@ -769,11 +769,7 @@ func (s *Test) TestPrepareApplyPolicies() (*BaseMiddleware, []testApplyPoliciesD
},
}

assert.Equal(t, user.AccessSpec{
URL: "/user", Methods: []string{"GET"},
}, s.Gw.getPolicy("per-path2").AccessRights["a"].AllowedURLs[0])

assert.Equal(t, want, sess.AccessRights)
assert.Equal(t, want, s.AccessRights)
},
},
{
Expand Down

0 comments on commit 9416376

Please sign in to comment.