Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"packages": [
"packages/*"
],
"version": "0.9.2",
"version": "0.9.3",
"hoist": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"name": "composer",
"description": "You must install [Lerna](https://lernajs.io) to build this multi-package repository.",
"version": "0.9.2",
"version": "0.9.3",
"main": "index.js",
"private": true,
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions packages/composer-admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-admin",
"version": "0.9.2",
"version": "0.9.3",
"description": "Hyperledger Composer Admin, code that manages business networks deployed to Hyperledger Fabric",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,9 +42,9 @@
"sinon-as-promised": "^4.0.2"
},
"dependencies": {
"composer-common": "^0.9.2",
"composer-connector-hlf": "^0.9.2",
"composer-connector-hlfv1": "^0.9.2"
"composer-common": "^0.9.3",
"composer-connector-hlf": "^0.9.3",
"composer-connector-hlfv1": "^0.9.3"
},
"license-check-config": {
"src": [
Expand Down
10 changes: 5 additions & 5 deletions packages/composer-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-cli",
"version": "0.9.2",
"version": "0.9.3",
"description": "Hyperledger Composer command line interfaces (CLIs)",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,10 +42,10 @@
"dependencies": {
"chalk": "^1.1.3",
"cli-table": "^0.3.1",
"composer-admin": "^0.9.2",
"composer-client": "^0.9.2",
"composer-common": "^0.9.2",
"composer-rest-server": "^0.9.2",
"composer-admin": "^0.9.3",
"composer-client": "^0.9.3",
"composer-common": "^0.9.3",
"composer-rest-server": "^0.9.3",
"homedir": "^0.6.0",
"npm-paths": "^0.1.3",
"nunjucks": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-client/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BusinessNetworkConnection extends EventEmitter {
+ Promise ping()
+ Promise issueIdentity(string,object,boolean)
+ Promise bindIdentity(string)
+ Promise revokeIdentity(string)
+ Promise revokeIdentity()
}
class IdentityRegistry extends Registry {
+ Promise getIdentityRegistry(SecurityContext,ModelManager,Factory,Serializer)
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-client/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 0.9.2 {60d41f6d3b545fd4ad53ca2bf0e5a36c} 2017-07-11
Version 0.9.3 {6eb4db0430cdbc024d059e7987946e24} 2017-07-11
- Added bindIdentity
- Added getIdentityRegistry

Expand Down
16 changes: 11 additions & 5 deletions packages/composer-client/lib/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,23 @@ class BusinessNetworkConnection extends EventEmitter {

/**
* Revoke the specified identity by removing any existing mapping to a participant.
* @param {string} identityId The identity, for example the enrollment ID.
* @param {Resource|string} identity The identity, or the identifier of the identity.
* @return {Promise} A promise that will be fulfilled when the identity has
* been removed from the specified participant. The promise will be rejected if
* the participant does not exist, or if the identity is not mapped to the
* participant.
*/
revokeIdentity(identityId) {
revokeIdentity(identity) {
const method = 'revokeIdentity';
LOG.entry(method, identityId);
if (!identityId) {
throw new Error('identityId not specified');
LOG.entry(method, identity);
if (!identity) {
throw new Error('identity not specified');
}
let identityId;
if (identity instanceof Resource) {
identityId = identity.getIdentifier();
} else {
identityId = identity;
}
Util.securityCheck(this.securityContext);
// It is not currently possible to revoke the certificate, so we just call
Expand Down
10 changes: 3 additions & 7 deletions packages/composer-client/lib/identityregistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ class IdentityRegistry extends Registry {
} else if (!serializer) {
throw new Error('serializer not specified');
}
return Registry.getAllRegistries(securityContext, REGISTRY_TYPE)
.then((registries) => {
return registries.map((registry) => {
if (registry.id === 'org.hyperledger.composer.system.Identity') {
return new IdentityRegistry(registry.id, registry.name, securityContext, modelManager, factory, serializer);
}
})[0];
return Registry.getRegistry(securityContext, REGISTRY_TYPE, 'org.hyperledger.composer.system.Identity')
.then((registry) => {
return new IdentityRegistry(registry.id, registry.name, securityContext, modelManager, factory, serializer);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/composer-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composer-client",
"version": "0.9.2",
"version": "0.9.3",
"description": "The node.js client library for Hyperledger Composer, a development framework for Hyperledger Fabric",
"engines": {
"node": ">=6",
Expand Down Expand Up @@ -42,9 +42,9 @@
"logError": true
},
"dependencies": {
"composer-common": "^0.9.2",
"composer-connector-hlf": "^0.9.2",
"composer-connector-hlfv1": "^0.9.2",
"composer-common": "^0.9.3",
"composer-connector-hlf": "^0.9.3",
"composer-connector-hlfv1": "^0.9.3",
"uuid": "^3.0.1"
},
"devDependencies": {
Expand Down
79 changes: 30 additions & 49 deletions packages/composer-client/test/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ComboConnectionProfileStore = require('composer-common').ComboConnectionPr
const commonQuery = require('composer-common').Query;
const Connection = require('composer-common').Connection;
const FSConnectionProfileStore = require('composer-common').FSConnectionProfileStore;
const IdentityRegistry = require('../lib/identityregistry');
const ModelManager = require('composer-common').ModelManager;
const ParticipantRegistry = require('../lib/participantregistry');
const Query = require('../lib/query');
Expand All @@ -33,8 +34,6 @@ const Resource = require('composer-common').Resource;
const SecurityContext = require('composer-common').SecurityContext;
const TransactionDeclaration = require('composer-common').TransactionDeclaration;
const TransactionRegistry = require('../lib/transactionregistry');
const IdentityRegistry = require('../lib/identityregistry');
const Registry = require('../lib/registry');
const Util = require('composer-common').Util;
const uuid = require('uuid');
const version = require('../package.json').version;
Expand Down Expand Up @@ -1073,63 +1072,30 @@ describe('BusinessNetworkConnection', () => {

});

describe('#bindIdentity', () => {

const pem = '-----BEGIN CERTIFICATE-----\nMIIB8jCCAZmgAwIBAgIULKt4c4xcdMwGgjNef9IL92HQkyAwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNzA4MTg1NzAwWhcNMTgwNzA4MTg1\nNzAwWjASMRAwDgYDVQQDEwdib29iaWVzMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD\nQgAE5P4RNqfEy8pArDxAbVIjRxqkwlpHUY7ANR6X7a4uvVIzIPDx4p7lf37xuc+5\nI9VZCvcI1SA5nIRphet0yYSgZaNsMGowDgYDVR0PAQH/BAQDAgIEMAwGA1UdEwEB\n/wQCMAAwHQYDVR0OBBYEFAmjJfUZvdB8pHvklsdd1HiVog+VMCsGA1UdIwQkMCKA\nIBmrZau7BIB9rRLkwKmqpmSecIaOOr0CF6Mi2J5H4aauMAoGCCqGSM49BAMCA0cA\nMEQCIGtqR9rUR2ESu2UfUpNUfEeeBsshMkMHmuP/r5uvo2fSAiBtFB9Aid/3nexB\nI5qkVbdRSRQpt7uxoKFDLV/LUDM9xw==\n-----END CERTIFICATE-----\n';

beforeEach(() => {
businessNetworkConnection.connection = mockConnection;
});
describe('#revokeIdentity', () => {

it('should throw if participant not specified', () => {
(() => {
businessNetworkConnection.bindIdentity(null, pem);
}).should.throw(/participant not specified/);
});

it('should throw if certificate not specified', () => {
it('should throw if identity not specified', () => {
(() => {
let mockResource = sinon.createStubInstance(Resource);
mockResource.getFullyQualifiedIdentifier.returns('org.doge.Doge#DOGE_1');
businessNetworkConnection.bindIdentity(mockResource, null);
}).should.throw(/certificate not specified/);
businessNetworkConnection.revokeIdentity(null);
}).should.throw(/identity not specified/);
});

it('should submit a request to the chaincode for a resource', () => {
sandbox.stub(Util, 'invokeChainCode').resolves();
let mockResource = sinon.createStubInstance(Resource);
mockResource.getFullyQualifiedIdentifier.returns('org.doge.Doge#DOGE_1');
return businessNetworkConnection.bindIdentity(mockResource, pem)
.then(() => {
sinon.assert.calledOnce(Util.invokeChainCode);
sinon.assert.calledWith(Util.invokeChainCode, mockSecurityContext, 'bindIdentity', ['org.doge.Doge#DOGE_1', pem]);
});
});

it('should submit a request to the chaincode for a fully qualified identifier', () => {
sandbox.stub(Util, 'invokeChainCode').resolves();
return businessNetworkConnection.bindIdentity('org.doge.Doge#DOGE_1', pem)
return businessNetworkConnection.revokeIdentity('dogeid1')
.then(() => {
sinon.assert.calledOnce(Util.invokeChainCode);
sinon.assert.calledWith(Util.invokeChainCode, mockSecurityContext, 'bindIdentity', ['org.doge.Doge#DOGE_1', pem]);
sinon.assert.calledWith(Util.invokeChainCode, mockSecurityContext, 'revokeIdentity', ['dogeid1']);
});
});

});

describe('#revokeIdentity', () => {

it('should throw if identityId not specified', () => {
(() => {
let mockResource = sinon.createStubInstance(Resource);
mockResource.getFullyQualifiedIdentifier.returns('org.doge.Doge#DOGE_1');
businessNetworkConnection.revokeIdentity(null);
}).should.throw(/identityId not specified/);
});

it('should submit a request to the chaincode', () => {
it('should submit a request to the chaincode for an identifier', () => {
let mockResource = sinon.createStubInstance(Resource);
mockResource.getIdentifier.returns('dogeid1');
sandbox.stub(Util, 'invokeChainCode').resolves();
return businessNetworkConnection.revokeIdentity('dogeid1')
return businessNetworkConnection.revokeIdentity(mockResource)
.then(() => {
sinon.assert.calledOnce(Util.invokeChainCode);
sinon.assert.calledWith(Util.invokeChainCode, mockSecurityContext, 'revokeIdentity', ['dogeid1']);
Expand All @@ -1145,15 +1111,30 @@ describe('BusinessNetworkConnection', () => {
// Set up the mock.
let stub = sandbox. stub(Util, 'securityCheck');
let identityRegistry = sinon.createStubInstance(IdentityRegistry);
identityRegistry.id = 'org.hyperledger.composer.system.Identity';
identityRegistry.name = 'such registry';
sandbox.stub(Registry, 'getAllRegistries').resolves([identityRegistry]);
sandbox.stub(IdentityRegistry, 'getIdentityRegistry').resolves(identityRegistry);

// Invoke the function.
return businessNetworkConnection
.getIdentityRegistry()
.then(() => {
sinon.assert.calledTwice(stub);
sinon.assert.calledOnce(stub);
});

});

it('should call the static helper method', () => {

// Set up the mock.
let mockIdentityRegistry = sinon.createStubInstance(IdentityRegistry);
let stub = sandbox.stub(IdentityRegistry, 'getIdentityRegistry').resolves(mockIdentityRegistry);

// Invoke the function.
return businessNetworkConnection
.getIdentityRegistry()
.then((result) => {
sinon.assert.calledOnce(stub);
sinon.assert.calledWith(stub, sinon.match.instanceOf(SecurityContext), sinon.match.instanceOf(ModelManager), sinon.match.instanceOf(Factory), sinon.match.instanceOf(Serializer));
result.should.equal(mockIdentityRegistry);
});

});
Expand Down
30 changes: 10 additions & 20 deletions packages/composer-client/test/identityregistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
'use strict';

const Factory = require('composer-common').Factory;
const ModelManager = require('composer-common').ModelManager;
const IdentityRegistry = require('../lib/identityregistry');
const ModelManager = require('composer-common').ModelManager;
const Registry = require('../lib/registry');
const SecurityContext = require('composer-common').SecurityContext;
const Serializer = require('composer-common').Serializer;
Expand Down Expand Up @@ -70,26 +70,26 @@ describe('IdentityRegistry', () => {
}).should.throw(/serializer not specified/);
});

it('should invoke the chain-code and return the transaction registry', () => {
it('should invoke the chain-code and return the identity registry', () => {

// Set up the responses from the chain-code.
sandbox.stub(Registry, 'getAllRegistries', () => {
sandbox.stub(Registry, 'getRegistry', () => {
return Promise.resolve(
[{id: 'org.hyperledger.composer.system.Identity', name: 'doge registry'}]
{id: 'org.hyperledger.composer.system.Identity', name: 'doge registry'}
);
});

// Invoke the getAllTransactionRegistries function.
// Invoke the getAllIdentityRegistries function.
return IdentityRegistry
.getIdentityRegistry(mockSecurityContext, mockModelManager, mockFactory, mockSerializer)
.then((identityRegistry) => {

// Check that the registry was requested correctly.
sinon.assert.calledWith(Util.securityCheck, mockSecurityContext);
sinon.assert.calledOnce(Registry.getAllRegistries);
sinon.assert.calledWith(Registry.getAllRegistries, mockSecurityContext, 'Asset');
sinon.assert.calledOnce(Registry.getRegistry);
sinon.assert.calledWith(Registry.getRegistry, mockSecurityContext, 'Asset', 'org.hyperledger.composer.system.Identity');

// Check that the transaction registries were returned correctly.
// Check that the identity registries were returned correctly.
identityRegistry.should.be.an.instanceOf(IdentityRegistry);
identityRegistry.id.should.equal('org.hyperledger.composer.system.Identity');
identityRegistry.name.should.equal('doge registry');
Expand All @@ -101,13 +101,13 @@ describe('IdentityRegistry', () => {
it('should handle an error from the chain-code', () => {

// Set up the responses from the chain-code.
sandbox.stub(Registry, 'getAllRegistries', () => {
sandbox.stub(Registry, 'getRegistry', () => {
return Promise.reject(
new Error('failed to invoke chain-code')
);
});

// Invoke the getAllTransactionRegistries function.
// Invoke the getAllIdentityRegistries function.
return IdentityRegistry
.getIdentityRegistry(mockSecurityContext, mockModelManager, mockFactory, mockSerializer)
.then((identityRegistry) => {
Expand All @@ -118,16 +118,6 @@ describe('IdentityRegistry', () => {

});

it('should not throw if Identity registry is not found', () => {
sandbox.stub(Registry, 'getAllRegistries', () => {
return Promise.resolve(
[{id: 'org.hyperledger.composer.system.Doge', name: 'doge registry'}]
);
});
(function () {
IdentityRegistry.getIdentityRegistry(mockSecurityContext, mockModelManager, mockFactory, mockSerializer);
}).should.not.throw();
});
});

describe('#add', () => {
Expand Down
18 changes: 11 additions & 7 deletions packages/composer-common/lib/modelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ const LOG = require('./log/logger').getLog('ModelManager');
const SYSTEM_MODEL_CONTENTS = `
namespace org.hyperledger.composer.system

abstract asset Asset { }
abstract asset Asset {

abstract participant Participant { }
}

abstract participant Participant {

}

abstract transaction Transaction identified by transactionId{
abstract transaction Transaction identified by transactionId {
o String transactionId
o DateTime timestamp
}

abstract event Event identified by eventId{
abstract event Event identified by eventId {
o String eventId
o DateTime timestamp
}
Expand All @@ -47,8 +51,8 @@ const SYSTEM_MODEL_CONTENTS = `
o REVOKED
}

asset Identity identified by identifier extends Asset {
o String identifier
asset Identity identified by identityId extends Asset {
o String identityId
o String name
o String issuer
o String certificate
Expand All @@ -75,7 +79,7 @@ const SYSTEM_MODEL_CONTENTS = `
}

transaction RevokeIdentity extends IdentityTransaction {
o String identifier
--> Identity identity
}
`;

Expand Down
Loading