Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit fd4ecec

Browse files
author
Simon Stone
authored
Merge branch 'master' into master
2 parents 9442d0b + 685174d commit fd4ecec

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

packages/composer-connector-hlf/.istanbul.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ instrumentation:
44
- scripts/**
55
check:
66
global:
7-
statements: 95
8-
branches: 95
9-
lines: 95
10-
functions: 90
7+
statements: 100
8+
branches: 100
9+
lines: 100
10+
functions: 100

packages/composer-connector-hlf/lib/hfcconnectionmanager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class HFCConnectionManager extends ConnectionManager {
118118
// Check to see that the certificate is not just whitespace.
119119
let certificate = connectOptions.certificate.trim();
120120
if (certificate) {
121+
// Certificates *must* end with a trailing newline.
122+
certificate += '\n';
121123
grpcOptions.pem = certificate;
122124
}
123125
}

packages/composer-connector-hlf/test/hfcconnectionmanager.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ describe('HFCConnectionManager', () => {
343343

344344
// Check for the correct interactions with hfc.
345345
sinon.assert.calledOnce(mockChain.setMemberServicesUrl);
346-
sinon.assert.calledWith(mockChain.setMemberServicesUrl, connectOptions.membershipServicesURL, { pem: '=== such certificate ===' });
346+
sinon.assert.calledWith(mockChain.setMemberServicesUrl, connectOptions.membershipServicesURL, { pem: '=== such certificate ===\n' });
347347
sinon.assert.calledOnce(mockChain.addPeer);
348-
sinon.assert.calledWith(mockChain.addPeer, connectOptions.peerURL, { pem: '=== such certificate ===' });
348+
sinon.assert.calledWith(mockChain.addPeer, connectOptions.peerURL, { pem: '=== such certificate ===\n' });
349349
sinon.assert.calledOnce(mockChain.eventHubConnect);
350-
sinon.assert.calledWith(mockChain.eventHubConnect, 'grpc://vp1', { pem: '=== such certificate ===' });
350+
sinon.assert.calledWith(mockChain.eventHubConnect, 'grpc://vp1', { pem: '=== such certificate ===\n' });
351351
return true;
352352

353353
});
@@ -406,6 +406,24 @@ describe('HFCConnectionManager', () => {
406406
};
407407
});
408408

409+
it('should throw for a connection not created by the connection manager', () => {
410+
let mockConnection = sinon.createStubInstance(HFCConnection);
411+
mockConnection.getIdentifier.returns('not a real identifier');
412+
(() => {
413+
connectionManager.onDisconnect(mockConnection);
414+
}).should.throw(/not created by connection manager/);
415+
});
416+
417+
it('should throw for a connection already closed by the connection manager', () => {
418+
let mockConnection = sinon.createStubInstance(HFCConnection);
419+
let mockChain = sinon.createStubInstance(hfcChain);
420+
mockConnection.getIdentifier.returns('not a real identifier');
421+
connectionManager.chainPool['not a real identifier'] = { count: 0, chain: mockChain };
422+
(() => {
423+
connectionManager.onDisconnect(mockConnection);
424+
}).should.throw(/already closed/);
425+
});
426+
409427
it('should call onDisconnect when client connection is disconnected', function() {
410428

411429
// Set up the hfc mock.

0 commit comments

Comments
 (0)