This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
System and unit tests Rich query support for fabric V1 alpha Alpha 2 Support
- Loading branch information
Showing
121 changed files
with
3,123 additions
and
2,497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Import = require ('./lib/import.js'); | ||
|
||
module.exports.command = 'import [options]'; | ||
module.exports.describe = 'Import an identity to wallet defined by the connection profile'; | ||
module.exports.builder = { | ||
connectionProfileName: {alias: 'p', required: true, describe: 'The connection profile name', type: 'string' }, | ||
userId: { alias: 'u', required: true, describe: 'The user ID for the new identity', type: 'string' }, | ||
publicKeyFile: { alias: 'c', required: true, describe: 'File containing the public key', type: 'string' }, | ||
privateKeyFile: { alias: 'k', required: true, describe: 'File containing the private key', type: 'string' } | ||
}; | ||
|
||
module.exports.handler = (argv) => { | ||
argv.thePromise = Import.handler(argv) | ||
.then(() => { | ||
console.log ('Command completed successfully.'); | ||
}); | ||
return argv.thePromise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
const cmdUtil = require('../../utils/cmdutils'); | ||
|
||
/** | ||
* <p> | ||
* Composer "identity issue" command | ||
* </p> | ||
* <p><a href="diagrams/Deploy.svg"><img src="diagrams/deploy.svg" style="width:100%;"/></a></p> | ||
* @private | ||
*/ | ||
class Import { | ||
|
||
/** | ||
* Command process for deploy command | ||
* @param {string} argv argument list from composer command | ||
* @return {Promise} promise when command complete | ||
*/ | ||
static handler(argv) { | ||
let userId; | ||
let publicKeyFile; | ||
let privateKeyFile; | ||
let connectionProfileName; | ||
|
||
userId = argv.userId; | ||
publicKeyFile = argv.publicKeyFile; | ||
privateKeyFile = argv.privateKeyFile; | ||
connectionProfileName = argv.connectionProfileName; | ||
let adminConnection = cmdUtil.createAdminConnection(); | ||
let signerCert; | ||
let key; | ||
try { | ||
signerCert = fs.readFileSync(publicKeyFile).toString(); | ||
} catch(error) { | ||
return Promise.reject(new Error('Unable to read public key file ' + publicKeyFile + '. ' + error.message)); | ||
} | ||
try { | ||
key = fs.readFileSync(privateKeyFile).toString(); | ||
} catch(error) { | ||
return Promise.reject(new Error('Unable to read private key file ' + privateKeyFile + '. ' + error.message)); | ||
} | ||
return adminConnection.importIdentity(connectionProfileName, userId, signerCert, key) | ||
.then((result) => { | ||
console.log(`An identity was imported with name '${userId}' successfully`); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Import; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Client = require('composer-admin'); | ||
|
||
const Import = require('../../lib/cmds/identity/importCommand.js'); | ||
const CmdUtil = require('../../lib/cmds/utils/cmdutils.js'); | ||
const fs = require('fs'); | ||
|
||
const sinon = require('sinon'); | ||
require('sinon-as-promised'); | ||
const chai = require('chai'); | ||
chai.should(); | ||
chai.use(require('chai-as-promised')); | ||
|
||
const PROFILE_NAME = 'myprofile'; | ||
const USER_ID = 'SuccessKid'; | ||
const CERT_PATH = 'someCertPath'; | ||
const KEY_PATH = 'someKeyPath'; | ||
|
||
describe('composer identity import CLI unit tests', () => { | ||
|
||
let sandbox; | ||
let mockAdminConnection; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
mockAdminConnection = sinon.createStubInstance(Client.AdminConnection); | ||
sandbox.stub(CmdUtil, 'createAdminConnection').returns(mockAdminConnection); | ||
sandbox.stub(process, 'exit'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should import a new identity using the specified profile', () => { | ||
let argv = { | ||
connectionProfileName: PROFILE_NAME, | ||
userId: USER_ID, | ||
publicKeyFile: CERT_PATH, | ||
privateKeyFile: KEY_PATH | ||
}; | ||
|
||
let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert'); | ||
fsStub.withArgs(KEY_PATH).returns('akey'); | ||
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves(); | ||
return Import.handler(argv) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockAdminConnection.importIdentity); | ||
sinon.assert.calledWith(mockAdminConnection.importIdentity, PROFILE_NAME, USER_ID, 'acert', 'akey'); | ||
}); | ||
}); | ||
|
||
it('should fail gracefully if importIdentity fails', () => { | ||
let argv = { | ||
connectionProfileName: PROFILE_NAME, | ||
userId: USER_ID, | ||
publicKeyFile: CERT_PATH, | ||
privateKeyFile: KEY_PATH | ||
}; | ||
|
||
let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert'); | ||
fsStub.withArgs(KEY_PATH).returns('akey'); | ||
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').rejects('some error'); | ||
return Import.handler(argv) | ||
.should.be.rejectedWith(/some error/); | ||
}); | ||
|
||
it('should fail gracefully if cert file cannot be found', () => { | ||
let argv = { | ||
connectionProfileName: PROFILE_NAME, | ||
userId: USER_ID, | ||
publicKeyFile: CERT_PATH, | ||
privateKeyFile: KEY_PATH | ||
}; | ||
|
||
let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).throws(new Error('no file found')); | ||
fsStub.withArgs(KEY_PATH).returns('akey'); | ||
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves(); | ||
return Import.handler(argv) | ||
.should.be.rejectedWith(/no file found/); | ||
|
||
}); | ||
|
||
it('should fail gracefully if key file cannot be found', () => { | ||
let argv = { | ||
connectionProfileName: PROFILE_NAME, | ||
userId: USER_ID, | ||
publicKeyFile: CERT_PATH, | ||
privateKeyFile: KEY_PATH | ||
}; | ||
|
||
let fsStub = sandbox.stub(fs, 'readFileSync').withArgs(CERT_PATH).returns('acert'); | ||
fsStub.withArgs(KEY_PATH).throws(new Error('no key file found')); | ||
mockAdminConnection.importIdentity.withArgs(PROFILE_NAME, USER_ID, 'acert', 'akey').resolves(); | ||
return Import.handler(argv) | ||
.should.be.rejectedWith(/no key file found/); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.