Skip to content

Commit

Permalink
[FAB-4887] Server creates unused MSP directory
Browse files Browse the repository at this point in the history
Starting the fabric-ca server creates an additional, unused MSP
directory in the location of where the server was started from
and then another one inside the server's home directory. The
first MSP directory described is incorrectly created and no
certificates/keys get stored there.

See [FAB-4887] for reproduction steps

Change-Id: I125dbf2a67c5ddf2a2563d198765115f808fa8ba
Signed-off-by: Saad Karim <skarim@us.ibm.com>
  • Loading branch information
Saad Karim committed Jun 21, 2017
1 parent 82fad13 commit a71e0f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
20 changes: 20 additions & 0 deletions cmd/fabric-ca-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,26 @@ func TestMultiCA(t *testing.T) {
}
}

func TestMSPDirectoryCreation(t *testing.T) {
os.RemoveAll("mspConfigTest")
defer os.RemoveAll("mspConfigTest")
srv := lib.TestGetServer(serverPort, "mspConfigTest", "", -1, t)

err := srv.Start()
if err != nil {
t.Fatal("Failed to start server:", err)
}

if util.FileExists("msp") {
t.Errorf("MSP directory should not exist at the local directory")
}

err = srv.Stop()
if err != nil {
t.Errorf("Server stop failed: %s", err)
}
}

func TestCleanUp(t *testing.T) {
os.Remove("../../testdata/ca-cert.pem")
os.Remove("../../testdata/ca-key.pem")
Expand Down
7 changes: 6 additions & 1 deletion lib/client_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/hyperledger/fabric-ca/api"
"github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
cspsigner "github.com/hyperledger/fabric/bccsp/signer"
"github.com/hyperledger/fabric/bccsp/utils"
)
Expand Down Expand Up @@ -216,7 +217,11 @@ func testImpersonation(id *Identity, t *testing.T) {
if err != nil {
t.Fatalf("Failed to convert admin's cert: %s", err)
}
csp := util.GetDefaultBCCSP()
bc := &factory.FactoryOpts{}
csp, err := util.InitBCCSP(&bc, "", path.Join(testTLSClientAuthDir, "client"))
if err != nil {
t.Fatalf("Failed to initialize BCCSP: %s", err)
}
privateKey, err := csp.KeyGen(&bccsp.ECDSAKeyGenOpts{Temporary: false})
if err != nil {
t.Fatalf("Failed generating ECDSA key [%s]", err)
Expand Down
12 changes: 6 additions & 6 deletions util/csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GetDefaultBCCSP() bccsp.BCCSP {

// InitBCCSP initializes BCCSP
func InitBCCSP(optsPtr **factory.FactoryOpts, mspDir, homeDir string) (bccsp.BCCSP, error) {
err := ConfigureBCCSP(optsPtr, mspDir)
err := ConfigureBCCSP(optsPtr, mspDir, homeDir)
if err != nil {
return nil, err
}
Expand All @@ -63,7 +63,7 @@ func InitBCCSP(optsPtr **factory.FactoryOpts, mspDir, homeDir string) (bccsp.BCC
}

// ConfigureBCCSP configures BCCSP, using
func ConfigureBCCSP(optsPtr **factory.FactoryOpts, mspDir string) error {
func ConfigureBCCSP(optsPtr **factory.FactoryOpts, mspDir, homeDir string) error {
var err error
if optsPtr == nil {
return errors.New("nil argument not allowed")
Expand Down Expand Up @@ -95,6 +95,10 @@ func ConfigureBCCSP(optsPtr **factory.FactoryOpts, mspDir string) error {
opts.SwOpts.FileKeystore.KeyStorePath = path.Join("msp", "keystore")
}
}
err = makeFileNamesAbsolute(opts, homeDir)
if err != nil {
return fmt.Errorf("Failed to make BCCSP files absolute: %s", err)
}
log.Debugf("Initializing BCCSP: %+v", opts)
if opts.SwOpts != nil {
log.Debugf("Initializing BCCSP with software options %+v", opts.SwOpts)
Expand All @@ -114,10 +118,6 @@ func ConfigureBCCSP(optsPtr **factory.FactoryOpts, mspDir string) error {
// GetBCCSP returns BCCSP
func GetBCCSP(opts *factory.FactoryOpts, homeDir string) (bccsp.BCCSP, error) {

err := makeFileNamesAbsolute(opts, homeDir)
if err != nil {
return nil, fmt.Errorf("Failed to make BCCSP files absolute: %s", err)
}
// Get BCCSP from the opts
csp, err := factory.GetBCCSPFromOpts(opts)
if err != nil {
Expand Down

0 comments on commit a71e0f5

Please sign in to comment.