Skip to content

Commit

Permalink
Merge "[FAB-10175] Ginkgo runner for idemixgen"
Browse files Browse the repository at this point in the history
  • Loading branch information
hacera-jonathan authored and Gerrit Code Review committed May 19, 2018
2 parents 6118e7e + 54237e4 commit 29e4b65
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 3 deletions.
6 changes: 3 additions & 3 deletions common/tools/idemixgen/idemixgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func writeFile(path string, contents []byte) {

// readIssuerKey reads the issuer key from the current directory
func readIssuerKey() *idemix.IssuerKey {
path := filepath.Join(IdemixDirIssuer, IdemixConfigIssuerSecretKey)
path := filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigIssuerSecretKey)
isk, err := ioutil.ReadFile(path)
if err != nil {
handleError(errors.Wrapf(err, "failed to open issuer secret key file: %s", path))
}
path = filepath.Join(IdemixDirIssuer, msp.IdemixConfigFileIssuerPublicKey)
path = filepath.Join(*outputDir, IdemixDirIssuer, msp.IdemixConfigFileIssuerPublicKey)
ipkBytes, err := ioutil.ReadFile(path)
if err != nil {
handleError(errors.Wrapf(err, "failed to open issuer public key file: %s", path))
Expand All @@ -129,7 +129,7 @@ func readIssuerKey() *idemix.IssuerKey {
}

func readRevocationKey() *ecdsa.PrivateKey {
path := filepath.Join(IdemixDirIssuer, IdemixConfigRevocationKey)
path := filepath.Join(*outputDir, IdemixDirIssuer, IdemixConfigRevocationKey)
keyBytes, err := ioutil.ReadFile(path)
if err != nil {
handleError(errors.Wrapf(err, "failed to open revocation secret key file: %s", path))
Expand Down
61 changes: 61 additions & 0 deletions integration/runner/idemixgen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package runner

import (
"os/exec"

"github.com/tedsuo/ifrit/ginkgomon"
)

// Idemixgen creates runners that call idemixgen functions.
type Idemixgen struct {
// Location of the idemixgen executable
Path string
// Output directory
Output string
// Enrollment ID for the default signer
EnrollID string
// The organizational unit for the default signer
OrgUnit string
// Flag for making the default signer an admin
IsAdmin bool
// Handle used to revoke the default signer
RevocationHandle int
}

// CAKeyGen uses idemixgen to generate CA key material for an IdeMix MSP.
func (c *Idemixgen) CAKeyGen(extraArgs ...string) *ginkgomon.Runner {
return ginkgomon.New(ginkgomon.Config{
Name: "idemix ca-keygen",
AnsiColorCode: "38m",
Command: exec.Command(
c.Path,
append([]string{
"ca-keygen",
"--output", c.Output,
}, extraArgs...)...,
),
})
}

// SignerConfig uses idemixgen to generate a signer for an IdeMix MSP.
func (c *Idemixgen) SignerConfig(extraArgs ...string) *ginkgomon.Runner {
return ginkgomon.New(ginkgomon.Config{
Name: "idemix signerconfig",
AnsiColorCode: "38m",
Command: exec.Command(
c.Path,
append([]string{
"signerconfig",
"-e", c.EnrollID,
"-u", c.OrgUnit,
"--output", c.Output,
}, extraArgs...)...,
),
})
}
78 changes: 78 additions & 0 deletions integration/runner/idemixgen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package runner_test

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/hyperledger/fabric/integration/runner"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/tedsuo/ifrit"
)

var _ = Describe("Idemixgen", func() {
var idemixgen *runner.Idemixgen
var tempDir string
var err error
tempDir, err = ioutil.TempDir("", "idemix")
if err != nil {
Fail("Failed to create test directory")
}

BeforeEach(func() {
idemixgen = &runner.Idemixgen{
Path: components.Paths["idemixgen"],
EnrollID: "IdeMixUser1",
OrgUnit: "IdeMixOU",
Output: tempDir,
}
})

It("creates a runner that calls idemixgen ca-keygen", func() {
igRunner := idemixgen.CAKeyGen()
process := ifrit.Invoke(igRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))

Expect(filepath.Join(tempDir, "ca")).To(BeADirectory())
Expect(filepath.Join(tempDir, "msp")).To(BeADirectory())
})

Context("when idemixgen ca-keygen fails", func() {
It("returns an error", func() {
igRunner := idemixgen.CAKeyGen("bogus")
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
})
})

It("creates a runner that calls idemixgen signerconfig", func() {
igRunner := idemixgen.SignerConfig()
process := ifrit.Invoke(igRunner)
Eventually(process.Ready()).Should(BeClosed())
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(igRunner.ExitCode()).To(Equal(0))

Expect(filepath.Join(tempDir, "user")).To(BeADirectory())
})

Context("when idemixgen signerconfig fails", func() {
It("returns an error", func() {
igRunner := idemixgen.SignerConfig("bogus")
process := ifrit.Invoke(igRunner)
Eventually(process.Wait()).Should(Receive(HaveOccurred()))
})
})

// cleanup
os.RemoveAll(tempDir)
})
10 changes: 10 additions & 0 deletions integration/world/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (c *Components) Build(args ...string) {
Expect(err).NotTo(HaveOccurred())
c.Paths["cryptogen"] = cryptogen

idemixgen, err := gexec.Build("github.com/hyperledger/fabric/common/tools/idemixgen", args...)
Expect(err).NotTo(HaveOccurred())
c.Paths["idemixgen"] = idemixgen

configtxgen, err := gexec.Build("github.com/hyperledger/fabric/common/tools/configtxgen", args...)
Expect(err).NotTo(HaveOccurred())
c.Paths["configtxgen"] = configtxgen
Expand All @@ -55,6 +59,12 @@ func (c *Components) Cryptogen() *runner.Cryptogen {
}
}

func (c *Components) Idemixgen() *runner.Idemixgen {
return &runner.Idemixgen{
Path: c.Paths["idemixgen"],
}
}

func (c *Components) Configtxgen() *runner.Configtxgen {
return &runner.Configtxgen{
Path: c.Paths["configtxgen"],
Expand Down
1 change: 1 addition & 0 deletions integration/world/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type World struct {
PeerOrgs []PeerOrgConfig
Profiles map[string]localconfig.Profile
Cryptogen runner.Cryptogen
Idemixgen runner.Idemixgen
Deployment Deployment

LocalStoppers []Stopper
Expand Down

0 comments on commit 29e4b65

Please sign in to comment.