| 1 | package fsrepo |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "runtime" |
| 6 | "testing" |
| 7 | |
| 8 | config "github.com/ipfs/kubo/config" |
| 9 | ) |
| 10 | |
| 11 | func TestConfig(t *testing.T) { |
| 12 | const filename = ".ipfsconfig" |
| 13 | cfgWritten := new(config.Config) |
| 14 | cfgWritten.Identity.PeerID = "faketest" |
| 15 | |
| 16 | err := WriteConfigFile(filename, cfgWritten) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | cfgRead, err := Load(filename) |
| 21 | if err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if cfgWritten.Identity.PeerID != cfgRead.Identity.PeerID { |
| 25 | t.Fatal() |
| 26 | } |
| 27 | st, err := os.Stat(filename) |
| 28 | if err != nil { |
| 29 | t.Fatalf("cannot stat config file: %v", err) |
| 30 | } |
| 31 | |
| 32 | if runtime.GOOS != "windows" { // see https://golang.org/src/os/types_windows.go |
| 33 | if g := st.Mode().Perm(); g&0o117 != 0 { |
| 34 | t.Fatalf("config file should not be executable or accessible to world: %v", g) |
| 35 | } |
| 36 | } |
| 37 | } |