Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Associate identity with a node #1184

Merged
merged 1 commit into from
Jul 26, 2019
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
1 change: 1 addition & 0 deletions client/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ExtensionCommands {
// ENVIRONMENT VIEW
static readonly ADD_ENVIRONMENT: string = 'environmentExplorer.addEnvironmentEntry';
static readonly DELETE_ENVIRONMENT: string = 'environmentExplorer.deleteEnvironmentEntry';
static readonly ASSOCIATE_IDENTITY_NODE: string = 'environmentExplorer.associateIdentityNodeEntry';
static readonly CONNECT_TO_ENVIRONMENT: string = 'environmentExplorer.connectEntry';
static readonly DISCONNECT_ENVIRONMENT: string = 'environmentExplorer.disconnectEntry';
static readonly INSTALL_SMART_CONTRACT: string = 'environmentExplorer.installSmartContractEntry';
Expand Down
10 changes: 7 additions & 3 deletions client/cucumber/features/evaluate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ Feature: Evaluate transaction

@otherFabric
Scenario Outline: Evaluate a transaction for a smart contract (other fabric)
Given a <language> smart contract for <assetType> assets with the name <name> and version <version>
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
And the 'myFabric' environment is connected
And a <language> smart contract for <assetType> assets with the name <name> and version <version>
And the contract has been created
And the contract has been packaged
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the package has been installed
And the contract has been instantiated with the transaction '' and args '', not using private data
And the gateway 'myGateway' is created
And I'm connected to the 'myGateway' gateway without association
And the other fabric is setup with contract name <name> and version <version>
And the transaction 'createConga' has been submitted with args '["Conga_001", "Big Conga"]'
When I evaluate the transaction 'readConga' with args '["Conga_001"]'
Then the logger should have been called with 'SUCCESS', 'Successfully evaluated transaction' and 'Returned value from readConga: {"value":"Big Conga"}'
Expand Down
42 changes: 37 additions & 5 deletions client/cucumber/features/fabric-environments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: Fabric Environments
| nodeType |
| fabric-peer |
| fabric-ca |
| fabric-orderer |
| fabric-orderer |

Scenario Outline: It should persist data after being stopped
Given the Local Fabric is running
Expand Down Expand Up @@ -73,12 +73,42 @@ Feature: Fabric Environments
Scenario: It should create an environment
When I create an environment 'myFabric'
Then there should be a tree item with a label 'myFabric' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to 'myFabric'
And the tree item should have a tooltip equal to 'myFabric'

@otherFabric
Scenario Outline: It should setup environment
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
When I connect to the environment 'myFabric'
Then there should be a tree item with a label '<label>' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to '<tooltip>'
Examples:
| label | tooltip |
| Setting up: myFabric | Setting up: myFabric |
| (Click each node to perform setup) | (Click each node to perform setup) |
| ca.example.com ⚠ | ca.example.com |
| orderer.example.com ⚠ | orderer.example.com |
| peer0.org1.example.com ⚠ | peer0.org1.example.com |

@otherFabric
Scenario Outline: It should associate nodes with identities
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the 'myFabric' environment is connected
When I associate identity '<identity>' in wallet '<wallet>' with node '<name>'
Then the logger should have been called with 'SUCCESS' and 'Succesfully associated node <name> with wallet <wallet> and identity <identity>'
Examples:
| name | wallet | identity |
| peer0.org1.example.com | myWallet | conga |
| orderer.example.com | myWallet | conga |
| ca.example.com | myWallet | conga2 |


@otherFabric
Scenario Outline: It should connect to an environment
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
When I connect to the environment 'myFabric'
Then there should be a <treeItem> tree item with a label '<label>' in the 'Fabric Environments' panel
And the tree item should have a tooltip equal to '<tooltip>'
Expand All @@ -97,6 +127,7 @@ Feature: Fabric Environments
Scenario Outline: It should instantiate a smart contract
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
And the 'myFabric' environment is connected
And a <language> smart contract for <assetType> assets with the name <name> and version <version>
And the contract has been created
Expand All @@ -113,6 +144,7 @@ Feature: Fabric Environments
Scenario Outline: It should upgrade a smart contract
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
And the 'myFabric' environment is connected
And a <language> smart contract for <assetType> assets with the name <name> and version <version>
And the contract has been created
Expand All @@ -131,6 +163,6 @@ Feature: Fabric Environments

@otherFabric
Scenario: It should delete an environment
Given an environment 'myFabric' exists
When I delete an environment 'myFabric'
Then there should not be a tree item with a label 'myFabric' in the 'Fabric Environments' panel
Given an environment 'myFabric2' exists
When I delete an environment 'myFabric2'
Then there should not be a tree item with a label 'myFabric2' in the 'Fabric Environments' panel
10 changes: 7 additions & 3 deletions client/cucumber/features/submit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ Feature: Submit transaction

@otherFabric
Scenario Outline: Submit a transaction for a smart contract (other fabric)
Given a <language> smart contract for <assetType> assets with the name <name> and version <version>
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
And the 'myFabric' environment is connected
And a <language> smart contract for <assetType> assets with the name <name> and version <version>
And the contract has been created
And the contract has been packaged
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the package has been installed
And the contract has been instantiated with the transaction '' and args '', not using private data
And the gateway 'myGateway' is created
And I'm connected to the 'myGateway' gateway without association
And the other fabric is setup with contract name <name> and version <version>
When I submit the transaction 'createConga' with args '["Conga_001", "Big Conga"]'
Then the logger should have been called with 'SUCCESS', 'Successfully submitted transaction' and 'No value returned from createConga'
Examples:
Expand Down
12 changes: 11 additions & 1 deletion client/cucumber/features/wallet.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Fabric Wallets
And the 'Local Fabric' environment is connected
And the 'Local Fabric' wallet
When I register a new identity 'attributes_user' with the attributes '[{"name": "hello", "value": "world", "ecert": true}]'
Then there should be a identity tree item with a label 'attributes_user' in the 'Fabric Wallets' panel for item local_fabric_wallet
Then there should be an identity tree item with a label 'attributes_user' in the 'Fabric Wallets' panel for item local_fabric_wallet
And the tree item should have a tooltip equal to 'Attributes:\n\nhello:world\nhf.Affiliation:\nhf.EnrollmentID:attributes_user\nhf.Type:client'

@otherFabric
Expand Down Expand Up @@ -63,3 +63,13 @@ Feature: Fabric Wallets
When I create an identity using enrollId with identity name 'otherJason' and mspid 'Org1MSP' in wallet 'myWalletyWallet'
Then there should be a identity tree item with a label 'otherJason' in the 'Fabric Wallets' panel for item myWalletyWallet
And the tree item should have a tooltip equal to 'Attributes:\n\nNone'

@otherFabric
Scenario: create an identity with attributes
Given an environment 'myFabric' exists
And the wallet 'myWallet' with identity 'conga' and mspid 'Org1MSP' exists
And the environment is setup
And the 'myFabric' environment is connected
When I register a new identity 'attributes_user' with the attributes '[{"name": "hello", "value": "world", "ecert": true}]'
Then there should be an identity tree item with a label 'attributes_user' in the 'Fabric Wallets' panel for item myWallet
And the tree item should have a tooltip equal to 'Attributes:\n\nhello:world\nhf.Affiliation:\nhf.EnrollmentID:attributes_user\nhf.Type:client'
36 changes: 35 additions & 1 deletion client/cucumber/helpers/environmentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import * as vscode from 'vscode';
import * as sinon from 'sinon';
import * as path from 'path';
import * as fs from 'fs-extra';
import * as chai from 'chai';
import * as sinonChai from 'sinon-chai';
import * as chaiAsPromised from 'chai-as-promised';
Expand All @@ -29,6 +30,9 @@ import { FabricEnvironmentRegistryEntry } from '../../src/fabric/FabricEnvironme
import { FabricRuntimeUtil } from '../../src/fabric/FabricRuntimeUtil';
import { FabricWalletUtil } from '../../src/fabric/FabricWalletUtil';
import { FabricEnvironmentRegistry } from '../../src/fabric/FabricEnvironmentRegistry';
import { FabricWalletRegistryEntry } from '../../src/fabric/FabricWalletRegistryEntry';
import { FabricNode } from '../../src/fabric/FabricNode';
import { FabricWalletRegistry } from '../../src/fabric/FabricWalletRegistry';

chai.use(sinonChai);
chai.use(chaiAsPromised);
Expand All @@ -45,6 +49,8 @@ export class EnvironmentHelper {

public async createEnvironment(name: string): Promise<void> {
const blockchainEnvironmentExplorerProvider: BlockchainEnvironmentExplorerProvider = myExtension.getBlockchainEnvironmentExplorerProvider();
// need to make sure its not showing the setup tree
blockchainEnvironmentExplorerProvider['fabricEnvironmentToSetUp'] = undefined;
const treeItems: Array<BlockchainTreeItem> = await blockchainEnvironmentExplorerProvider.getChildren();

const treeItem: any = treeItems.find((item: any) => {
Expand All @@ -66,7 +72,35 @@ export class EnvironmentHelper {
}
}

public async connectToEnvironment(environment: string) {
public async deleteEnvironment(environmentName: string): Promise<void> {
this.userInputUtilHelper.showConfirmationWarningMessageStub.resolves('yes');
const fabricEnvironmentRegistryEntry: FabricEnvironmentRegistryEntry = FabricEnvironmentRegistry.instance().get(environmentName);
this.userInputUtilHelper.showEnvironmentQuickPickStub.resolves({ label: environmentName, data: fabricEnvironmentRegistryEntry });
await vscode.commands.executeCommand(ExtensionCommands.DELETE_ENVIRONMENT);
}

public async associateNodeWithIdentitiy(environmentName: string, nodeName: string, identityName: string, walletName: string): Promise<void> {
const walletReigstryEntry: FabricWalletRegistryEntry = FabricWalletRegistry.instance().get(walletName);
this.userInputUtilHelper.showWalletsQuickPickStub.resolves({ label: walletName, data: walletReigstryEntry });
this.userInputUtilHelper.showIdentitiesQuickPickStub.resolves(identityName);
this.userInputUtilHelper.showQuickPickStub.resolves('Use ID and secret to enroll a new identity');
this.userInputUtilHelper.inputBoxStub.withArgs('Provide a name for the identity').resolves(identityName);
this.userInputUtilHelper.inputBoxStub.withArgs('Enter MSPID').resolves('Org1MSP');

const nodePath: string = path.join(__dirname, `../../../cucumber/tmp/environments/${environmentName}/nodes/${nodeName}.json`);
const node: FabricNode = await fs.readJson(nodePath);

if (node.identity && node.wallet) {
// already setup
return;
}

const environmentRegistryEntry: FabricEnvironmentRegistryEntry = FabricEnvironmentRegistry.instance().get(environmentName);

await vscode.commands.executeCommand(ExtensionCommands.ASSOCIATE_IDENTITY_NODE, environmentRegistryEntry, node);
}

public async connectToEnvironment(environment: string): Promise<void> {
let registryEntry: FabricEnvironmentRegistryEntry;
if (environment === 'Local Fabric') {
registryEntry = new FabricEnvironmentRegistryEntry();
Expand Down
4 changes: 4 additions & 0 deletions client/cucumber/helpers/userInputUtilHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class UserInputUtilHelper {
showGetCertKeyStub: sinon.SinonStub;
showAddWalletOptionsQuickPickStub: sinon.SinonStub;
getEnrollIdSecretStub: sinon.SinonStub;
showQuickPickStub: sinon.SinonStub;
showEnvironmentQuickPickStub: sinon.SinonStub;

constructor(sandbox: sinon.SinonSandbox) {
this.mySandBox = sandbox;
Expand Down Expand Up @@ -78,6 +80,8 @@ export class UserInputUtilHelper {
this.showGetCertKeyStub = this.mySandBox.stub(UserInputUtil, 'getCertKey').callThrough();
this.showAddWalletOptionsQuickPickStub = this.mySandBox.stub(UserInputUtil, 'showAddWalletOptionsQuickPick').callThrough();
this.getEnrollIdSecretStub = this.mySandBox.stub(UserInputUtil, 'getEnrollIdSecret').callThrough();
this.showQuickPickStub = this.mySandBox.stub(UserInputUtil, 'showQuickPick').callThrough();
this.showEnvironmentQuickPickStub = this.mySandBox.stub(UserInputUtil, 'showFabricEnvironmentQuickPickBox').callThrough();
}

}
19 changes: 12 additions & 7 deletions client/cucumber/helpers/walletAndIdentityHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { FabricWalletGeneratorFactory } from '../../src/fabric/FabricWalletGener
import { FabricGatewayRegistryEntry } from '../../src/fabric/FabricGatewayRegistryEntry';
import { FabricWalletRegistryEntry } from '../../src/fabric/FabricWalletRegistryEntry';
import { FabricWalletUtil } from '../../src/fabric/FabricWalletUtil';
import { FabricWalletRegistry } from '../../src/fabric/FabricWalletRegistry';

chai.use(sinonChai);
chai.use(chaiAsPromised);
Expand All @@ -48,15 +49,19 @@ export class WalletAndIdentityHelper {
this.userInputUtilHelper = userInputUtilHelper;
}

public async createCAIdentity(name: string, attributes: string = '[]'): Promise<void> {
const walletEntry: FabricWalletRegistryEntry = new FabricWalletRegistryEntry();
walletEntry.name = FabricWalletUtil.LOCAL_WALLET;
walletEntry.walletPath = WalletAndIdentityHelper.localWalletPath;
public async createCAIdentity(walletName: string, identitiyName: string, attributes: string = '[]'): Promise<void> {
let walletEntry: FabricWalletRegistryEntry;
if (walletName === FabricWalletUtil.LOCAL_WALLET) {
walletEntry = new FabricWalletRegistryEntry();
walletEntry.name = FabricWalletUtil.LOCAL_WALLET;
walletEntry.walletPath = WalletAndIdentityHelper.localWalletPath;
} else {
walletEntry = FabricWalletRegistry.instance().get(walletName);
}

const identityExists: boolean = await fs.pathExists(path.join(walletEntry.walletPath, name));
const identityExists: boolean = await fs.pathExists(path.join(walletEntry.walletPath, identitiyName));
if (!identityExists) {
this.userInputUtilHelper.showCertificateAuthorityQuickPickStub.withArgs('Choose certificate authority to create a new identity with').resolves('ca.org1.example.com');
this.userInputUtilHelper.inputBoxStub.withArgs('Provide a name for the identity').resolves(name);
this.userInputUtilHelper.inputBoxStub.withArgs('Provide a name for the identity').resolves(identitiyName);

if (attributes !== '[]') {
// The user has given us attributes
Expand Down
7 changes: 3 additions & 4 deletions client/cucumber/hlfv1/nodes/ca.example.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"api_url": "http://localhost:7054",
"type": "fabric-ca",
"ca_name": "ca.example.com",
"wallet": "myWallet",
"identity": "conga",
"msp_id": "Org1MSP",
"container_name": "ca.example.com"
"container_name": "ca.example.com",
"enroll_id": "admin",
"enroll_secret": "adminpw"
}
2 changes: 0 additions & 2 deletions client/cucumber/hlfv1/nodes/orderer.example.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"name": "orderer.example.com",
"api_url": "grpc://localhost:7050",
"type": "fabric-orderer",
"wallet": "myWallet",
"identity": "conga",
"msp_id": "OrdererMSP",
"container_name": "orderer.example.com"
}
2 changes: 0 additions & 2 deletions client/cucumber/hlfv1/nodes/peer0.org1.example.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"api_url": "grpc://localhost:7051",
"chaincode_url": "grpc://localhost:7053",
"type": "fabric-peer",
"wallet": "myWallet",
"identity": "conga",
"msp_id": "Org1MSP",
"container_name": "peer0.org1.example.com"
}
8 changes: 4 additions & 4 deletions client/cucumber/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ async function runCucumberTest(): Promise<any> {
features[3] = feature;
} else if (file === 'upgrade.feature') {
features[4] = feature;
} else if (file === 'submit.feature') {
} else if (file === 'fabric-environments.feature') {
features[5] = feature;
} else if (file === 'evaluate.feature') {
} else if (file === 'submit.feature') {
features[6] = feature;
} else if (file === 'wallet.feature') {
} else if (file === 'evaluate.feature') {
features[7] = feature;
} else if (file === 'fabric-environments.feature') {
} else if (file === 'wallet.feature') {
features[8] = feature;
} else {
otherFeatures.push(feature);
Expand Down
Loading