Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

box: fix ~ and environment variables not being expanded in box_config_file

Nick Craig-Wood4b0029e1e7da
diff --git a/backend/box/box.go b/backend/box/box.go
index 7ad816ceb..d37e95fb5 100644
--- a/backend/box/box.go
+++ b/backend/box/box.go
@@ -223,7 +223,7 @@ func getBoxConfig(m configmap.Mapper) (boxConfig *api.ConfigJSON, err error) {
if configFileCredentials == "" {
configFile, _ := m.Get("box_config_file")
- configFileBytes, err = os.ReadFile(configFile)
+ configFileBytes, err = os.ReadFile(env.ShellExpand(configFile))
if err != nil {
return nil, fmt.Errorf("box: failed to read Box config: %w", err)
}
diff --git a/backend/box/box_internal_test.go b/backend/box/box_internal_test.go
new file mode 100644
index 000000000..b4eb4c1ed
--- /dev/null
+++ b/backend/box/box_internal_test.go
@@ -0,0 +1,24 @@
+package box
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/rclone/rclone/fs/config/configmap"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+// Test box_config_file has ~ and environment variables expanded
+func TestGetBoxConfigShellExpand(t *testing.T) {
+ dir := t.TempDir()
+ require.NoError(t, os.WriteFile(filepath.Join(dir, "config.json"), []byte(`{"enterpriseID":"enterprise-id"}`), 0600))
+ t.Setenv("RCLONE_TEST_BOX_CONFIG_DIR", dir)
+ m := configmap.Simple{
+ "box_config_file": "$RCLONE_TEST_BOX_CONFIG_DIR/config.json",
+ }
+ boxConfig, err := getBoxConfig(m)
+ require.NoError(t, err)
+ assert.Equal(t, "enterprise-id", boxConfig.EnterpriseID)
+}