Skip to content

Commit

Permalink
Client home has incorrect path when env vars set
Browse files Browse the repository at this point in the history
If you specify either FABRIC_CA_CLIENT_HOME or FABRIC_CA_HOME
environment variables it will create a hidden folder for client home
(.fabric-ca-client). The hidden folder should only get created when no
location for the client home directory has been specified.

https://jira.hyperledger.org/browse/FAB-2796

Change-Id: I776a750cca7733d7ee71310924e93903132e8401
Signed-off-by: Saad Karim <[email protected]>
  • Loading branch information
Saad Karim committed Mar 15, 2017
1 parent 8d26cf9 commit 9132e6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
9 changes: 5 additions & 4 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,17 @@ func GetDefaultConfigFile(cmdName string) string {

var fname = fmt.Sprintf("%s-config.yaml", cmdName)
// First check home env variables
home := "."
envs := []string{"FABRIC_CA_CLIENT_HOME", "FABRIC_CA_HOME", "CA_CFG_PATH", "HOME"}
var home string
envs := []string{"FABRIC_CA_CLIENT_HOME", "FABRIC_CA_HOME", "CA_CFG_PATH"}
for _, env := range envs {
envVal := os.Getenv(env)
if envVal != "" {
home = envVal
break
return path.Join(home, fname)
}
}
return path.Join(home, ".fabric-ca-client", fname)

return path.Join(os.Getenv("HOME"), ".fabric-ca-client", fname)
}

// GetX509CertificateFromPEM converts a PEM buffer to an X509 Certificate
Expand Down
31 changes: 29 additions & 2 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,45 @@ func TestCreateHome(t *testing.T) {
func TestGetDefaultConfigFile(t *testing.T) {
os.Unsetenv("FABRIC_CA_HOME")
os.Unsetenv("FABRIC_CA_CLIENT_HOME")
os.Unsetenv("FABRIC_CA_SERVER_HOME")

const clientConfig = "fabric-ca-client-config.yaml"
const serverConfig = "fabric-ca-server-config.yaml"

os.Setenv("HOME", "/tmp")

expected := filepath.Join("/tmp", ".fabric-ca-client/fabric-ca-client-config.yaml")
expected := filepath.Join("/tmp/.fabric-ca-client/", clientConfig)
real := GetDefaultConfigFile("fabric-ca-client")
if real != expected {
t.Errorf("Incorrect default config path retrieved; expected %s but found %s",
expected, real)
}

os.Setenv("FABRIC_CA_HOME", "/tmp")
expected = filepath.Join("/tmp", "fabric-ca-server-config.yaml")
expected = filepath.Join("/tmp", clientConfig)
real = GetDefaultConfigFile("fabric-ca-client")
if real != expected {
t.Errorf("Incorrect default config path retrieved; expected %s but found %s",
expected, real)
}

expected = filepath.Join("/tmp", serverConfig)
real = GetDefaultConfigFile("fabric-ca-server")
if real != expected {
t.Errorf("Incorrect default config path retrieved; expected %s but found %s",
expected, real)
}

os.Setenv("FABRIC_CA_CLIENT_HOME", "/tmp/client")
expected = filepath.Join("/tmp/client", clientConfig)
real = GetDefaultConfigFile("fabric-ca-client")
if real != expected {
t.Errorf("Incorrect default config path retrieved; expected %s but found %s",
expected, real)
}

os.Setenv("FABRIC_CA_SERVER_HOME", "/tmp/server")
expected = filepath.Join("/tmp/server", serverConfig)
real = GetDefaultConfigFile("fabric-ca-server")
if real != expected {
t.Errorf("Incorrect default config path retrieved; expected %s but found %s",
Expand Down

0 comments on commit 9132e6d

Please sign in to comment.