Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty policies when traversing the policy tree in discovery policy analysis (backport #3334) #3335

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/policies/inquire/inquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func principalsOfTree(tree *graph.Tree, principals policies.PrincipalSet) polici
continue
}
pol := v.Data.(*common.SignaturePolicy)
if pol == nil {
logger.Warnf("Malformed policy, it is either not composed of signature policy envelopes or is missing some")
return nil
}
switch principalIndex := pol.Type.(type) {
case *common.SignaturePolicy_SignedBy:
if len(principals) <= int(principalIndex.SignedBy) {
Expand Down
27 changes: 27 additions & 0 deletions common/policies/inquire/inquire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/common/policydsl"
"github.com/hyperledger/fabric/protoutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

type testCase struct {
Expand Down Expand Up @@ -107,6 +110,30 @@ func TestSatisfiedBy(t *testing.T) {
}
}

func TestSatisfiedByEmptyPolicy(t *testing.T) {
backupLogger := logger
defer func() {
logger = backupLogger
}()

logged := make(map[string]struct{})

logger = logger.WithOptions(zap.Hooks(func(entry zapcore.Entry) error {
logged[entry.Message] = struct{}{}
return nil
}))

ip := NewInquireableSignaturePolicy(&common.SignaturePolicyEnvelope{
Identities: []*msp.MSPPrincipal{{}},
})

require.Nil(t, ip.SatisfiedBy())

require.Equal(t, map[string]struct{}{
"Malformed policy, it is either not composed of signature policy envelopes or is missing some": {},
}, logged)
}

func TestSatisfiedByTooManyCombinations(t *testing.T) {
// We have 26 choose 15 members which is 7,726,160
// and we ensure we don't return so many combinations,
Expand Down