Skip to content

Commit

Permalink
FAB-1245 Move COP client tests to headless-tests
Browse files Browse the repository at this point in the history
To ensure that the CI has some coverage of the
COP client code, the fabriccopservices-tests that
do not require target network are moved to
headless-tests.js.

Change-Id: Ifa23ba2eab2342ff26402418d64f5f14d0777b51
Signed-off-by: cdaughtr <cdaughtr@us.ibm.com>
  • Loading branch information
cdaughtr committed Dec 1, 2016
1 parent 1f08e84 commit 004ef32
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 182 deletions.
184 changes: 2 additions & 182 deletions test/unit/fabriccopservices-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,126 +32,8 @@ var FabricCOPServices = require('hfc-cop/lib/FabricCOPImpl');
var FabricCOPClient = FabricCOPServices.FabricCOPClient;

/**
* FabricCOPClient class tests
* FabricCOPClient enroll tests
*/

//test constructor
test('FabricCOPClient: Test constructor', function (t) {

var connectOpts = {};

t.throws(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Protocol must be set to 'http' or 'https'/,
'Throw error for missing protocol'
);

connectOpts.protocol = 'dummy';

t.throws(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Protocol must be set to 'http' or 'https'/,
'Throw error for invalid protocol'
);

connectOpts.protocol = 'http';
connectOpts.hostname = 'hostname';

t.doesNotThrow(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Protocol must be set to 'http' or 'https'/,
'HTTP is a valid protocol'
);

connectOpts.protocol = 'https';

t.doesNotThrow(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Protocol must be set to 'http' or 'https'/,
'HTTPS is a valid protocol'
);

delete connectOpts.hostname;

t.throws(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Hostname must be set/,
'Throw error for missing hostname'
);

connectOpts.hostname = 'hostname';

t.doesNotThrow(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Port must be an integer/,
'Should not throw error if port is not set'
);

connectOpts.port = '8888';

t.throws(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Port must be an integer/,
'Throw error for invalid port'
);

connectOpts.port = 8888;

t.doesNotThrow(
function () {
var client = new FabricCOPClient(connectOpts);
},
/Invalid connection options. Port must be an integer/,
'Integer is a valid type for port'
);

t.end();

});


//FabricCOPClient _pemToDER tests
var ecertPEM = fs.readFileSync(path.resolve(__dirname, '../fixtures/fabriccop/ecert.pem'));

test('FabricCOPClient: Test _pemToDer static method',function(t){

t.plan(2);

//call function with garbage
t.throws(
function(){
var hex = FabricCOPClient.pemToDER('garbage');
},
/Input parameter does not appear to be PEM-encoded./,
'Throw an error when input is not PEM-encoded'
);

try {
var hex = FabricCOPClient.pemToDER(ecertPEM.toString());
t.pass('Sucessfully converted ecert from PEM to DER');
} catch(err) {
t.fail('Failed to convert PEM to DER due to ' + err);
}

t.end();
});


//FabricCOPClient enroll tests
test('FabricCOPClient: Test enroll with missing parameters', function (t) {

var client = new FabricCOPClient({
Expand All @@ -169,7 +51,7 @@ test('FabricCOPClient: Test enroll with missing parameters', function (t) {
if (err.message.startsWith('Missing required parameters')) {
t.pass('Enrollment should fail when missing required parameters');
} else {
t.fail('Enrollment should have failed with \'Missing equired parameters\'');
t.fail('Enrollment should have failed with \'Missing required parameters\'');
}
});
});
Expand Down Expand Up @@ -201,73 +83,11 @@ test('FabricCOPClient: Test enroll', function (t) {
/**
* FabricCOPServices class tests
*/
test('FabricCOPServices: Test _parseURL() function', function (t) {

var goodHost = 'www.example.com';
var goodPort = 8888;
var goodURL = 'http://' + goodHost + ':' + goodPort;
var goodURLSecure = 'https://' + goodHost + ':' + goodPort;

var badHost = '';
var badURL = 'http://' + badHost + ':' + goodPort;
var badURL2 = 'httpD://' + goodHost + ':' + goodPort;
var badURL3 = 'httpsD://' + goodHost + ':' + goodPort;
var badURL4 = goodHost + ':' + goodPort;


t.plan(10);

//valid http endpoint
var endpointGood = FabricCOPServices._parseURL(goodURL);
t.equals(endpointGood.protocol, 'http', 'Check that protocol is set correctly to \'http\'');
t.equals(endpointGood.hostname, goodHost, 'Check that hostname is set correctly');
t.equals(endpointGood.port, goodPort, 'Check that port is set correctly');

//valid https endpoint
var endpointGoodSecure = FabricCOPServices._parseURL(goodURLSecure);
t.equals(endpointGoodSecure.protocol, 'https', 'Check that protocol is set correctly to \'https\'');
t.equals(endpointGoodSecure.hostname, goodHost, 'Check that hostname is set correctly');
t.equals(endpointGoodSecure.port, goodPort, 'Check that port is set correctly');

//check invalid endpoints
t.throws(
function () {
FabricCOPServices._parseURL(badURL);
},
/InvalidURL: missing hostname./,
'Throw error for missing hostname'
);

t.throws(
function () {
FabricCOPServices._parseURL(badURL2);
},
/InvalidURL: url must start with http or https./,
'Throw error for invalid protocol'
);

t.throws(
function () {
FabricCOPServices._parseURL(badURL3);
},
/InvalidURL: url must start with http or https./,
'Throw error for invalid protocol'
);

t.throws(
function () {
FabricCOPServices._parseURL(badURL3);
},
/InvalidURL: url must start with http or https./,
'Throw error for missing protocol'
);
});

//run the enroll test

test('FabricCOPServices: Test enroll()', function (t) {


//
// Create and configure the test chain
//
Expand Down
Loading

0 comments on commit 004ef32

Please sign in to comment.