@@ -12,13 +12,22 @@ const expect = chai.expect;
12
12
const rewire = require ( 'rewire' ) ;
13
13
const fabprotos = require ( '../../bundle' ) ;
14
14
const path = require ( 'path' ) ;
15
+ const fs = require ( 'fs' ) ;
15
16
16
17
const Logger = require ( '../../lib/logger' ) ;
17
18
18
19
const Stub = require ( '../../lib/stub' ) ;
19
20
const chaincodePath = '../../lib/chaincode.js' ;
20
21
const StartCommand = require ( '../../lib/cmds/startCommand.js' ) ;
21
22
23
+ const caPath = path . join ( __dirname , 'test-ca.pem' ) ;
24
+ const certPath = path . join ( __dirname , 'test-cert.pem' ) ;
25
+ const keyPath = path . join ( __dirname , 'test-key.pem' ) ;
26
+
27
+ const ca = fs . readFileSync ( caPath , 'utf8' ) ;
28
+ const key = fs . readFileSync ( keyPath , 'utf8' ) ;
29
+ const cert = fs . readFileSync ( certPath , 'utf8' ) ;
30
+
22
31
describe ( 'Chaincode' , ( ) => {
23
32
let Chaincode ;
24
33
let sandbox ;
@@ -159,15 +168,13 @@ describe('Chaincode', () => {
159
168
} ) ;
160
169
161
170
describe ( 'TLS handling' , ( ) => {
162
- const testfile = path . join ( __dirname , '../../../../package.json' ) ;
163
-
164
171
const myYargs = { 'argv' : { '$0' : 'fabric-chaincode-node' , 'peer.address' : 'localhost:7051' , 'chaincode-id-name' : 'mycc' } } ;
165
172
166
173
let getArgsStub ;
167
174
168
175
before ( ( ) => {
169
176
process . env . CORE_PEER_TLS_ENABLED = true ;
170
- process . env . CORE_PEER_TLS_ROOTCERT_FILE = testfile ;
177
+ process . env . CORE_PEER_TLS_ROOTCERT_FILE = caPath ;
171
178
} ) ;
172
179
173
180
beforeEach ( ( ) => {
@@ -198,7 +205,7 @@ describe('Chaincode', () => {
198
205
} ) ;
199
206
200
207
it ( 'should throw an error when CORE_TLS_CLIENT_KEY_PATH env var set but CORE_TLS_CLIENT_CERT_PATH env var not set' , ( ) => {
201
- process . env . CORE_TLS_CLIENT_KEY_PATH = testfile ;
208
+ process . env . CORE_TLS_CLIENT_KEY_PATH = keyPath ;
202
209
expect ( ( ) => {
203
210
Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
204
211
} ) . to . throw ( / T h e c l i e n t k e y a n d c e r t a r e n e e d e d w h e n T L S i s e n a b l e d , b u t e n v i r o n m e n t v a r i a b l e s s p e c i f y i n g t h e p a t h s t o t h e s e f i l e s a r e m i s s i n g / ) ;
@@ -209,8 +216,8 @@ describe('Chaincode', () => {
209
216
const handlerClass = Chaincode . __get__ ( 'Handler' ) ;
210
217
const chat = sandbox . stub ( handlerClass . prototype , 'chat' ) ;
211
218
212
- process . env . CORE_TLS_CLIENT_KEY_PATH = testfile ;
213
- process . env . CORE_TLS_CLIENT_CERT_PATH = testfile ;
219
+ process . env . CORE_TLS_CLIENT_KEY_PATH = keyPath ;
220
+ process . env . CORE_TLS_CLIENT_CERT_PATH = certPath ;
214
221
215
222
Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
216
223
@@ -243,22 +250,17 @@ describe('Chaincode', () => {
243
250
const handlerClass = Chaincode . __get__ ( 'Handler' ) ;
244
251
Chaincode . __set__ ( 'Handler' , MockHandler ) ;
245
252
246
- process . env . CORE_TLS_CLIENT_KEY_PATH = testfile ;
247
- process . env . CORE_TLS_CLIENT_CERT_PATH = testfile ;
253
+ process . env . CORE_TLS_CLIENT_KEY_PATH = keyPath ;
254
+ process . env . CORE_TLS_CLIENT_CERT_PATH = certPath ;
248
255
249
256
Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
250
257
251
258
sinon . assert . calledOnce ( getArgsStub ) ;
252
259
sinon . assert . calledWith ( getArgsStub , myYargs ) ;
253
260
254
- const attributes = [ 'pem' , 'cert' , 'key' ] ;
255
-
256
- attributes . forEach ( ( attr ) => {
257
- expect ( typeof testOpts [ attr ] ) . to . deep . equal ( 'string' ) ;
258
-
259
- const json = JSON . parse ( testOpts [ attr ] ) ;
260
- expect ( json . name ) . to . deep . equal ( 'fabric-chaincode-node' ) ;
261
- } ) ;
261
+ testOpts . pem . should . equal ( ca ) ;
262
+ testOpts . cert . should . equal ( cert ) ;
263
+ testOpts . key . should . equal ( key ) ;
262
264
263
265
Chaincode . __set__ ( 'Handler' , handlerClass ) ;
264
266
} ) ;
0 commit comments