Skip to content

Commit

Permalink
[FAB-5026] NodeSDK - verify install error
Browse files Browse the repository at this point in the history
Add new test case to verify that we get an
error when installing chain code and not
using an admin user to sign the request.

Change-Id: I8b66b54e2233fb6748fb55c358176c011fda5143
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob authored and jimthematrix committed Jul 17, 2017
1 parent 882e289 commit bf2f388
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
1 change: 1 addition & 0 deletions test/integration/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
require('./e2e/create-channel.js');
require('./e2e/join-channel.js');
require('./e2e/install-chaincode-fail.js');
require('./e2e/install-chaincode.js');
require('./e2e/instantiate-chaincode.js');
require('./e2e/invoke-transaction.js');
Expand Down
12 changes: 7 additions & 5 deletions test/integration/e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ function init() {
}
}

function installChaincode(org, chaincode_path, version, t) {
function installChaincode(org, chaincode_path, version, t, get_admin) {
init();

Client.setConfigSetting('request-timeout', 60000);
var channel_name = Client.getConfigSetting('E2E_CONFIGTX_CHANNEL_NAME', testUtil.END2END.channel);

Expand Down Expand Up @@ -88,8 +87,11 @@ function installChaincode(org, chaincode_path, version, t) {
}
);

targets.push(peer);
channel.addPeer(peer);
targets.push(peer); // a peer can be the target this way
channel.addPeer(peer); // or a peer can be the target this way
// you do not have to do both, just one, when there are
// 'targets' in the request, those will be used and not
// the peers added to the channel
}
}
}
Expand All @@ -100,7 +102,7 @@ function installChaincode(org, chaincode_path, version, t) {
client.setStateStore(store);

// get the peer org's admin required to send install chaincode requests
return testUtil.getSubmitter(client, t, true /* get peer org admin */, org);
return testUtil.getSubmitter(client, t, get_admin /* get peer org admin */, org);
}).then((admin) => {
t.pass('Successfully enrolled user \'admin\'');
the_user = admin;
Expand Down
53 changes: 53 additions & 0 deletions test/integration/e2e/install-chaincode-fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2017 IBM 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.
*/

// This is an end-to-end test that focuses on exercising all parts of the fabric APIs
// in a happy-path scenario
'use strict';

var utils = require('fabric-client/lib/utils.js');
var logger = utils.getLogger('E2E install-chaincode-fail');

var tape = require('tape');
var _test = require('tape-promise');
var test = _test(tape);

var e2eUtils = require('./e2eUtils.js');
var testUtil = require('../../unit/util.js');

test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', t, false)
.then(() => {
t.fail('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t, false);
}, (err) => {
t.pass('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org1". ');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t, false);
}).then(() => {
t.fail('Successfully installed chaincode in peers of organization "org2"');
t.end();
}, (err) => {
t.pass('Failed to install chaincode in peers of organization "org2". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org2". ');
t.end();
}).catch((err) => {
t.fail('Test failed due to unexpected reasons. ' + err.stack ? err.stack : err);
t.end();
});
});
6 changes: 3 additions & 3 deletions test/integration/e2e/install-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ var testUtil = require('../../unit/util.js');
test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', t)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org1". ');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', t, true);
}).then(() => {
t.pass('Successfully installed chaincode in peers of organization "org2"');
t.end();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/e2e/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ var testUtil = require('../../unit/util.js');
test('\n\n***** U P G R A D E flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', t)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', t);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
t.end();
Expand Down
6 changes: 3 additions & 3 deletions test/integration/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => {

// limit the send message size to 1M
utils.setConfigSetting('grpc-max-send-message-length', 1024 * 1024);
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', t)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', t, true)
.then(() => {
t.fail('Should have failed because the file size is too big for grpc send messages');
t.end();
Expand All @@ -83,7 +83,7 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => {
// now dial the send limit up
utils.setConfigSetting('grpc-max-send-message-length', 1024 * 1024 * 2);

return e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', t);
return e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', t, true);
}).then(() => {
t.pass('Successfully tested setting grpc send limit');

Expand All @@ -93,7 +93,7 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => {
path: testUtil.storePathForOrg(orgName)
});
}, (err) => {
t.fail('Failed to effectively use config setting to control grpc send message limit');
t.fail('Failed to effectively use config setting to control grpc send message limit with error ::'+err);
t.end();
}).then((store) => {

Expand Down

0 comments on commit bf2f388

Please sign in to comment.