Skip to content

Commit

Permalink
[FAB-5697] NodeSDK - make type not required
Browse files Browse the repository at this point in the history
The fabric-ca-client does not need to have the type
parameter as required. The ca parameter is known as
role on the API's. Will make optional and remove the
'client' as the default value when not set.

Change-Id: I7d932f190368eaccfbfb15b2d4657f10907b2187
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Sep 13, 2017
1 parent 33dd444 commit 5013dfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
24 changes: 16 additions & 8 deletions fabric-ca-client/lib/FabricCAClientImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var FabricCAServices = class extends BaseClient {
* @property {string} enrollmentID - ID which will be used for enrollment
* @property {string} enrollmentSecret - Optional enrollment secret to set for the registered user.
* If not provided, the server will generate one.
* @property {string} role - An arbitrary string representing a role value for the user
* @property {string} role - Optional arbitrary string representing a role value for the user
* @property {string} affiliation - Affiliation with which this user will be associated,
* like a company or an organization
* @property {number} maxEnrollments - The maximum number of times this user will be permitted to enroll
Expand Down Expand Up @@ -472,8 +472,10 @@ var FabricCAClient = class {
* Register a new user and return the enrollment secret
* @param {string} enrollmentID ID which will be used for enrollment
* @param {string} enrollmentSecret Optional enrollment secret to set for the registered user.
* If not provided, the server will generate one.
* @param {string} role Type of role for this user
* If not provided, the server will generate one.
* When not including, use a null for this parameter.
* @param {string} role Optional type of role for this user.
* When not including, use a null for this parameter.
* @param {string} affiliation Affiliation with which this user will be associated
* @param {number} maxEnrollments The maximum number of times the user is permitted to enroll
* @param {KeyValueAttribute[]} attrs Array of key/value attributes to assign to the user
Expand All @@ -486,20 +488,26 @@ var FabricCAClient = class {
var self = this;
var numArgs = arguments.length;
//all arguments are required
if (numArgs < 6) {
throw new Error('Missing required parameters. \'enrollmentID\', \'role\', \'affiliation\', \'attrs\', \
if (!enrollmentID || !affiliation || !maxEnrollments || !signingIdentity) {
throw new Error('Missing required parameters. \'enrollmentID\', \'affiliation\', \
and \'signingIdentity\' are all required.');
}

return new Promise(function (resolve, reject) {
var regRequest = {
'id': enrollmentID,
'type': role ? role : 'client',
'affiliation': affiliation,
'max_enrollments': maxEnrollments,
'attrs': attrs
'max_enrollments': maxEnrollments
};

if(role) {
regRequest.type = role;
}

if(attrs) {
regRequest.attrs = attrs;
}

if (typeof enrollmentSecret === 'string' && enrollmentSecret !== '') {
regRequest.secret = enrollmentSecret;
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fabric-ca-services-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ test('\n\n ** FabricCAServices: Test enroll() With Dynamic CSR **\n\n', function
// register a new user 'webAdmin' that can register other users of the role 'client'
return caService.register({enrollmentID: 'webAdmin', affiliation: 'org1.department2', attrs: [{name: 'hf.Registrar.Roles', value: 'client'}]}, member);
}).then((secret) => {
t.pass('Successfully registered "webAdmin" who can register other users of the "client" role');
t.pass('Successfully registered "webAdmin" who can register other users with no role');

return caService.enroll({enrollmentID: 'webAdmin', enrollmentSecret: secret});
},(err) => {
Expand Down
17 changes: 8 additions & 9 deletions test/unit/fabric-ca-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,14 @@ test('FabricCAServices: Test register() function', function(t) {
/Argument "registrar" must be an instance of the class "User", but is found to be missing a method "getSigningIdentity/,
'Must fail if registrar argument is not a User object'
);
return cop.register({enrollmentID: 'testUser'}, { getSigningIdentity: function() { return 'dummy'; } })
.then(() => {
t.fail('Should not have been able to resolve this request');
t.end();
}).catch((err) => {
t.pass('Successfully rejected register call due to invalid parameters');

t.end();
});
t.throws(
() => {
cop.register({enrollmentID: 'testUser3'}, { getSigningIdentity: function() { return 'dummy'; } });
},
/Missing required parameters/,
'Must fail if missing arguments'
);
t.end();
});


Expand Down

0 comments on commit 5013dfd

Please sign in to comment.