diff --git a/packages/composer-common/api.txt b/packages/composer-common/api.txt index 3699aacb1f..334b5a2eeb 100644 --- a/packages/composer-common/api.txt +++ b/packages/composer-common/api.txt @@ -50,11 +50,10 @@ class FileWallet extends Wallet { class IdCard { + String getName() + String getDescription() - + String getBusinessNetwork() - + Object getImage() - + Object getConnection() - + Map getCredentials() - + Map getTlsCertificates() + + String getBusinessNetworkName() + + Object getConnectionProfile() + + Object getCredentials() + + Object getEnrollmentCredentials() + Promise fromArchive(Buffer) } class IllegalModelException extends BaseFileException { diff --git a/packages/composer-common/changelog.txt b/packages/composer-common/changelog.txt index 9ee60d4a7b..e68a3671af 100644 --- a/packages/composer-common/changelog.txt +++ b/packages/composer-common/changelog.txt @@ -11,7 +11,7 @@ # # Note that the latest public API is documented using JSDocs and is available in api.txt. # -Version 0.10.1 {fe6fa1850003a7c5d47bf43e3ab8d628} 2017-07-24 +Version 0.10.1 {5d850eefdff10604eb0fdef2bd7aef5a} 2017-07-24 - Added InvalidQueryException, BaseFileException - Added IdCard to composer-common package diff --git a/packages/composer-common/index.js b/packages/composer-common/index.js index 8eadfb1c9c..c562d1fe48 100644 --- a/packages/composer-common/index.js +++ b/packages/composer-common/index.js @@ -76,6 +76,7 @@ module.exports.FileWriter = require('./lib/codegen/filewriter'); module.exports.FSConnectionProfileStore = require('./lib/fsconnectionprofilestore'); module.exports.FunctionDeclaration = require('./lib/introspect/functiondeclaration'); module.exports.Globalize = require('./lib/globalize'); +module.exports.IdCard = require('./lib/idcard'); module.exports.Introspector = require('./lib/introspect/introspector'); module.exports.Limit = require('./lib/query/limit'); module.exports.Logger = require('./lib/log/logger'); diff --git a/packages/composer-common/lib/idcard.js b/packages/composer-common/lib/idcard.js index 251df11f8e..43e8fac27c 100644 --- a/packages/composer-common/lib/idcard.js +++ b/packages/composer-common/lib/idcard.js @@ -15,37 +15,44 @@ 'use strict'; const JSZip = require('jszip'); -const path = require('path'); const Logger = require('./log/logger'); const LOG = Logger.getLog('IdCard'); /** - * An ID card. + * An ID card. Encapsulates credentials and other information required to connect to a specific business network + * as a specific user. + *
+ * Instances of this class should be created using {@link IdCard.fromArchive}. * @class * @memberof module:composer-common */ class IdCard { /** - * Create the BusinessNetworkDefinition. + * Create the IdCard. *
* Note: Only to be called by framework code. Applications should * retrieve instances from {@link IdCard.fromArchive} * @param {Object} metadata - metadata associated with the card. - * @param {Object} connection - connection properties associated with the card. - * @param {Map} credentials - map of credential filename String keys to credential data Buffer objects. - * @param {Map} tlscerts - map of TLS certificate filename String keys to TLS certificate data Buffer objects. + * @param {Object} connectionProfile - connection profile associated with the card. + * @param {Object} credentials - credentials used to connect to business network. * @private */ - constructor(metadata, connection, credentials, tlscerts) { + constructor(metadata, connectionProfile, credentials) { const method = 'constructor'; LOG.entry(method); + if (!(metadata && metadata.name)) { + throw Error('Required metadata field not found: name'); + } + if (!(connectionProfile && connectionProfile.name)) { + throw Error('Required connection field not found: name'); + } + this.metadata = metadata; - this.connection = connection; + this.connectionProfile = connectionProfile; this.credentials = credentials; - this.tlscerts = tlscerts; LOG.exit(method); } @@ -62,52 +69,55 @@ class IdCard { /** * Free text description of the card. - * @return {String} description, or {@link undefined} if none exists. + * @return {String} card description. */ getDescription() { - return this.metadata.description; - } - - /** - * Business network to which the ID card applies. Generally this will be present but may be omitted for system - * cards. - * @return {String} description, or {@link undefined} if none exists. - */ - getBusinessNetwork() { - return this.metadata.businessNetwork; + return this.metadata.description || ''; } /** - * Image associated with the card. - * @return {Object} an object of the form { name: imageFileName, data: bufferOfImageData }, - * or {@link undefined} if none exists. + * Name of the business network to which the ID card applies. Generally this will be present but may be + * omitted for system cards. + * @return {String} business network name. */ - getImage() { - return this.image; + getBusinessNetworkName() { + return this.metadata.businessNetwork || ''; } /** * Connection profile for this card. + *
+ * This is a mandatory field. * @return {Object} connection profile. */ - getConnection() { - return this.connection; + getConnectionProfile() { + return this.connectionProfile; } /** - * Credentials associated with this card. - * @return {Map} Map of filename {@link String} keys to {@link Buffer} data. + * Credentials associated with this card, and which are used to connect to the associated business network. + * @return {Object} credentials in the form { public: publicKey, private: privateKey }, if they exist. */ getCredentials() { return this.credentials; } /** - * TLS certificates used to connect to the business networks. - * @return {Map} Map of filename {@link String} keys to {@link Buffer} data. + * Enrollment credentials. If there are no credentials associated with this card, these credentials are used to + * enroll with a business network and obtain certificates. + * @return {Object} enrollment credentials in the form { id: enrollmentId, secret: enrollmentSecret }, if + * they exist. */ - getTlsCertificates() { - return this.tlscerts; + getEnrollmentCredentials() { + let result = null; + const id = this.metadata.enrollmentId; + const secret = this.metadata.enrollmentSecret; + if (id || secret) { + result = Object.create(null); + result.id = id; + result.secret = secret; + } + return result; } /** @@ -123,10 +133,8 @@ class IdCard { let promise = Promise.resolve(); let metadata; - let image; let connection; - const credentials = new Map(); - const tlscerts = new Map(); + let credentials = Object.create(null); LOG.debug(method, 'Loading connection.json'); const connectionFile = zip.file('connection.json'); @@ -150,52 +158,28 @@ class IdCard { return metadataFile.async('string'); }).then((metadataContent) => { metadata = JSON.parse(metadataContent); - if (!metadata.name) { - throw Error('Required meta-data field not found: name'); - } - - if (metadata.image) { - LOG.debug(method, 'Loading image ' + metadata.image); - - const imagePromise = zip.file(metadata.image); - if (!imagePromise) { - throw Error('Image file not found: ' + metadata.image); - } - - return imagePromise.async('nodebuffer').then((imageContent) => { - const shortFilename = path.basename(metadata.image); - image = { - name: shortFilename, - data: imageContent - }; - }); - } }); - const loadDirectoryToMap = function(directoryName, map) { + const loadDirectoryToObject = function(directoryName, obj) { // Incude '/' following directory name const fileIndex = directoryName.length + 1; // Find all files that are direct children of specified directory const files = zip.file(new RegExp(`^${directoryName}/[^/]+$`)); files && files.forEach((file) => { promise = promise.then(() => { - return file.async('nodebuffer'); + return file.async('string'); }).then((content) => { const filename = file.name.slice(fileIndex); - map.set(filename, content); + obj[filename] = content; }); }); }; LOG.debug(method, 'Loading credentials'); - loadDirectoryToMap('credentials', credentials); - - LOG.debug(method, 'Loading tlscerts'); - loadDirectoryToMap('tlscerts', tlscerts); + loadDirectoryToObject('credentials', credentials); return promise.then(() => { - const idCard = new IdCard(metadata, connection, credentials, tlscerts); - idCard.image = image; + const idCard = new IdCard(metadata, connection, credentials); LOG.exit(method, idCard.toString()); return idCard; }); diff --git a/packages/composer-common/test/data/id-cards/invalid-metadata-image/metadata.json b/packages/composer-common/test/data/id-cards/invalid-metadata-image/metadata.json deleted file mode 100644 index f9ca62bc90..0000000000 --- a/packages/composer-common/test/data/id-cards/invalid-metadata-image/metadata.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name" : "com.example.cards.Minimal", - "image": "NON_EXISTENT_IMAGE_FILENAME" -} diff --git a/packages/composer-common/test/data/id-cards/minimal/connection.json b/packages/composer-common/test/data/id-cards/minimal/connection.json index 549c63eef9..c77d5ec141 100644 --- a/packages/composer-common/test/data/id-cards/minimal/connection.json +++ b/packages/composer-common/test/data/id-cards/minimal/connection.json @@ -1,4 +1,5 @@ { + "name": "hlfv1", "type": "hlfv1", "orderers": [ { diff --git a/packages/composer-common/test/data/id-cards/minimal/metadata.json b/packages/composer-common/test/data/id-cards/minimal/metadata.json index 249da19d9b..c76a323a5f 100644 --- a/packages/composer-common/test/data/id-cards/minimal/metadata.json +++ b/packages/composer-common/test/data/id-cards/minimal/metadata.json @@ -1,3 +1,3 @@ { - "name" : "com.example.cards.Minimal" + "name": "Minimal" } diff --git a/packages/composer-common/test/data/id-cards/invalid-metadata-image/connection.json b/packages/composer-common/test/data/id-cards/missing-connection-name/connection.json similarity index 100% rename from packages/composer-common/test/data/id-cards/invalid-metadata-image/connection.json rename to packages/composer-common/test/data/id-cards/missing-connection-name/connection.json diff --git a/packages/composer-common/test/data/id-cards/missing-connection-name/metadata.json b/packages/composer-common/test/data/id-cards/missing-connection-name/metadata.json new file mode 100644 index 0000000000..c76a323a5f --- /dev/null +++ b/packages/composer-common/test/data/id-cards/missing-connection-name/metadata.json @@ -0,0 +1,3 @@ +{ + "name": "Minimal" +} diff --git a/packages/composer-common/test/data/id-cards/missing-connection/metadata.json b/packages/composer-common/test/data/id-cards/missing-connection/metadata.json index 249da19d9b..c76a323a5f 100644 --- a/packages/composer-common/test/data/id-cards/missing-connection/metadata.json +++ b/packages/composer-common/test/data/id-cards/missing-connection/metadata.json @@ -1,3 +1,3 @@ { - "name" : "com.example.cards.Minimal" + "name": "Minimal" } diff --git a/packages/composer-common/test/data/id-cards/missing-metadata-name/connection.json b/packages/composer-common/test/data/id-cards/missing-metadata-name/connection.json index 549c63eef9..c77d5ec141 100644 --- a/packages/composer-common/test/data/id-cards/missing-metadata-name/connection.json +++ b/packages/composer-common/test/data/id-cards/missing-metadata-name/connection.json @@ -1,4 +1,5 @@ { + "name": "hlfv1", "type": "hlfv1", "orderers": [ { diff --git a/packages/composer-common/test/data/id-cards/missing-metadata/connection.json b/packages/composer-common/test/data/id-cards/missing-metadata/connection.json index 549c63eef9..c77d5ec141 100644 --- a/packages/composer-common/test/data/id-cards/missing-metadata/connection.json +++ b/packages/composer-common/test/data/id-cards/missing-metadata/connection.json @@ -1,4 +1,5 @@ { + "name": "hlfv1", "type": "hlfv1", "orderers": [ { diff --git a/packages/composer-common/test/data/id-cards/valid-with-enrollment/connection.json b/packages/composer-common/test/data/id-cards/valid-with-enrollment/connection.json new file mode 100644 index 0000000000..c77d5ec141 --- /dev/null +++ b/packages/composer-common/test/data/id-cards/valid-with-enrollment/connection.json @@ -0,0 +1,39 @@ +{ + "name": "hlfv1", + "type": "hlfv1", + "orderers": [ + { + "url": "grpcs://", + "cert": "orderer1.crt" + }, + { + "url": "grpcs://", + "cert": "orderer2.crt" + } + ], + "ca": { + "url": "https://", + "name": "", + "trustedRoots": "", + "verify": true + }, + "peers": [ + { + "requestURL": "grpcs://", + "eventURL": "grpcs://", + "cert": "peer1.crt" + }, + { + "requestURL": "grpcs://", + "eventURL": "grpcs://", + "cert": "peer2.crt" + } + ], + "keyValStore": "/YOUR_HOME_DIR/.composer-credentials", + "channel": "composerchannel", + "mspID": "Org1MSP", + "timeout": 300, + "globalcert": "", + "maxSendSize": 10, + "maxRecvSize": 15 +} \ No newline at end of file diff --git a/packages/composer-common/test/data/id-cards/valid-with-enrollment/metadata.json b/packages/composer-common/test/data/id-cards/valid-with-enrollment/metadata.json new file mode 100644 index 0000000000..7bd10f73bc --- /dev/null +++ b/packages/composer-common/test/data/id-cards/valid-with-enrollment/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Conga", + "description": "A valid ID card", + "businessNetwork": "org-acme-biznet", + "image": "images/conga.png", + "enrollmentId": "conga", + "enrollmentSecret": "super-secret-passphrase" +} diff --git a/packages/composer-common/test/data/id-cards/valid/connection.json b/packages/composer-common/test/data/id-cards/valid/connection.json index 549c63eef9..c77d5ec141 100644 --- a/packages/composer-common/test/data/id-cards/valid/connection.json +++ b/packages/composer-common/test/data/id-cards/valid/connection.json @@ -1,4 +1,5 @@ { + "name": "hlfv1", "type": "hlfv1", "orderers": [ { diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-priv b/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-priv deleted file mode 100644 index 1edeb54e3b..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-priv +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgChrXYkGKlYO/Vyit -G7iWx7oYvdDhVZS9FKOUDf9hJzuhRANCAASJpA+8/w8scgjPGJZsvocNPJMT3Y9m -YtavzY9pup/rF7NAocoFEH+oYT9rTO39+92GkJO/7nk3HwWQ0YfocTNZ ------END PRIVATE KEY----- diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-pub b/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-pub deleted file mode 100644 index df88a7f64a..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/credentials/299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef-pub +++ /dev/null @@ -1,4 +0,0 @@ ------BEGIN PUBLIC KEY----- -MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiaQPvP8PLHIIzxiWbL6HDTyTE92P -ZmLWr82Pabqf6xezQKHKBRB/qGE/a0zt/fvdhpCTv+55Nx8FkNGH6HEzWQ== ------END PUBLIC KEY----- diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/PeerAdmin b/packages/composer-common/test/data/id-cards/valid/credentials/PeerAdmin deleted file mode 100644 index 7db3ed06a5..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/credentials/PeerAdmin +++ /dev/null @@ -1 +0,0 @@ -{"name":"PeerAdmin","mspid":"Org1MSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457","identity":{"certificate":"-----BEGIN CERTIFICATE-----\nMIICGjCCAcCgAwIBAgIRANuOnVN+yd/BGyoX7ioEklQwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjI2MTI0OTI2WhcNMjcwNjI0MTI0OTI2\nWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzEfMB0GA1UEAwwWQWRtaW5Ab3JnMS5leGFtcGxlLmNvbTBZ\nMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGu8KxBQ1GkxSTMVoLv7NXiYKWj5t6Dh\nWRTJBHnLkWV7lRUfYaKAKFadSii5M7Z7ZpwD8NS7IsMdPR6Z4EyGgwKjTTBLMA4G\nA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIBmrZau7BIB9\nrRLkwKmqpmSecIaOOr0CF6Mi2J5H4aauMAoGCCqGSM49BAMCA0gAMEUCIQC4sKQ6\nCEgqbTYe48az95W9/hnZ+7DI5eSnWUwV9vCd/gIgS5K6omNJydoFoEpaEIwM97uS\nXVMHPa0iyC497vdNURA=\n-----END CERTIFICATE-----\n"}}} \ No newline at end of file diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/admin b/packages/composer-common/test/data/id-cards/valid/credentials/admin deleted file mode 100644 index 65a81bd84b..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/credentials/admin +++ /dev/null @@ -1 +0,0 @@ -{"name":"admin","mspid":"Org1MSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"299acf40adb20268d13881833a0bed90e43e2276f0ed204e26233f906803b6ef","identity":{"certificate":"-----BEGIN CERTIFICATE-----\nMIIB8TCCAZegAwIBAgIUYiOMoEQLJjv67ouTyKF/AGQwc30wCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNzA3MDIzMTAwWhcNMTgwNzA3MDIz\nMTAwWjAQMQ4wDAYDVQQDEwVhZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBImkD7z/DyxyCM8Ylmy+hw08kxPdj2Zi1q/Nj2m6n+sXs0ChygUQf6hhP2tM7f37\n3YaQk7/ueTcfBZDRh+hxM1mjbDBqMA4GA1UdDwEB/wQEAwICBDAMBgNVHRMBAf8E\nAjAAMB0GA1UdDgQWBBTCXR6ye6azchCpfPqAC2eRoXKgEDArBgNVHSMEJDAigCAZ\nq2WruwSAfa0S5MCpqqZknnCGjjq9AhejItieR+GmrjAKBggqhkjOPQQDAgNIADBF\nAiEA+qTBDKAE/9Hjh0Zn/J4zUgmNwOfhjXKaUKDFWrklbd0CIBIRZRX5z1RDQJAy\nX/LfDmPKGY4uCqTMkUj8ZuuGwqol\n-----END CERTIFICATE-----\n"}}} \ No newline at end of file diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457-priv b/packages/composer-common/test/data/id-cards/valid/credentials/private similarity index 100% rename from packages/composer-common/test/data/id-cards/valid/credentials/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457-priv rename to packages/composer-common/test/data/id-cards/valid/credentials/private diff --git a/packages/composer-common/test/data/id-cards/valid/credentials/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457-pub b/packages/composer-common/test/data/id-cards/valid/credentials/public similarity index 100% rename from packages/composer-common/test/data/id-cards/valid/credentials/114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457-pub rename to packages/composer-common/test/data/id-cards/valid/credentials/public diff --git a/packages/composer-common/test/data/id-cards/valid/images/conga.png b/packages/composer-common/test/data/id-cards/valid/images/conga.png deleted file mode 100644 index 775c1ef889..0000000000 Binary files a/packages/composer-common/test/data/id-cards/valid/images/conga.png and /dev/null differ diff --git a/packages/composer-common/test/data/id-cards/valid/metadata.json b/packages/composer-common/test/data/id-cards/valid/metadata.json index c1658f09b1..4d981bb73d 100644 --- a/packages/composer-common/test/data/id-cards/valid/metadata.json +++ b/packages/composer-common/test/data/id-cards/valid/metadata.json @@ -1,6 +1,6 @@ { - "name" : "com.example.cards.Dan", - "description" : "Dan's Card for Production Network", - "businessNetwork" : "org-acme-biznet", - "image" : "images/conga.png" + "name": "Conga", + "description": "A valid ID card", + "businessNetwork": "org-acme-biznet", + "image": "images/conga.png" } diff --git a/packages/composer-common/test/data/id-cards/valid/tlscerts/ca.crt b/packages/composer-common/test/data/id-cards/valid/tlscerts/ca.crt deleted file mode 100644 index f779b66377..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/tlscerts/ca.crt +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICSDCCAe+gAwIBAgIQEvXT1R9Bjz16NNZ0lRCnyDAKBggqhkjOPQQDAjB2MQsw -CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy -YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxz -Y2Eub3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjYxMjQ5MjZaFw0yNzA2MjQxMjQ5 -MjZaMHYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH -Ew1TYW4gRnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMR8wHQYD -VQQDExZ0bHNjYS5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0D -AQcDQgAEXhfzP6un0RG7Ju3xB2L+Z1N3ti7ZWTUcjylvFIo9WH2kdbd2s2MXJAiq -0iWI64FUa4ZRwld9PXr12opwoaf5Q6NfMF0wDgYDVR0PAQH/BAQDAgGmMA8GA1Ud -JQQIMAYGBFUdJQAwDwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQg7ZoAf+CA940a -9UENvzXO2sl4HOaAjzw1c7dI6w3hQqwwCgYIKoZIzj0EAwIDRwAwRAIgLAHv49O1 -uEF96e1m45g5wOsBUDwFnYWg9iy53tJ815kCIAXL7AvDlNHk2eEGOKVi6UZUOrcP -d0fDafkffCmv86mE ------END CERTIFICATE----- diff --git a/packages/composer-common/test/data/id-cards/valid/tlscerts/server.crt b/packages/composer-common/test/data/id-cards/valid/tlscerts/server.crt deleted file mode 100644 index 30cab191cb..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/tlscerts/server.crt +++ /dev/null @@ -1,14 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICOjCCAeGgAwIBAgIQBJoV3CWCr6nSXQsjv8BgQzAKBggqhkjOPQQDAjB2MQsw -CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy -YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEfMB0GA1UEAxMWdGxz -Y2Eub3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjYxMjQ5MjZaFw0yNzA2MjQxMjQ5 -MjZaMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH -Ew1TYW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZBZG1pbkBvcmcxLmV4YW1wbGUuY29t -MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE3pLUrkpTc/+Dvk9q64SHYpbg0H14 -dDbqWiIHsdcRSKv1GLgW60Rs4WKcRgKj6jAzzt9qf3sNNyiLg6p4z4ROTaNsMGow -DgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAM -BgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIO2aAH/ggPeNGvVBDb81ztrJeBzmgI88 -NXO3SOsN4UKsMAoGCCqGSM49BAMCA0cAMEQCIH7xbUq9DMhy21bXXb3i8dIta/vV -mxLxZfSuu9+GLkZKAiBIRXd31n9LaoI1dgklt+d9A2ogpHX5+euq3k/fnp57qQ== ------END CERTIFICATE----- diff --git a/packages/composer-common/test/data/id-cards/valid/tlscerts/server.key b/packages/composer-common/test/data/id-cards/valid/tlscerts/server.key deleted file mode 100755 index b040bb2cc4..0000000000 --- a/packages/composer-common/test/data/id-cards/valid/tlscerts/server.key +++ /dev/null @@ -1,5 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgPc3M5x+tOTwF+nKp -t+LfeCHjPdzRGAgEF1PxtyApEnahRANCAATektSuSlNz/4O+T2rrhIdiluDQfXh0 -NupaIgex1xFIq/UYuBbrRGzhYpxGAqPqMDPO32p/ew03KIuDqnjPhE5N ------END PRIVATE KEY----- diff --git a/packages/composer-common/test/idcard.js b/packages/composer-common/test/idcard.js index ee4598be27..7c65b61cf2 100644 --- a/packages/composer-common/test/idcard.js +++ b/packages/composer-common/test/idcard.js @@ -91,32 +91,32 @@ describe('IdCard', function() { }); }); - it('should throw error on missing metadata.json', function() { - return readIdCardAsync('missing-metadata').then((readBuffer) => { + it('should throw error on missing name field in connection.json', function() { + return readIdCardAsync('missing-connection-name').then((readBuffer) => { return IdCard.fromArchive(readBuffer).then(function resolved(card) { throw Error('Card loaded without error'); }, function rejected(error) { - error.message.should.include('metadata.json'); + error.message.should.include('name'); }); }); }); - it('should throw error on missing name field in metadata', function() { - return readIdCardAsync('missing-metadata-name').then((readBuffer) => { + it('should throw error on missing metadata.json', function() { + return readIdCardAsync('missing-metadata').then((readBuffer) => { return IdCard.fromArchive(readBuffer).then(function resolved(card) { throw Error('Card loaded without error'); }, function rejected(error) { - error.message.should.include('name'); + error.message.should.include('metadata.json'); }); }); }); - it('should throw error on invalid image field in metadata', function() { - return readIdCardAsync('invalid-metadata-image').then((readBuffer) => { + it('should throw error on missing name field in metadata', function() { + return readIdCardAsync('missing-metadata-name').then((readBuffer) => { return IdCard.fromArchive(readBuffer).then(function resolved(card) { throw Error('Card loaded without error'); }, function rejected(error) { - error.message.should.include('NON_EXISTENT_IMAGE_FILENAME'); + error.message.should.include('name'); }); }); }); @@ -125,45 +125,34 @@ describe('IdCard', function() { return readIdCardAsync('valid').then((readBuffer) => { return IdCard.fromArchive(readBuffer); }).then((card) => { - card.getName().should.equal('com.example.cards.Dan'); - card.getDescription().should.equal('Dan\'s Card for Production Network'); - card.getBusinessNetwork().should.equal('org-acme-biznet'); - card.getImage().should.exist; + card.getName().should.equal('Conga'); + card.getDescription().should.equal('A valid ID card'); + card.getBusinessNetworkName().should.equal('org-acme-biznet'); + should.not.exist(card.getEnrollmentCredentials()); }); }); - it('should load connection details', function() { - return readIdCardAsync('valid').then((readBuffer) => { + it('should return empty string if no business network name defined', function() { + return readIdCardAsync('minimal').then((readBuffer) => { return IdCard.fromArchive(readBuffer); }).then((card) => { - card.getConnection().should.be.an('Object'); + card.getBusinessNetworkName().should.be.empty; }); }); - it('should load an image named in metadata.json', function() { - return readIdCardAsync('valid').then((readBuffer) => { + it('should return empty string if no description defined', function() { + return readIdCardAsync('minimal').then((readBuffer) => { return IdCard.fromArchive(readBuffer); }).then((card) => { - const image = card.getImage(); - image.name.should.be.a('String'); - image.data.should.be.an.instanceof(Buffer); + card.getDescription().should.be.empty; }); }); - it('should refer to an image by short filename', function() { + it('should load connection profile', function() { return readIdCardAsync('valid').then((readBuffer) => { return IdCard.fromArchive(readBuffer); }).then((card) => { - const image = card.getImage(); - image.name.should.equal('conga.png'); - }); - }); - - it('should have an undefined image field if no image specified in metadata.json', function() { - return readIdCardAsync('minimal').then((readBuffer) => { - return IdCard.fromArchive(readBuffer); - }).then((card) => { - should.equal(card.getImage(), undefined); + card.getConnectionProfile().should.be.an('Object'); }); }); @@ -172,20 +161,18 @@ describe('IdCard', function() { return IdCard.fromArchive(readBuffer); }).then((card) => { const credentials = card.getCredentials(); - credentials.should.be.an.instanceof(Map); - credentials.size.should.equal(6); - credentials.get('PeerAdmin').should.be.an.instanceof(Buffer); + credentials.public.should.include('-----BEGIN PUBLIC KEY-----'); + credentials.private.should.include('-----BEGIN PRIVATE KEY-----'); }); }); - it('should load tlscerts', function() { - return readIdCardAsync('valid').then((readBuffer) => { + it('should load enrollment credentials', function() { + return readIdCardAsync('valid-with-enrollment').then((readBuffer) => { return IdCard.fromArchive(readBuffer); }).then((card) => { - const tlscerts = card.getTlsCertificates(); - tlscerts.should.be.an.instanceof(Map); - tlscerts.size.should.equal(3); - tlscerts.get('ca.crt').should.be.an.instanceof(Buffer); + const credentials = card.getEnrollmentCredentials(); + credentials.id.should.equal('conga'); + credentials.secret.should.equal('super-secret-passphrase'); }); });