33 lines
702 B
Go
33 lines
702 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestSaveLoadSecureConfig(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "nested", "config.json")
|
|
cfg := &Config{ClientID: "id", ClientSecret: "secret"}
|
|
if err := Save(path, cfg); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
loaded, err := Load(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if loaded.Root != "/" || loaded.UserAgent != DefaultUserAgent || loaded.UploadParts != 3 {
|
|
t.Fatalf("defaults not applied: %+v", loaded)
|
|
}
|
|
if runtime.GOOS != "windows" {
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if info.Mode().Perm() != 0o600 {
|
|
t.Fatalf("config permissions = %o", info.Mode().Perm())
|
|
}
|
|
}
|
|
}
|