-
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-5944] Restore disabled config update checks
In order to refactor the channel config to be immutable, checks which depended upon the previous state had to be removed (in particular, checks for the consensus type changing and for the org's MSPID changing were temporarily removed). This CR adds those checks back in a step which allows the previous config to validate the new one via 'ValidateNew'. Change-Id: Ic6c51f4b09f5aaaa8d176d850728287a1381b5e4 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Aug 30, 2017
1 parent
0cd1626
commit 10d340c
Showing
11 changed files
with
308 additions
and
17 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
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,202 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package channelconfig | ||
|
||
import ( | ||
"testing" | ||
|
||
ab "github.com/hyperledger/fabric/protos/orderer" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidateNew(t *testing.T) { | ||
t.Run("DisappearingOrdererConfig", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
ordererConfig: &OrdererConfig{}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Current config has orderer section, but new config does not", err.Error()) | ||
}) | ||
|
||
t.Run("DisappearingApplicationConfig", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
appConfig: &ApplicationConfig{}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Current config has consortiums section, but new config does not", err.Error()) | ||
}) | ||
|
||
t.Run("DisappearingConsortiumsConfig", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
consortiumsConfig: &ConsortiumsConfig{}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Current config has consortiums section, but new config does not", err.Error()) | ||
}) | ||
|
||
t.Run("ConsensusTypeChange", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
ordererConfig: &OrdererConfig{ | ||
protos: &OrdererProtos{ | ||
ConsensusType: &ab.ConsensusType{ | ||
Type: "type1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
ordererConfig: &OrdererConfig{ | ||
protos: &OrdererProtos{ | ||
ConsensusType: &ab.ConsensusType{ | ||
Type: "type2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Attempted to change consensus type from", err.Error()) | ||
}) | ||
|
||
t.Run("OrdererOrgMSPIDChange", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
ordererConfig: &OrdererConfig{ | ||
protos: &OrdererProtos{ | ||
ConsensusType: &ab.ConsensusType{ | ||
Type: "type1", | ||
}, | ||
}, | ||
orgs: map[string]Org{ | ||
"org1": &OrganizationConfig{mspID: "org1msp"}, | ||
"org2": &OrganizationConfig{mspID: "org2msp"}, | ||
"org3": &OrganizationConfig{mspID: "org3msp"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
ordererConfig: &OrdererConfig{ | ||
protos: &OrdererProtos{ | ||
ConsensusType: &ab.ConsensusType{ | ||
Type: "type1", | ||
}, | ||
}, | ||
orgs: map[string]Org{ | ||
"org1": &OrganizationConfig{mspID: "org1msp"}, | ||
"org3": &OrganizationConfig{mspID: "org2msp"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Orderer org org3 attempted to change MSP ID from", err.Error()) | ||
}) | ||
|
||
t.Run("ApplicationOrgMSPIDChange", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
appConfig: &ApplicationConfig{ | ||
applicationOrgs: map[string]ApplicationOrg{ | ||
"org1": &ApplicationOrgConfig{OrganizationConfig: &OrganizationConfig{mspID: "org1msp"}}, | ||
"org2": &ApplicationOrgConfig{OrganizationConfig: &OrganizationConfig{mspID: "org2msp"}}, | ||
"org3": &ApplicationOrgConfig{OrganizationConfig: &OrganizationConfig{mspID: "org3msp"}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
appConfig: &ApplicationConfig{ | ||
applicationOrgs: map[string]ApplicationOrg{ | ||
"org1": &ApplicationOrgConfig{OrganizationConfig: &OrganizationConfig{mspID: "org1msp"}}, | ||
"org3": &ApplicationOrgConfig{OrganizationConfig: &OrganizationConfig{mspID: "org2msp"}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Application org org3 attempted to change MSP ID from", err.Error()) | ||
}) | ||
|
||
t.Run("ConsortiumOrgMSPIDChange", func(t *testing.T) { | ||
cb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
consortiumsConfig: &ConsortiumsConfig{ | ||
consortiums: map[string]Consortium{ | ||
"consortium1": &ConsortiumConfig{ | ||
orgs: map[string]Org{ | ||
"org1": &OrganizationConfig{mspID: "org1msp"}, | ||
"org2": &OrganizationConfig{mspID: "org2msp"}, | ||
"org3": &OrganizationConfig{mspID: "org3msp"}, | ||
}, | ||
}, | ||
"consortium2": &ConsortiumConfig{}, | ||
"consortium3": &ConsortiumConfig{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
nb := &Bundle{ | ||
channelConfig: &ChannelConfig{ | ||
consortiumsConfig: &ConsortiumsConfig{ | ||
consortiums: map[string]Consortium{ | ||
"consortium1": &ConsortiumConfig{ | ||
orgs: map[string]Org{ | ||
"org1": &OrganizationConfig{mspID: "org1msp"}, | ||
"org3": &OrganizationConfig{mspID: "org2msp"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := cb.ValidateNew(nb) | ||
assert.Error(t, err) | ||
assert.Regexp(t, "Consortium consortium1 org org3 attempted to change MSP ID from", err.Error()) | ||
}) | ||
} |
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
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
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
Oops, something went wrong.