Skip to content

Commit

Permalink
FAB-6628 NodeSDK - identitiesy REST change
Browse files Browse the repository at this point in the history
The input body layout changed for the identities create
and update calls.

Change-Id: If2c533275f8316a5b7f21ca0084577aaee05e71d
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Jan 25, 2018
1 parent f7da339 commit 31fe394
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
2 changes: 0 additions & 2 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ if (!/-snapshot/.test(release)) {

// these environment variables would be read at test/fixtures/docker-compose.yaml
process.env.DOCKER_IMG_TAG = dockerImageTag;
process.env.V11_IDENTITIES_ALLOWREMOVE = '--cfg.identities.allowremove';
process.env.V11_AFFILIATIONS_ALLOWREMOVE = '--cfg.affiliations.allowremove';

gulp.task('pre-test', function() {
return gulp.src([
Expand Down
35 changes: 27 additions & 8 deletions fabric-ca-client/lib/IdentityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ class IdentityService {

return new Promise(function (resolve, reject) {
const request = {
info: {
id: req.enrollmentID,
type: req.type || null,
affiliation: req.affiliation,
attrs: req.attrs || [],
max_enrollments: maxEnrollments,
},
id: req.enrollmentID,
type: req.type || null,
affiliation: req.affiliation,
attrs: req.attrs || [],
max_enrollments: maxEnrollments,
secret: req.enrollmentSecret || null,
caname: req.caname || null,
};
Expand Down Expand Up @@ -213,7 +211,28 @@ class IdentityService {
throw new Error('Can not get signingIdentity from registrar');
}
const url = 'identities/' + enrollmentID;
return this.client.put(url, req, signingIdentity);

let request = {};
if(req.type) {
request.type = req.type;
}
if(req.affiliation) {
request.affiliation = req.affiliation;
}
if (Number.isInteger(req.maxEnrollments)) {
request.maxEnrollments = req.maxEnrollments;
}
if(req.attrs) {
request.attrs = req.attrs;
}
if(req.enrollmentSecret) {
request.secret = req.enrollmentSecret;
}
if(req.caname) {
request.caname = req.caname;
}

return this.client.put(url, request, signingIdentity);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
- FABRIC_CA_SERVER_TLS_KEYFILE=/etc/hyperledger/fabric-ca-server-config/a22daf356b2aab5792ea53e35f66fccef1d7f1aa2b3a2b92dbfbf96a448ea26a_sk
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start ${V11_IDENTITIES_ALLOWREMOVE} ${V11_AFFILIATIONS_ALLOWREMOVE} -b admin:adminpw -d'
command: sh -c 'fabric-ca-server start --cfg.identities.allowremove --cfg.affiliations.allowremove -b admin:adminpw -d'
volumes:
- ./channel/crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca_peerOrg1
Expand Down
16 changes: 7 additions & 9 deletions test/integration/fabric-ca-identity-service-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let tlsOptions = {

let ORGS;

test('\n\n ** HFCAIdentityService Test **\n\n', (t) => {
test('\n\n ** FabricCAServices - IdentityService Test **\n\n', (t) => {

FabricCAServices.addConfigFile(path.join(__dirname, 'e2e', 'config.json'));
ORGS = FabricCAServices.getConfigSetting('test-network');
Expand All @@ -30,20 +30,18 @@ test('\n\n ** HFCAIdentityService Test **\n\n', (t) => {

let bootstrapUser = {
enrollmentID: 'admin',
enrollmentSecret: 'adminpw',
enrollmentSecret: 'adminpw'
};

let admin;
let testIdentity = {
enrollmentID: 'user_' + Math.random().toFixed(2).toString(),
enrollmentSecret: 'userpw',
affiliation: 'org1',
affiliation: 'org1'
};
let update = {
info: {
affiliation: 'org2'
},
secret: 'mysecret',
affiliation: 'org2',
enrollmentSecret: 'mysecret'
};
let hfcaIdentityService;

Expand Down Expand Up @@ -72,8 +70,8 @@ test('\n\n ** HFCAIdentityService Test **\n\n', (t) => {

return hfcaIdentityService.update(testIdentity.enrollmentID, update, admin);
}).then((resp) => {
t.equal(resp.result.secret, update.secret);
t.equal(resp.result.affiliation, update.info.affiliation);
t.equal(resp.result.secret, update.enrollmentSecret);
t.equal(resp.result.affiliation, update.affiliation);
t.pass('Successfully updated indentity ' + testIdentity.enrollmentID);

return hfcaIdentityService.getAll(admin);
Expand Down

0 comments on commit 31fe394

Please sign in to comment.