You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
I'd like to be able to test access control to chaincode invocations based on whether or not the fabric client's certificate has the required attributes. Here is some example chaincode. I don't see any built-in functionality for mocking the cert coming from stub. Am I missing something? Thanks in advance.
/////////////////////////////////////////////////////////// ROLE-BASED ACCESS CONTROL EXAMPLE// // The following chaincode demonstrates how to prevent// unauthorized clients from invoking chaincode methods./////////////////////////////////////////////////////////'use strict';constshim=require('fabric-shim');/////////////////////////////////////////////////////////// requireRole//// This method will throw an error if the calling client// does not have the specified role./////////////////////////////////////////////////////////asyncfunctionrequireRole(stub,role){constClientIdentity=shim.ClientIdentity;letcid=newClientIdentity(stub);if(!cid.assertAttributeValue('role',role))thrownewError(`Unauthorized access: ${role} required`);}letChaincode=class{asyncInit(stub){console.info('============= Init called =============');returnshim.success();}asyncInvoke(stub){console.info('============= Invoke called =============');// ensure client has admin role before proceedingtry{awaitrequireRole(stub,'admin');}catch(err){// log failed access attempt and returnconsole.error("Error during Invoke: ",err);returnshim.error(err.message||err);}// client has the expected role, so continueconsole.info('SUCCESS!')returnshim.success();}}shim.start(newChaincode());
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'd like to be able to test access control to chaincode invocations based on whether or not the fabric client's certificate has the required attributes. Here is some example chaincode. I don't see any built-in functionality for mocking the cert coming from stub. Am I missing something? Thanks in advance.
The text was updated successfully, but these errors were encountered: