@@ -12,13 +12,22 @@ const expect = chai.expect;
1212const rewire = require ( 'rewire' ) ;
1313const fabprotos = require ( '../../bundle' ) ;
1414const path = require ( 'path' ) ;
15+ const fs = require ( 'fs' ) ;
1516
1617const Logger = require ( '../../lib/logger' ) ;
1718
1819const Stub = require ( '../../lib/stub' ) ;
1920const chaincodePath = '../../lib/chaincode.js' ;
2021const StartCommand = require ( '../../lib/cmds/startCommand.js' ) ;
2122
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+
2231describe ( 'Chaincode' , ( ) => {
2332 let Chaincode ;
2433 let sandbox ;
@@ -159,15 +168,13 @@ describe('Chaincode', () => {
159168 } ) ;
160169
161170 describe ( 'TLS handling' , ( ) => {
162- const testfile = path . join ( __dirname , '../../../../package.json' ) ;
163-
164171 const myYargs = { 'argv' : { '$0' : 'fabric-chaincode-node' , 'peer.address' : 'localhost:7051' , 'chaincode-id-name' : 'mycc' } } ;
165172
166173 let getArgsStub ;
167174
168175 before ( ( ) => {
169176 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 ;
171178 } ) ;
172179
173180 beforeEach ( ( ) => {
@@ -198,7 +205,7 @@ describe('Chaincode', () => {
198205 } ) ;
199206
200207 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 ;
202209 expect ( ( ) => {
203210 Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
204211 } ) . 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', () => {
209216 const handlerClass = Chaincode . __get__ ( 'Handler' ) ;
210217 const chat = sandbox . stub ( handlerClass . prototype , 'chat' ) ;
211218
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 ;
214221
215222 Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
216223
@@ -243,22 +250,17 @@ describe('Chaincode', () => {
243250 const handlerClass = Chaincode . __get__ ( 'Handler' ) ;
244251 Chaincode . __set__ ( 'Handler' , MockHandler ) ;
245252
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 ;
248255
249256 Chaincode . start ( { Init : function ( ) { } , Invoke : function ( ) { } } ) ;
250257
251258 sinon . assert . calledOnce ( getArgsStub ) ;
252259 sinon . assert . calledWith ( getArgsStub , myYargs ) ;
253260
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 ) ;
262264
263265 Chaincode . __set__ ( 'Handler' , handlerClass ) ;
264266 } ) ;
0 commit comments