forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ouconfig_test.go
83 lines (65 loc) · 2.49 KB
/
ouconfig_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
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 msp
import (
"path/filepath"
"testing"
"github.com/hyperledger/fabric/bccsp/sw"
"github.com/stretchr/testify/assert"
)
func TestBadConfigOU(t *testing.T) {
// testdata/badconfigou:
// the configuration is such that only identities
// with OU=COP2 and signed by the root ca should be validated
thisMSP := getLocalMSP(t, "testdata/badconfigou")
id, err := thisMSP.GetDefaultSigningIdentity()
assert.NoError(t, err)
// the default signing identity OU is COP but the msp is configured
// to validate only identities whose OU is COP2
err = id.Validate()
assert.Error(t, err)
}
func TestBadConfigOUCert(t *testing.T) {
// testdata/badconfigoucert:
// the configuration of the OU identifier points to a
// certificate that is neither a CA nor an intermediate CA for the msp.
conf, err := GetLocalMspConfig("testdata/badconfigoucert", nil, "SampleOrg")
assert.NoError(t, err)
thisMSP, err := newBccspMsp(MSPv1_0)
assert.NoError(t, err)
err = thisMSP.Setup(conf)
assert.Error(t, err)
assert.Contains(t, err.Error(), "Failed adding OU. Certificate [")
assert.Contains(t, err.Error(), "] not in root or intermediate certs.")
}
func TestValidateIntermediateConfigOU(t *testing.T) {
// testdata/external:
// the configuration is such that only identities with
// OU=Hyperledger Testing and signed by the intermediate ca should be validated
thisMSP := getLocalMSP(t, "testdata/external")
id, err := thisMSP.GetDefaultSigningIdentity()
assert.NoError(t, err)
err = id.Validate()
assert.NoError(t, err)
conf, err := GetLocalMspConfig("testdata/external", nil, "SampleOrg")
assert.NoError(t, err)
thisMSP, err = newBccspMsp(MSPv1_0)
assert.NoError(t, err)
ks, err := sw.NewFileBasedKeyStore(nil, filepath.Join("testdata/external", "keystore"), true)
assert.NoError(t, err)
csp, err := sw.NewWithParams(256, "SHA2", ks)
assert.NoError(t, err)
thisMSP.(*bccspmsp).bccsp = csp
err = thisMSP.Setup(conf)
assert.NoError(t, err)
}