Scrub example config of real credentials and internal hosts #190
+5
-5
@@ -257,16 +257,16 @@ exclude:
|
||||
|
||||
# Storage URL - use either this OR the s3 section below
|
||||
# Supports: s3://bucket/prefix, file:///path, rclone://remote/path
|
||||
storage_url: "rclone://las1stor1//srv/pool.2024.04/backups/heraklion"
|
||||
storage_url: "rclone://myremote/path/to/backups"
|
||||
|
||||
# S3-compatible storage configuration
|
||||
#s3:
|
||||
# # S3-compatible endpoint URL
|
||||
# # Examples: https://s3.amazonaws.com, https://storage.googleapis.com
|
||||
# endpoint: http://10.100.205.122:8333
|
||||
# endpoint: https://s3.example.com
|
||||
#
|
||||
# # Bucket name where backups will be stored
|
||||
# bucket: testbucket
|
||||
# bucket: mybucket
|
||||
#
|
||||
# # Prefix (folder) within the bucket for this host's backups
|
||||
# # Useful for organizing backups from multiple hosts
|
||||
@@ -274,8 +274,8 @@ storage_url: "rclone://las1stor1//srv/pool.2024.04/backups/heraklion"
|
||||
# #prefix: "hosts/myserver/"
|
||||
#
|
||||
# # S3 access credentials
|
||||
# access_key_id: Z9GT22M9YFU08WRMC5D4
|
||||
# secret_access_key: Pi0tPKjFbN4rZlRhcA4zBtEkib04yy2WcIzI+AXk
|
||||
# access_key_id: YOUR_ACCESS_KEY
|
||||
# secret_access_key: YOUR_SECRET_KEY
|
||||
#
|
||||
# # S3 region
|
||||
# # Default: us-east-1
|
||||
|
||||
@@ -87,6 +87,48 @@ func TestConfigLoad(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestExampleConfigIsScrubbedAndLoads checks that the shipped
|
||||
// config.example.yml carries only neutral placeholders (no real credentials,
|
||||
// private addresses, or internal host names) and still parses.
|
||||
func TestExampleConfigIsScrubbedAndLoads(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
examplePath := filepath.Join("..", "..", "config.example.yml")
|
||||
|
||||
cfg, err := Load(examplePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load config.example.yml: %v", err)
|
||||
}
|
||||
|
||||
if cfg.StorageURL != "rclone://myremote/path/to/backups" {
|
||||
t.Errorf("Expected neutral storage_url, got '%s'", cfg.StorageURL)
|
||||
}
|
||||
|
||||
//nolint:gosec // G304: examplePath is a fixed in-repo path, not user input
|
||||
raw, err := os.ReadFile(examplePath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read config.example.yml: %v", err)
|
||||
}
|
||||
|
||||
text := string(raw)
|
||||
|
||||
wantSubstrings := []string{
|
||||
"YOUR_ACCESS_KEY",
|
||||
"YOUR_SECRET_KEY",
|
||||
"endpoint: https://",
|
||||
}
|
||||
for _, want := range wantSubstrings {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Errorf("Expected config.example.yml to contain %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
// A raw "http://" scheme would mean a plaintext, likely private endpoint.
|
||||
if strings.Contains(text, "http://") {
|
||||
t.Error("config.example.yml should not contain an http:// endpoint")
|
||||
}
|
||||
}
|
||||
|
||||
// TestConfigFromEnv tests loading config path from environment variable
|
||||
func TestConfigFromEnv(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
Reference in New Issue
Block a user