-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-2322] Allow mod_policy to be relative
https://jira.hyperledger.org/browse/FAB-2322 With the notion of hierarchical policies, the configuration mod_policy needs to be able to refer to policies in the current group (relatively) or policies relative to the channel root configuration (absolute). This CR modifies the policy lookup to ask the relative policy manager unless the policy begins with a "/" in which case the policy is retrieved from the root policy manager. Change-Id: Id14e327a5c37c4c1848521abd691aa857a12039d Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Feb 17, 2017
1 parent
a971b0f
commit 22d2d5c
Showing
3 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package configtx | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" | ||
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPolicyForItem(t *testing.T) { | ||
// Policies are set to different error values to differentiate them in equal assertion | ||
rootPolicy := &mockpolicies.Policy{Err: fmt.Errorf("rootPolicy")} | ||
fooPolicy := &mockpolicies.Policy{Err: fmt.Errorf("fooPolicy")} | ||
|
||
cm := &configManager{ | ||
Resources: &mockconfigtx.Resources{ | ||
PolicyManagerVal: &mockpolicies.Manager{ | ||
BasePathVal: "root", | ||
Policy: rootPolicy, | ||
SubManagersMap: map[string]*mockpolicies.Manager{ | ||
"foo": &mockpolicies.Manager{ | ||
Policy: fooPolicy, | ||
BasePathVal: "foo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
policy, ok := cm.policyForItem(comparable{ | ||
path: []string{"root"}, | ||
ConfigValue: &cb.ConfigValue{ | ||
ModPolicy: "rootPolicy", | ||
}, | ||
}) | ||
assert.True(t, ok) | ||
assert.Equal(t, policy, rootPolicy, "Should have found relative policy off the root manager") | ||
|
||
policy, ok = cm.policyForItem(comparable{ | ||
path: []string{"root", "wrong"}, | ||
ConfigValue: &cb.ConfigValue{ | ||
ModPolicy: "rootPolicy", | ||
}, | ||
}) | ||
assert.False(t, ok, "Should not have found rootPolicy off a non-existant manager") | ||
|
||
policy, ok = cm.policyForItem(comparable{ | ||
path: []string{"root", "foo"}, | ||
ConfigValue: &cb.ConfigValue{ | ||
ModPolicy: "foo", | ||
}, | ||
}) | ||
assert.True(t, ok) | ||
assert.Equal(t, policy, fooPolicy, "Should not have found relative foo policy the foo manager") | ||
|
||
policy, ok = cm.policyForItem(comparable{ | ||
path: []string{"root", "foo"}, | ||
ConfigValue: &cb.ConfigValue{ | ||
ModPolicy: "/rootPolicy", | ||
}, | ||
}) | ||
assert.True(t, ok) | ||
assert.Equal(t, policy, rootPolicy, "Should not have found absolute root policy from the foo path position") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters