config_test.go 755 B

12345678910111213141516171819202122232425262728
  1. package config
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. )
  9. func TestFWHPasswordsAreMD5Encoded(t *testing.T) {
  10. path := filepath.Join(t.TempDir(), "config.env")
  11. if err := os.WriteFile(path, []byte("FWH_PASSWORD=plain-password\nFWH_TEST_PASSWORD=test-password\n"), 0600); err != nil {
  12. t.Fatal(err)
  13. }
  14. cfg, err := LoadConfig(path)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. productionHash := md5.Sum([]byte("plain-password"))
  19. if cfg.FwhApi.FwhPassword != hex.EncodeToString(productionHash[:]) {
  20. t.Fatalf("production password was not MD5 encoded")
  21. }
  22. testHash := md5.Sum([]byte("test-password"))
  23. if cfg.FwhTestApi.FwhPassword != hex.EncodeToString(testHash[:]) {
  24. t.Fatalf("test environment password hashing changed")
  25. }
  26. }