Skip to content

Commit

Permalink
Fixes token update when non-partitioned policies change access rights…
Browse files Browse the repository at this point in the history
…, related to TykTechnologies#1559

Adds test to cover TykTechnologies#1501 changes
  • Loading branch information
matiasinsaurralde authored and buger committed Mar 23, 2018
1 parent 329c7fb commit ec62eba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (t BaseMiddleware) ApplyPolicies(key string, session *user.SessionState) er
}

// ACL
session.AccessRights = policy.AccessRights
rights = policy.AccessRights
session.HMACEnabled = policy.HMACEnabled
}

Expand Down
22 changes: 22 additions & 0 deletions policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func TestApplyPolicies(t *testing.T) {
Partitions: user.PolicyPartitions{Acl: true},
AccessRights: map[string]user.AccessDefinition{"b": {}},
},
"acl3": {
AccessRights: map[string]user.AccessDefinition{"c": {}},
},
}
policiesMu.RUnlock()
bmid := &BaseMiddleware{Spec: &APISpec{
Expand Down Expand Up @@ -186,6 +189,25 @@ func TestApplyPolicies(t *testing.T) {
}
},
},
{
"RightsUpdate", []string{"acl3"},
"", func(t *testing.T, s *user.SessionState) {
newPolicy := user.Policy{
AccessRights: map[string]user.AccessDefinition{"a": {}, "b": {}, "c": {}},
}
policiesMu.Lock()
policiesByID["acl3"] = newPolicy
policiesMu.Unlock()
err := bmid.ApplyPolicies("", s)
if err != nil {
t.Fatalf("couldn't apply policy: %s", err.Error())
}
want := newPolicy.AccessRights
if !reflect.DeepEqual(want, s.AccessRights) {
t.Fatalf("want %v got %v", want, s.AccessRights)
}
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit ec62eba

Please sign in to comment.