@@ -70,17 +70,138 @@ func TestCAConfig(t *testing.T) {
7070 //Test Crypto config path
7171 crossCheckWithViperConfig (myViper .GetString ("client.cryptoconfig.path" ), configImpl .CryptoConfigPath (), "Incorrect crypto config path" , t )
7272
73+ //Testing CA Client File Location
74+ certfile , err := configImpl .CAClientCertFile ("peerorg1" )
75+
76+ if certfile == "" || err != nil {
77+ t .Fatal ("CA Cert file location read failed" )
78+ }
79+
80+ //Testing CA Key File Location
81+ keyFile , err := configImpl .CAClientKeyFile ("peerorg1" )
82+
83+ if keyFile == "" || err != nil {
84+ t .Fatal ("CA Key file location read failed" )
85+ }
86+
87+ //Testing CA Server Cert Files
88+ sCertFiles , err := configImpl .CAServerCertFiles ("peerorg1" )
89+
90+ if sCertFiles == nil || len (sCertFiles ) == 0 || err != nil {
91+ t .Fatal ("Getting CA server cert files failed" )
92+ }
93+
94+ //Testing MSPID
95+ mspID , err := configImpl .MspID ("peerorg1" )
96+ if mspID == "" || mspID != "Org1MSP" || err != nil {
97+ t .Fatal ("Get MSP ID failed" )
98+ }
99+
100+ //Testing CAConfig
101+ caConfig , err := configImpl .CAConfig ("peerorg1" )
102+ if caConfig == nil || err != nil {
103+ t .Fatal ("Get CA Config failed" )
104+ }
105+
106+ // Test CA KeyStore Path
107+ if vConfig .GetString ("client.keystore.path" ) != configImpl .CAKeyStorePath () {
108+ t .Fatalf ("Incorrect CA keystore path" )
109+ }
110+
111+ // Test KeyStore Path
112+ if vConfig .GetString ("client.keystore.path" )+ "/keystore" != configImpl .KeyStorePath () {
113+ t .Fatalf ("Incorrect keystore path " )
114+ }
115+
116+ }
117+
118+ func TestCAConfigFailsByNetworkConfig (t * testing.T ) {
119+
120+ //Tamper 'client.network' value and use a new config to avoid conflicting with other tests
121+ sampleConfig , err := InitConfig ("../../test/fixtures/config/config_test.yaml" )
122+ myViper := sampleConfig .FabricClientViper ()
123+ clientNetworks := myViper .Get ("client.network" )
124+ myViper .Set ("client.network" , "INVALID" )
125+ //...
126+
127+ _ , err = sampleConfig .NetworkConfig ()
128+ if err == nil {
129+ t .Fatal ("Network config load supposed to fail" )
130+ }
131+
132+ //Test CA client cert file failure scenario
133+ certfile , err := sampleConfig .CAClientCertFile ("peerorg1" )
134+ if certfile != "" || err == nil {
135+ t .Fatal ("CA Cert file location read supposed to fail" )
136+ }
137+
138+ //Test CA client cert file failure scenario
139+ keyFile , err := sampleConfig .CAClientKeyFile ("peerorg1" )
140+ if keyFile != "" || err == nil {
141+ t .Fatal ("CA Key file location read supposed to fail" )
142+ }
143+
144+ //Testing CA Server Cert Files failure scenario
145+ sCertFiles , err := sampleConfig .CAServerCertFiles ("peerorg1" )
146+ if len (sCertFiles ) > 0 || err == nil {
147+ t .Fatal ("Getting CA server cert files supposed to fail" )
148+ }
149+
150+ //Testing MSPID failure scenario
151+ mspID , err := sampleConfig .MspID ("peerorg1" )
152+ if mspID != "" || err == nil {
153+ t .Fatal ("Get MSP ID supposed to fail" )
154+ }
155+
156+ //Testing CAConfig failure scenario
157+ caConfig , err := sampleConfig .CAConfig ("peerorg1" )
158+ if caConfig != nil || err == nil {
159+ t .Fatal ("Get CA Config supposed to fail" )
160+ }
161+
162+ //Testing RandomOrdererConfig failure scenario
163+ oConfig , err := sampleConfig .RandomOrdererConfig ()
164+ if oConfig != nil || err == nil {
165+ t .Fatal ("Testing get RandomOrdererConfig supposed to fail" )
166+ }
167+
168+ //Testing RandomOrdererConfig failure scenario
169+ oConfig , err = sampleConfig .OrdererConfig ("peerorg1" )
170+ if oConfig != nil || err == nil {
171+ t .Fatal ("Testing get OrdererConfig supposed to fail" )
172+ }
173+
174+ //Testing PeersConfig failure scenario
175+ pConfig , err := sampleConfig .PeersConfig ("peerorg1" )
176+ if pConfig != nil || err == nil {
177+ t .Fatal ("Testing PeersConfig supposed to fail" )
178+ }
179+
180+ //Set it back to valid one, otherwise other tests may fail
181+ myViper .Set ("client.network" , clientNetworks )
73182}
74183
75184func TestTLSACAConfig (t * testing.T ) {
185+ //Test TLSCA Cert Pool (Positive test case)
186+ certFile , _ := configImpl .CAClientCertFile ("peerorg1" )
187+ _ , err := configImpl .TLSCACertPool (certFile )
188+ if err != nil {
189+ t .Fatalf ("TLS CA cert pool fetch failed, reason: %v" , err )
190+ }
76191
77- //Test TLSCA Cert Pool (Negative test case
78- _ , err : = configImpl .TLSCACertPool ("some random invalid path" )
192+ //Test TLSCA Cert Pool (Negative test case)
193+ _ , err = configImpl .TLSCACertPool ("some random invalid path" )
79194 if err == nil {
80195 t .Fatalf ("TLS CA cert pool was supposed to fail" )
81196 }
82197
83- //Test TLSCA Cert Pool from roots(Negative test case
198+ keyFile , _ := configImpl .CAClientKeyFile ("peerorg1" )
199+ _ , err = configImpl .TLSCACertPool (keyFile )
200+ if err == nil {
201+ t .Fatalf ("TLS CA cert pool was supposed to fail when provided with wrong cert file" )
202+ }
203+
204+ //Test TLSCA Cert Pool from roots(Negative test case)
84205 samplebytes := [][]byte {
85206 []byte (validRootCA ),
86207 }
@@ -89,7 +210,7 @@ func TestTLSACAConfig(t *testing.T) {
89210 t .Fatalf ("TLS CA cert pool fetch failed, reason %v" , err )
90211 }
91212
92- //Test TLSCA Cert Pool from roots(Negative test case
213+ //Test TLSCA Cert Pool from roots(Negative test case)
93214 samplebytes = [][]byte {
94215 []byte ("sample invalid string" ),
95216 }
@@ -100,6 +221,20 @@ func TestTLSACAConfig(t *testing.T) {
100221
101222}
102223
224+ func TestOrdererConfig (t * testing.T ) {
225+ oConfig , err := configImpl .RandomOrdererConfig ()
226+
227+ if oConfig == nil || err != nil {
228+ t .Fatal ("Testing get RandomOrdererConfig failed" )
229+ }
230+
231+ oConfig , err = configImpl .OrdererConfig ("peerorg1" )
232+
233+ if oConfig == nil || err != nil {
234+ t .Fatal ("Testing get OrdererConfig failed" )
235+ }
236+ }
237+
103238func TestCSPConfig (t * testing.T ) {
104239 cspconfig := configImpl .CSPConfig ()
105240
0 commit comments