Exemple #1
0
// TestInvalidProposal checks that even if the policy allows the transaction and the sequence etc. is well formed,
// that if the handler does not accept the config, it is rejected
func TestInvalidProposal(t *testing.T) {
	handlers := defaultHandlers()
	cm, err := NewConfigurationManager(&cb.ConfigurationEnvelope{
		Items: []*cb.SignedConfigurationItem{makeSignedConfigurationItem("foo", "foo", 0, []byte("foo"), defaultChain)},
	}, &mockPolicyManager{&mockPolicy{}}, handlers)

	if err != nil {
		t.Fatalf("Error constructing configuration manager: %s", err)
	}

	cm.(*configurationManager).handlers[cb.ConfigurationItem_ConfigurationType(0)] = failHandler{}

	newConfig := &cb.ConfigurationEnvelope{
		Items: []*cb.SignedConfigurationItem{makeSignedConfigurationItem("foo", "foo", 1, []byte("foo"), defaultChain)},
	}

	err = cm.Validate(newConfig)
	if err == nil {
		t.Errorf("Should have errored validating config because the handler rejected it")
	}

	err = cm.Apply(newConfig)
	if err == nil {
		t.Errorf("Should have errored applying config because the handler rejected it")
	}
}
Exemple #2
0
func defaultHandlers() map[cb.ConfigurationItem_ConfigurationType]Handler {
	handlers := make(map[cb.ConfigurationItem_ConfigurationType]Handler)
	for ctype := range cb.ConfigurationItem_ConfigurationType_name {
		handlers[cb.ConfigurationItem_ConfigurationType(ctype)] = NewBytesHandler()
	}
	return handlers
}