-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runs against the result of `npm pack` to give some confidence that the published module will work. Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
- Loading branch information
1 parent
35853fa
commit fde20af
Showing
18 changed files
with
329 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
dist | ||
*.tsbuildinfo | ||
coverage | ||
*.tgz |
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 |
---|---|---|
|
@@ -6,3 +6,6 @@ test | |
jest.config.js | ||
coverage | ||
azure-pipelines.yml | ||
scenario | ||
*.tgz | ||
*.sh |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverage: true | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
collectCoverage: true, | ||
testPathIgnorePatterns: [ | ||
"/node_modules/", | ||
"/scenario/" | ||
] | ||
}; |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) | ||
|
||
createPackFile() { | ||
local packFile | ||
packFile=$( npm pack ) | ||
targetFile=$( echo "${packFile}" | sed -e 's/[^-]*\.tgz$/dev.tgz/' ) | ||
mv "${packFile}" "${targetFile}" | ||
} | ||
|
||
scenarioTest() { | ||
npm install | ||
npm test | ||
} | ||
|
||
( cd "${DIR}" && createPackFile ) | ||
( cd "${DIR}/scenario" && scenarioTest ) |
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,2 @@ | ||
package-lock.json | ||
|
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,5 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
rootDir: "./test" | ||
}; |
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,18 @@ | ||
{ | ||
"name": "scenario", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"fabric-network": "^2.0.0-beta.3", | ||
"fabric-wallet-migration": "file:../fabric-wallet-migration-dev.tgz", | ||
"jest": "^25.1.0", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
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,96 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WalletStores } from "fabric-wallet-migration"; | ||
import { Wallet, Wallets, Identity, X509Identity } from "fabric-network"; | ||
|
||
import fs = require("fs"); | ||
import os = require("os"); | ||
import path = require("path"); | ||
import util = require("util"); | ||
import _rimraf = require("rimraf"); | ||
const rimraf = util.promisify(_rimraf); | ||
|
||
const oldWalletPath = path.resolve(__dirname, "..", "wallet"); | ||
|
||
async function createTempDir() { | ||
const prefix = path.join(os.tmpdir(), "wallet-"); | ||
return await fs.promises.mkdtemp(prefix); | ||
} | ||
|
||
describe("Wallet migration", () => { | ||
let walletPath: string; | ||
let wallet: Wallet; | ||
|
||
beforeAll(async () => { | ||
walletPath = await createTempDir(); | ||
await migrate(); | ||
wallet = await Wallets.newFileSystemWallet(walletPath); | ||
}); | ||
|
||
afterAll(async () => { | ||
await rimraf(walletPath); | ||
}); | ||
|
||
async function migrate() { | ||
const walletStore = WalletStores.newFileSystemWalletStore(oldWalletPath); | ||
const oldWallet = new Wallet(walletStore); | ||
|
||
const newWallet = await Wallets.newFileSystemWallet(walletPath); | ||
|
||
const migratedLabels: string[] = []; | ||
const identityLabels = await oldWallet.list(); | ||
for (const label of identityLabels) { | ||
const identity = await oldWallet.get(label); | ||
if (identity) { | ||
await newWallet.put(label, identity); | ||
migratedLabels.push(label); | ||
} | ||
} | ||
|
||
return migratedLabels; | ||
} | ||
|
||
async function getAll() { | ||
const identities = new Map<string, Identity>(); | ||
|
||
const labels = await wallet.list(); | ||
for (const label of labels) { | ||
const identity = await wallet.get(label); | ||
if (identity) { | ||
identities.set(label, identity); | ||
} | ||
} | ||
|
||
return identities; | ||
} | ||
|
||
it("has expected labels", async () => { | ||
const labels = await wallet.list(); | ||
expect(labels).toEqual(["user1", "user2"]); | ||
}); | ||
|
||
it("contains X.509 identities", async () => { | ||
const identities = await getAll(); | ||
identities.forEach((identity) => { | ||
expect(identity.type).toEqual("X.509"); | ||
}); | ||
}); | ||
|
||
it("identities have non-empty certificates", async () => { | ||
const identities = await getAll(); | ||
identities.forEach((identity) => { | ||
const x509Identity = identity as X509Identity; | ||
expect(x509Identity.credentials.certificate).toMatch(/.+/); | ||
}); | ||
}); | ||
|
||
it("identities have non-empty private keys", async () => { | ||
const identities = await getAll(); | ||
identities.forEach((identity) => { | ||
const x509Identity = identity as X509Identity; | ||
expect(x509Identity.credentials.privateKey).toMatch(/.+/); | ||
}); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
scenario/wallet/user1/8ee3f5bf29b8a30a038c38c5fc2c825e3b9823582ddebc4b3c39ee9cd493712c-priv
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,5 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgyzr9w9VY9qI3koXq | ||
Ovxz4chsz16obqzKdRG0cKUpvUyhRANCAAQ3HCLhuIk/ZKOUrTJblTfTbPrYEcEp | ||
GiHtmkUcswGiEIk0Z8kzp4zgMKPvFoOjukht4dhk/+eDMFAvLa12ER41 | ||
-----END PRIVATE KEY----- |
4 changes: 4 additions & 0 deletions
4
scenario/wallet/user1/8ee3f5bf29b8a30a038c38c5fc2c825e3b9823582ddebc4b3c39ee9cd493712c-pub
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,4 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENxwi4biJP2SjlK0yW5U302z62BHB | ||
KRoh7ZpFHLMBohCJNGfJM6eM4DCj7xaDo7pIbeHYZP/ngzBQLy2tdhEeNQ== | ||
-----END PUBLIC KEY----- |
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 @@ | ||
{"name":"user1","mspid":"Org1MSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"8ee3f5bf29b8a30a038c38c5fc2c825e3b9823582ddebc4b3c39ee9cd493712c","identity":{"certificate":"-----BEGIN CERTIFICATE-----\nMIICWTCCAf+gAwIBAgIUSKAUBU+/6sqUHKjxbbH/ZvkkgAUwCgYIKoZIzj0EAwIw\nfzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK\nBgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMjAwMjI0MTUzNzAw\nWhcNMjEwMjIzMTU0MjAwWjBdMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg\nQ2Fyb2xpbmExFDASBgNVBAoTC0h5cGVybGVkZ2VyMQ8wDQYDVQQLEwZjbGllbnQx\nDjAMBgNVBAMTBWFkbWluMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENxwi4biJ\nP2SjlK0yW5U302z62BHBKRoh7ZpFHLMBohCJNGfJM6eM4DCj7xaDo7pIbeHYZP/n\ngzBQLy2tdhEeNaN7MHkwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwHQYD\nVR0OBBYEFCBh9T6woSaKdCYc3xp0b2fHqGDaMB8GA1UdIwQYMBaAFBdnQj2qnoI/\nxMUdn1vDmdG1nEgQMBkGA1UdEQQSMBCCDmRvY2tlci1kZXNrdG9wMAoGCCqGSM49\nBAMCA0gAMEUCIQDvXlen/JmnziTlKKhVu/zpIk+LbtdsJv6xlf4AXzjfSgIgRQ94\nurE2nabbhBB8QDIyI7+vnXLNPbT7OneAefxnUI4=\n-----END CERTIFICATE-----"}}} |
5 changes: 5 additions & 0 deletions
5
scenario/wallet/user2/00d1b0fa0256847ecc75b3ff087e00e54008883449b7411a05ad7882ee1f1aab-priv
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,5 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgvUT1OcbWZO8Mu9Il | ||
PGMhpFMsT63gGKIbN6EH0M5aw3OhRANCAARnkEt2rIASwyCYBFlDs8xT27v7YMoq | ||
ktBB435jO3AgtOLsvcQjnIMHTkEHVU4M4NTpKmCVT8Yy/zS9B21AcWhN | ||
-----END PRIVATE KEY----- |
4 changes: 4 additions & 0 deletions
4
scenario/wallet/user2/00d1b0fa0256847ecc75b3ff087e00e54008883449b7411a05ad7882ee1f1aab-pub
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,4 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZ5BLdqyAEsMgmARZQ7PMU9u7+2DK | ||
KpLQQeN+YztwILTi7L3EI5yDB05BB1VODODU6SpglU/GMv80vQdtQHFoTQ== | ||
-----END PUBLIC KEY----- |
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 @@ | ||
{"name":"user2","mspid":"Org1MSP","roles":null,"affiliation":"","enrollmentSecret":"","enrollment":{"signingIdentity":"00d1b0fa0256847ecc75b3ff087e00e54008883449b7411a05ad7882ee1f1aab","identity":{"certificate":"-----BEGIN CERTIFICATE-----\nMIICvDCCAmOgAwIBAgIUE/PYgz1FszgQyZdJMTD7WVotlZ4wCgYIKoZIzj0EAwIw\nfzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK\nBgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMjAwMjI0MTUzNzAw\nWhcNMjEwMjIzMTU0MjAwWjBhMQswCQYDVQQGEwJVUzEXMBUGA1UECBMOTm9ydGgg\nQ2Fyb2xpbmExFDASBgNVBAoTC0h5cGVybGVkZ2VyMQ8wDQYDVQQLEwZjbGllbnQx\nEjAQBgNVBAMTCW9yZzFBZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGeQ\nS3asgBLDIJgEWUOzzFPbu/tgyiqS0EHjfmM7cCC04uy9xCOcgwdOQQdVTgzg1Okq\nYJVPxjL/NL0HbUBxaE2jgdowgdcwDgYDVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQC\nMAAwHQYDVR0OBBYEFPoIUbE0sNAmYKoUxiRCxYOAG1bJMB8GA1UdIwQYMBaAFBdn\nQj2qnoI/xMUdn1vDmdG1nEgQMBkGA1UdEQQSMBCCDmRvY2tlci1kZXNrdG9wMFwG\nCCoDBAUGBwgBBFB7ImF0dHJzIjp7ImhmLkFmZmlsaWF0aW9uIjoiIiwiaGYuRW5y\nb2xsbWVudElEIjoib3JnMUFkbWluIiwiaGYuVHlwZSI6ImNsaWVudCJ9fTAKBggq\nhkjOPQQDAgNHADBEAiAgZFVt/vMETbX6SFvbwCLBm9EhmxnuJ1QnXwD3xbFTpwIg\nK4UQSGTVbujzmp6tvE9fClhKOkMKaGBzoWMU+32ZqtA=\n-----END CERTIFICATE-----"}}} |
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