| 1 |
package server_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/stretchr/testify/assert" |
| 5 |
"heckel.io/ntfy/v2/server" |
| 6 |
"heckel.io/ntfy/v2/user" |
| 7 |
"testing" |
| 8 |
) |
| 9 |
|
| 10 |
func TestConfig_New(t *testing.T) { |
| 11 |
c := server.NewConfig() |
| 12 |
assert.Equal(t, ":80", c.ListenHTTP) |
| 13 |
assert.Equal(t, server.DefaultKeepaliveInterval, c.KeepaliveInterval) |
| 14 |
} |
| 15 |
|
| 16 |
func TestConfig_HashExcludesSecrets(t *testing.T) { |
| 17 |
// The config hash is served to browsers (ConfigHash, for webapp change detection), so |
| 18 |
// secret material must not feed it: a weak secret would otherwise be offline-brute-forceable |
| 19 |
// against a publicly visible hash. |
| 20 |
conf1 := server.NewConfig() |
| 21 |
conf2 := server.NewConfig() |
| 22 |
conf2.StripeSecretKey = "sk_live_topsecret" |
| 23 |
conf2.StripeWebhookKey = "whsec_topsecret" |
| 24 |
conf2.TwilioAuthToken = "twilio-auth-token" |
| 25 |
conf2.UpstreamAccessToken = "tk_upstream" |
| 26 |
conf2.WebPushPrivateKey = "web-push-private-key" |
| 27 |
conf2.SMTPSenderPass = "hunter2" |
| 28 |
conf2.AuthUsers = []*user.User{{Name: "phil", Hash: "$2a$10$somebcrypthash"}} |
| 29 |
conf2.AuthTokens = map[string][]*user.Token{"phil": {{Value: "tk_secrettoken"}}} |
| 30 |
assert.Equal(t, conf1.Hash(), conf2.Hash()) |
| 31 |
// Non-secret fields must still change the hash |
| 32 |
conf3 := server.NewConfig() |
| 33 |
conf3.BaseURL = "https://ntfy.example.com" |
| 34 |
assert.NotEqual(t, conf1.Hash(), conf3.Hash()) |
| 35 |
} |