Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions utils/coreutils/coreconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var (
ApplicationKey = "JFROG_CLI_APPLICATION_KEY"
SigningKey = "JFROG_CLI_SIGNING_KEY"
KeyAlias = "JFROG_CLI_KEY_ALIAS"
CertsDir = "JFROG_CLI_CERTS_DIR"
//#nosec G101
EncryptionKey = "JFROG_CLI_ENCRYPTION_KEY"
// For CI runs
Expand Down
11 changes: 11 additions & 0 deletions utils/coreutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ func GetJfrogSecurityDir() (string, error) {
}

func GetJfrogCertsDir() (string, error) {
if dir := os.Getenv(CertsDir); dir != "" {
dir = filepath.Clean(dir)

absoluteDir, err := filepath.Abs(dir)
if err != nil {
return "", errorutils.CheckError(err)
}

return absoluteDir, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to normalize and validate the system paths

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a filepath normalization to the certsDir, but validation doesn't seem to fit here.
We do not validate the JFrog Home Dir either

func GetJfrogHomeDir() (string, error) {
if os.Getenv(HomeDir) != "" {
return os.Getenv(HomeDir), nil
}

Please tell me if i should add validation nonetheless

securityDir, err := GetJfrogSecurityDir()
if err != nil {
return "", err
Expand Down
45 changes: 45 additions & 0 deletions utils/coreutils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,48 @@ func TestGetMaskedCommandString(t *testing.T) {
"pip -i ***@someurl.com/repo --access-token=***",
GetMaskedCommandString(exec.Command("pip", "-i", "https://user:pass@someurl.com/repo", "--access-token=123")))
}

func TestGetJfrogCertsDirFromEnv(t *testing.T) {
certsDirPath, err := filepath.Abs(filepath.Join("/", "custom", "certs"))
assert.NoError(t, err)

t.Setenv(CertsDir, certsDirPath)
defer func() {
assert.NoError(t, os.Unsetenv(CertsDir))
}()

certsDir, err := GetJfrogCertsDir()

assert.NoError(t, err)
assert.Equal(t, certsDirPath, certsDir)
}

func TestGetJfrogCertsDirFallsBackToHomeDir(t *testing.T) {
certsDirPath, err := filepath.Abs(filepath.Join("tmp", "jfrog"))
assert.NoError(t, err)

t.Setenv(HomeDir, certsDirPath)
defer func() {
assert.NoError(t, os.Unsetenv(HomeDir))
}()

certsDir, err := GetJfrogCertsDir()

assert.NoError(t, err)
assert.Equal(t, filepath.Join(certsDirPath, JfrogSecurityDirName, JfrogCertsDirName), certsDir)
}

func TestGetJfrogCertsDirNormalizesPath(t *testing.T) {
t.Setenv(CertsDir, filepath.Join("test", "..", "custom", "certs"))
defer func() {
assert.NoError(t, os.Unsetenv(CertsDir))
}()

expectedDir, err := filepath.Abs(filepath.Join("custom", "certs"))
assert.NoError(t, err)

certsDir, err := GetJfrogCertsDir()

assert.NoError(t, err)
assert.Equal(t, expectedDir, certsDir)
}
Loading