Make server tests also run against postgres
This commit is contained in:
@@ -26,12 +26,13 @@ type Store interface {
|
|||||||
AddMessage(m *model.Message) error
|
AddMessage(m *model.Message) error
|
||||||
AddMessages(ms []*model.Message) error
|
AddMessages(ms []*model.Message) error
|
||||||
DB() *sql.DB
|
DB() *sql.DB
|
||||||
|
Message(id string) (*model.Message, error)
|
||||||
|
MessageCounts() (map[string]int, error)
|
||||||
Messages(topic string, since model.SinceMarker, scheduled bool) ([]*model.Message, error)
|
Messages(topic string, since model.SinceMarker, scheduled bool) ([]*model.Message, error)
|
||||||
MessagesDue() ([]*model.Message, error)
|
MessagesDue() ([]*model.Message, error)
|
||||||
MessagesExpired() ([]string, error)
|
MessagesExpired() ([]string, error)
|
||||||
Message(id string) (*model.Message, error)
|
|
||||||
MarkPublished(m *model.Message) error
|
MarkPublished(m *model.Message) error
|
||||||
MessageCounts() (map[string]int, error)
|
UpdateMessageTime(messageID string, timestamp int64) error
|
||||||
Topics() ([]string, error)
|
Topics() ([]string, error)
|
||||||
DeleteMessages(ids ...string) error
|
DeleteMessages(ids ...string) error
|
||||||
DeleteScheduledBySequenceID(topic, sequenceID string) ([]string, error)
|
DeleteScheduledBySequenceID(topic, sequenceID string) ([]string, error)
|
||||||
@@ -71,6 +72,7 @@ type storeQueries struct {
|
|||||||
selectAttachmentsSizeByUserID string
|
selectAttachmentsSizeByUserID string
|
||||||
selectStats string
|
selectStats string
|
||||||
updateStats string
|
updateStats string
|
||||||
|
updateMessageTime string
|
||||||
}
|
}
|
||||||
|
|
||||||
// commonStore implements store operations that are identical across database backends
|
// commonStore implements store operations that are identical across database backends
|
||||||
@@ -302,6 +304,12 @@ func (c *commonStore) Message(id string) (*model.Message, error) {
|
|||||||
return readMessage(rows)
|
return readMessage(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateMessageTime updates the time column for a message by ID. This is only used for testing.
|
||||||
|
func (c *commonStore) UpdateMessageTime(messageID string, timestamp int64) error {
|
||||||
|
_, err := c.db.Exec(c.queries.updateMessageTime, timestamp, messageID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (c *commonStore) MarkPublished(m *model.Message) error {
|
func (c *commonStore) MarkPublished(m *model.Message) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ const (
|
|||||||
|
|
||||||
pgSelectStatsQuery = `SELECT value FROM message_stats WHERE key = 'messages'`
|
pgSelectStatsQuery = `SELECT value FROM message_stats WHERE key = 'messages'`
|
||||||
pgUpdateStatsQuery = `UPDATE message_stats SET value = $1 WHERE key = 'messages'`
|
pgUpdateStatsQuery = `UPDATE message_stats SET value = $1 WHERE key = 'messages'`
|
||||||
|
pgUpdateMessageTimesQuery = `UPDATE message SET time = $1 WHERE mid = $2`
|
||||||
)
|
)
|
||||||
|
|
||||||
var pgQueries = storeQueries{
|
var pgQueries = storeQueries{
|
||||||
@@ -100,6 +101,7 @@ var pgQueries = storeQueries{
|
|||||||
selectAttachmentsSizeByUserID: pgSelectAttachmentsSizeByUserIDQuery,
|
selectAttachmentsSizeByUserID: pgSelectAttachmentsSizeByUserIDQuery,
|
||||||
selectStats: pgSelectStatsQuery,
|
selectStats: pgSelectStatsQuery,
|
||||||
updateStats: pgUpdateStatsQuery,
|
updateStats: pgUpdateStatsQuery,
|
||||||
|
updateMessageTime: pgUpdateMessageTimesQuery,
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPostgresStore creates a new PostgreSQL-backed message cache store.
|
// NewPostgresStore creates a new PostgreSQL-backed message cache store.
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ const (
|
|||||||
|
|
||||||
sqliteSelectStatsQuery = `SELECT value FROM stats WHERE key = 'messages'`
|
sqliteSelectStatsQuery = `SELECT value FROM stats WHERE key = 'messages'`
|
||||||
sqliteUpdateStatsQuery = `UPDATE stats SET value = ? WHERE key = 'messages'`
|
sqliteUpdateStatsQuery = `UPDATE stats SET value = ? WHERE key = 'messages'`
|
||||||
|
sqliteUpdateMessageTimeQuery = `UPDATE messages SET time = ? WHERE mid = ?`
|
||||||
)
|
)
|
||||||
|
|
||||||
var sqliteQueries = storeQueries{
|
var sqliteQueries = storeQueries{
|
||||||
@@ -103,6 +104,7 @@ var sqliteQueries = storeQueries{
|
|||||||
selectAttachmentsSizeByUserID: sqliteSelectAttachmentsSizeByUserIDQuery,
|
selectAttachmentsSizeByUserID: sqliteSelectAttachmentsSizeByUserIDQuery,
|
||||||
selectStats: sqliteSelectStatsQuery,
|
selectStats: sqliteSelectStatsQuery,
|
||||||
updateStats: sqliteUpdateStatsQuery,
|
updateStats: sqliteUpdateStatsQuery,
|
||||||
|
updateMessageTime: sqliteUpdateMessageTimeQuery,
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSQLiteStore creates a SQLite file-backed cache
|
// NewSQLiteStore creates a SQLite file-backed cache
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAccount_Signup_Success(t *testing.T) {
|
func TestAccount_Signup_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -49,9 +50,11 @@ func TestAccount_Signup_Success(t *testing.T) {
|
|||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
||||||
require.Equal(t, "phil", account.Username)
|
require.Equal(t, "phil", account.Username)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Signup_UserExists(t *testing.T) {
|
func TestAccount_Signup_UserExists(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -63,9 +66,11 @@ func TestAccount_Signup_UserExists(t *testing.T) {
|
|||||||
rr = request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
rr = request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
||||||
require.Equal(t, 409, rr.Code)
|
require.Equal(t, 409, rr.Code)
|
||||||
require.Equal(t, 40901, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 40901, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Signup_LimitReached(t *testing.T) {
|
func TestAccount_Signup_LimitReached(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -78,9 +83,11 @@ func TestAccount_Signup_LimitReached(t *testing.T) {
|
|||||||
rr := request(t, s, "POST", "/v1/account", `{"username":"thiswontwork", "password":"mypass"}`, nil)
|
rr := request(t, s, "POST", "/v1/account", `{"username":"thiswontwork", "password":"mypass"}`, nil)
|
||||||
require.Equal(t, 429, rr.Code)
|
require.Equal(t, 429, rr.Code)
|
||||||
require.Equal(t, 42906, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 42906, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Signup_AsUser(t *testing.T) {
|
func TestAccount_Signup_AsUser(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -100,9 +107,11 @@ func TestAccount_Signup_AsUser(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("ben", "ben"),
|
"Authorization": util.BasicAuth("ben", "ben"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Signup_Disabled(t *testing.T) {
|
func TestAccount_Signup_Disabled(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = false
|
conf.EnableSignup = false
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -111,9 +120,11 @@ func TestAccount_Signup_Disabled(t *testing.T) {
|
|||||||
rr := request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
rr := request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
||||||
require.Equal(t, 400, rr.Code)
|
require.Equal(t, 400, rr.Code)
|
||||||
require.Equal(t, 40022, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 40022, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Signup_Rate_Limit(t *testing.T) {
|
func TestAccount_Signup_Rate_Limit(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -125,9 +136,11 @@ func TestAccount_Signup_Rate_Limit(t *testing.T) {
|
|||||||
rr := request(t, s, "POST", "/v1/account", `{"username":"notallowed", "password":"mypass"}`, nil)
|
rr := request(t, s, "POST", "/v1/account", `{"username":"notallowed", "password":"mypass"}`, nil)
|
||||||
require.Equal(t, 429, rr.Code)
|
require.Equal(t, 429, rr.Code)
|
||||||
require.Equal(t, 42906, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 42906, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Get_Anonymous(t *testing.T) {
|
func TestAccount_Get_Anonymous(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.VisitorRequestLimitReplenish = 86 * time.Second
|
conf.VisitorRequestLimitReplenish = 86 * time.Second
|
||||||
conf.VisitorEmailLimitReplenish = time.Hour
|
conf.VisitorEmailLimitReplenish = time.Hour
|
||||||
@@ -168,9 +181,11 @@ func TestAccount_Get_Anonymous(t *testing.T) {
|
|||||||
require.Equal(t, int64(1002), account.Stats.MessagesRemaining)
|
require.Equal(t, int64(1002), account.Stats.MessagesRemaining)
|
||||||
require.Equal(t, int64(1), account.Stats.Emails)
|
require.Equal(t, int64(1), account.Stats.Emails)
|
||||||
require.Equal(t, int64(23), account.Stats.EmailsRemaining)
|
require.Equal(t, int64(23), account.Stats.EmailsRemaining)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_ChangeSettings(t *testing.T) {
|
func TestAccount_ChangeSettings(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -197,9 +212,11 @@ func TestAccount_ChangeSettings(t *testing.T) {
|
|||||||
require.Equal(t, util.Int(86400), account.Notification.DeleteAfter)
|
require.Equal(t, util.Int(86400), account.Notification.DeleteAfter)
|
||||||
require.Equal(t, util.String("juntos"), account.Notification.Sound)
|
require.Equal(t, util.String("juntos"), account.Notification.Sound)
|
||||||
require.Nil(t, account.Notification.MinPriority) // Not set
|
require.Nil(t, account.Notification.MinPriority) // Not set
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Subscription_AddUpdateDelete(t *testing.T) {
|
func TestAccount_Subscription_AddUpdateDelete(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -248,9 +265,11 @@ func TestAccount_Subscription_AddUpdateDelete(t *testing.T) {
|
|||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
||||||
require.Equal(t, 0, len(account.Subscriptions))
|
require.Equal(t, 0, len(account.Subscriptions))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_ChangePassword(t *testing.T) {
|
func TestAccount_ChangePassword(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.AuthUsers = []*user.User{
|
conf.AuthUsers = []*user.User{
|
||||||
{Name: "philuser", Hash: "$2a$10$U4WSIYY6evyGmZaraavM2e2JeVG6EMGUKN1uUwufUeeRd4Jpg6cGC", Role: user.RoleUser}, // philuser:philpass
|
{Name: "philuser", Hash: "$2a$10$U4WSIYY6evyGmZaraavM2e2JeVG6EMGUKN1uUwufUeeRd4Jpg6cGC", Role: user.RoleUser}, // philuser:philpass
|
||||||
@@ -291,17 +310,21 @@ func TestAccount_ChangePassword(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("philuser", "philpass"),
|
"Authorization": util.BasicAuth("philuser", "philpass"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 409, rr.Code)
|
require.Equal(t, 409, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_ChangePassword_NoAccount(t *testing.T) {
|
func TestAccount_ChangePassword_NoAccount(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
rr := request(t, s, "POST", "/v1/account/password", `{"password": "new password"}`, nil)
|
rr := request(t, s, "POST", "/v1/account/password", `{"password": "new password"}`, nil)
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_ExtendToken(t *testing.T) {
|
func TestAccount_ExtendToken(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
@@ -336,9 +359,11 @@ func TestAccount_ExtendToken(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, "some label", token.Label)
|
require.Equal(t, "some label", token.Label)
|
||||||
require.Equal(t, expires.Unix(), token.Expires)
|
require.Equal(t, expires.Unix(), token.Expires)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_ExtendToken_NoTokenProvided(t *testing.T) {
|
func TestAccount_ExtendToken_NoTokenProvided(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -349,9 +374,11 @@ func TestAccount_ExtendToken_NoTokenProvided(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Equal(t, 400, rr.Code)
|
require.Equal(t, 400, rr.Code)
|
||||||
require.Equal(t, 40023, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 40023, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_DeleteToken(t *testing.T) {
|
func TestAccount_DeleteToken(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -389,9 +416,11 @@ func TestAccount_DeleteToken(t *testing.T) {
|
|||||||
"Authorization": util.BearerAuth(token.Token),
|
"Authorization": util.BearerAuth(token.Token),
|
||||||
})
|
})
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Delete_Success(t *testing.T) {
|
func TestAccount_Delete_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -418,9 +447,11 @@ func TestAccount_Delete_Success(t *testing.T) {
|
|||||||
// Cannot re-create account, since still exists
|
// Cannot re-create account, since still exists
|
||||||
rr = request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
rr = request(t, s, "POST", "/v1/account", `{"username":"phil", "password":"mypass"}`, nil)
|
||||||
require.Equal(t, 409, rr.Code)
|
require.Equal(t, 409, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Delete_Not_Allowed(t *testing.T) {
|
func TestAccount_Delete_Not_Allowed(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -439,9 +470,11 @@ func TestAccount_Delete_Not_Allowed(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.Equal(t, 400, rr.Code)
|
require.Equal(t, 400, rr.Code)
|
||||||
require.Equal(t, 40026, toHTTPError(t, rr.Body.String()).Code)
|
require.Equal(t, 40026, toHTTPError(t, rr.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Reservation_AddWithoutTierFails(t *testing.T) {
|
func TestAccount_Reservation_AddWithoutTierFails(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -453,9 +486,11 @@ func TestAccount_Reservation_AddWithoutTierFails(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "mypass"),
|
"Authorization": util.BasicAuth("phil", "mypass"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Reservation_AddAdminSuccess(t *testing.T) {
|
func TestAccount_Reservation_AddAdminSuccess(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -505,9 +540,11 @@ func TestAccount_Reservation_AddAdminSuccess(t *testing.T) {
|
|||||||
reservations, err = s.userManager.Reservations("noadmin2")
|
reservations, err = s.userManager.Reservations("noadmin2")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 0, len(reservations))
|
require.Equal(t, 0, len(reservations))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Reservation_AddRemoveUserWithTierSuccess(t *testing.T) {
|
func TestAccount_Reservation_AddRemoveUserWithTierSuccess(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
conf.EnableReservations = true
|
conf.EnableReservations = true
|
||||||
@@ -591,9 +628,11 @@ func TestAccount_Reservation_AddRemoveUserWithTierSuccess(t *testing.T) {
|
|||||||
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
account, _ = util.UnmarshalJSON[apiAccountResponse](io.NopCloser(rr.Body))
|
||||||
require.Equal(t, 1, len(account.Reservations))
|
require.Equal(t, 1, len(account.Reservations))
|
||||||
require.Equal(t, "mytopic", account.Reservations[0].Topic)
|
require.Equal(t, "mytopic", account.Reservations[0].Topic)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Reservation_PublishByAnonymousFails(t *testing.T) {
|
func TestAccount_Reservation_PublishByAnonymousFails(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.AuthDefault = user.PermissionReadWrite
|
conf.AuthDefault = user.PermissionReadWrite
|
||||||
conf.EnableSignup = true
|
conf.EnableSignup = true
|
||||||
@@ -625,9 +664,11 @@ func TestAccount_Reservation_PublishByAnonymousFails(t *testing.T) {
|
|||||||
// Publish a message (as anonymous)
|
// Publish a message (as anonymous)
|
||||||
rr = request(t, s, "POST", "/mytopic", `Howdy`, nil)
|
rr = request(t, s, "POST", "/mytopic", `Howdy`, nil)
|
||||||
require.Equal(t, 403, rr.Code)
|
require.Equal(t, 403, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccount_Reservation_Delete_Messages_And_Attachments(t *testing.T) {
|
func TestAccount_Reservation_Delete_Messages_And_Attachments(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
conf := newTestConfigWithAuthFile(t)
|
conf := newTestConfigWithAuthFile(t)
|
||||||
conf.AuthDefault = user.PermissionReadWrite
|
conf.AuthDefault = user.PermissionReadWrite
|
||||||
@@ -715,6 +756,7 @@ func TestAccount_Reservation_Delete_Messages_And_Attachments(t *testing.T) {
|
|||||||
require.Equal(t, 1, len(ms))
|
require.Equal(t, 1, len(ms))
|
||||||
require.Equal(t, m2.ID, ms[0].ID)
|
require.Equal(t, m2.ID, ms[0].ID)
|
||||||
require.FileExists(t, filepath.Join(s.config.AttachmentCacheDir, m2.ID))
|
require.FileExists(t, filepath.Join(s.config.AttachmentCacheDir, m2.ID))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func TestAccount_Persist_UserStats_After_Tier_Change(t *testing.T) {
|
/*func TestAccount_Persist_UserStats_After_Tier_Change(t *testing.T) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestVersion_Admin(t *testing.T) {
|
func TestVersion_Admin(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.BuildVersion = "1.2.3"
|
c.BuildVersion = "1.2.3"
|
||||||
c.BuildCommit = "abcdef0"
|
c.BuildCommit = "abcdef0"
|
||||||
@@ -43,9 +44,11 @@ func TestVersion_Admin(t *testing.T) {
|
|||||||
// Unauthenticated user cannot access /v1/version
|
// Unauthenticated user cannot access /v1/version
|
||||||
rr = request(t, s, "GET", "/v1/version", "", nil)
|
rr = request(t, s, "GET", "/v1/version", "", nil)
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_AddRemove(t *testing.T) {
|
func TestUser_AddRemove(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -99,9 +102,11 @@ func TestUser_AddRemove(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "phil"),
|
"Authorization": util.BasicAuth("phil", "phil"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 400, rr.Code)
|
require.Equal(t, 400, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_AddWithPasswordHash(t *testing.T) {
|
func TestUser_AddWithPasswordHash(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -128,9 +133,11 @@ func TestUser_AddWithPasswordHash(t *testing.T) {
|
|||||||
require.Equal(t, user.RoleAdmin, users[0].Role)
|
require.Equal(t, user.RoleAdmin, users[0].Role)
|
||||||
require.Equal(t, "ben", users[1].Name)
|
require.Equal(t, "ben", users[1].Name)
|
||||||
require.Equal(t, user.RoleUser, users[1].Role)
|
require.Equal(t, user.RoleUser, users[1].Role)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_ChangeUserPassword(t *testing.T) {
|
func TestUser_ChangeUserPassword(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -166,9 +173,11 @@ func TestUser_ChangeUserPassword(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("ben", "ben-two"),
|
"Authorization": util.BasicAuth("ben", "ben-two"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_ChangeUserTier(t *testing.T) {
|
func TestUser_ChangeUserTier(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -206,9 +215,11 @@ func TestUser_ChangeUserTier(t *testing.T) {
|
|||||||
users, err = s.userManager.Users()
|
users, err = s.userManager.Users()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, "tier2", users[1].Tier.Code)
|
require.Equal(t, "tier2", users[1].Tier.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_ChangeUserPasswordAndTier(t *testing.T) {
|
func TestUser_ChangeUserPasswordAndTier(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -258,9 +269,11 @@ func TestUser_ChangeUserPasswordAndTier(t *testing.T) {
|
|||||||
users, err = s.userManager.Users()
|
users, err = s.userManager.Users()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, "tier2", users[1].Tier.Code)
|
require.Equal(t, "tier2", users[1].Tier.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_ChangeUserPasswordWithHash(t *testing.T) {
|
func TestUser_ChangeUserPasswordWithHash(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -290,9 +303,11 @@ func TestUser_ChangeUserPasswordWithHash(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("ben", "ben"),
|
"Authorization": util.BasicAuth("ben", "ben"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_DontChangeAdminPassword(t *testing.T) {
|
func TestUser_DontChangeAdminPassword(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -305,9 +320,11 @@ func TestUser_DontChangeAdminPassword(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "phil"),
|
"Authorization": util.BasicAuth("phil", "phil"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 403, rr.Code)
|
require.Equal(t, 403, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUser_AddRemove_Failures(t *testing.T) {
|
func TestUser_AddRemove_Failures(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
s := newTestServer(t, newTestConfigWithAuthFile(t))
|
||||||
defer s.closeDatabases()
|
defer s.closeDatabases()
|
||||||
|
|
||||||
@@ -344,9 +361,11 @@ func TestUser_AddRemove_Failures(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "phil"),
|
"Authorization": util.BasicAuth("phil", "phil"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccess_AllowReset(t *testing.T) {
|
func TestAccess_AllowReset(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.AuthDefault = user.PermissionDenyAll
|
c.AuthDefault = user.PermissionDenyAll
|
||||||
s := newTestServer(t, c)
|
s := newTestServer(t, c)
|
||||||
@@ -385,9 +404,11 @@ func TestAccess_AllowReset(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("ben", "ben"),
|
"Authorization": util.BasicAuth("ben", "ben"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 403, rr.Code)
|
require.Equal(t, 403, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccess_AllowReset_NonAdminAttempt(t *testing.T) {
|
func TestAccess_AllowReset_NonAdminAttempt(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.AuthDefault = user.PermissionDenyAll
|
c.AuthDefault = user.PermissionDenyAll
|
||||||
s := newTestServer(t, c)
|
s := newTestServer(t, c)
|
||||||
@@ -401,9 +422,11 @@ func TestAccess_AllowReset_NonAdminAttempt(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("ben", "ben"),
|
"Authorization": util.BasicAuth("ben", "ben"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccess_AllowReset_KillConnection(t *testing.T) {
|
func TestAccess_AllowReset_KillConnection(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.AuthDefault = user.PermissionDenyAll
|
c.AuthDefault = user.PermissionDenyAll
|
||||||
s := newTestServer(t, c)
|
s := newTestServer(t, c)
|
||||||
@@ -434,4 +457,5 @@ func TestAccess_AllowReset_KillConnection(t *testing.T) {
|
|||||||
waitFor(t, func() bool {
|
waitFor(t, func() bool {
|
||||||
return timeTaken.Load() >= 500
|
return timeTaken.Load() >= 500
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestServer_Manager_Prune_Messages_Without_Attachments_DoesNotPanic(t *testing.T) {
|
func TestServer_Manager_Prune_Messages_Without_Attachments_DoesNotPanic(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
// Tests that the manager runs without attachment-cache-dir set, see #617
|
// Tests that the manager runs without attachment-cache-dir set, see #617
|
||||||
c := newTestConfig(t)
|
c := newTestConfig(t)
|
||||||
c.AttachmentCacheDir = ""
|
c.AttachmentCacheDir = ""
|
||||||
@@ -25,4 +26,5 @@ func TestServer_Manager_Prune_Messages_Without_Attachments_DoesNotPanic(t *testi
|
|||||||
// Actually deleted
|
// Actually deleted
|
||||||
_, err := s.messageCache.Message(m.ID)
|
_, err := s.messageCache.Message(m.ID)
|
||||||
require.Equal(t, errMessageNotFound, err)
|
require.Equal(t, errMessageNotFound, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPayments_Tiers(t *testing.T) {
|
func TestPayments_Tiers(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -128,9 +129,11 @@ func TestPayments_Tiers(t *testing.T) {
|
|||||||
require.Equal(t, int64(999111), tier.Limits.AttachmentFileSize)
|
require.Equal(t, int64(999111), tier.Limits.AttachmentFileSize)
|
||||||
require.Equal(t, int64(888111), tier.Limits.AttachmentTotalSize)
|
require.Equal(t, int64(888111), tier.Limits.AttachmentTotalSize)
|
||||||
require.Equal(t, int64(3600), tier.Limits.AttachmentExpiryDuration)
|
require.Equal(t, int64(3600), tier.Limits.AttachmentExpiryDuration)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_SubscriptionCreate_NotAStripeCustomer_Success(t *testing.T) {
|
func TestPayments_SubscriptionCreate_NotAStripeCustomer_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -161,9 +164,11 @@ func TestPayments_SubscriptionCreate_NotAStripeCustomer_Success(t *testing.T) {
|
|||||||
redirectResponse, err := util.UnmarshalJSON[apiAccountBillingSubscriptionCreateResponse](io.NopCloser(response.Body))
|
redirectResponse, err := util.UnmarshalJSON[apiAccountBillingSubscriptionCreateResponse](io.NopCloser(response.Body))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, "https://billing.stripe.com/abc/def", redirectResponse.RedirectURL)
|
require.Equal(t, "https://billing.stripe.com/abc/def", redirectResponse.RedirectURL)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_SubscriptionCreate_StripeCustomer_Success(t *testing.T) {
|
func TestPayments_SubscriptionCreate_StripeCustomer_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -205,9 +210,11 @@ func TestPayments_SubscriptionCreate_StripeCustomer_Success(t *testing.T) {
|
|||||||
redirectResponse, err := util.UnmarshalJSON[apiAccountBillingSubscriptionCreateResponse](io.NopCloser(response.Body))
|
redirectResponse, err := util.UnmarshalJSON[apiAccountBillingSubscriptionCreateResponse](io.NopCloser(response.Body))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, "https://billing.stripe.com/abc/def", redirectResponse.RedirectURL)
|
require.Equal(t, "https://billing.stripe.com/abc/def", redirectResponse.RedirectURL)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_AccountDelete_Cancels_Subscription(t *testing.T) {
|
func TestPayments_AccountDelete_Cancels_Subscription(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -250,9 +257,11 @@ func TestPayments_AccountDelete_Cancels_Subscription(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "mypass"),
|
"Authorization": util.BasicAuth("phil", "mypass"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 401, rr.Code)
|
require.Equal(t, 401, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_Checkout_Success_And_Increase_Rate_Limits_Reset_Visitor(t *testing.T) {
|
func TestPayments_Checkout_Success_And_Increase_Rate_Limits_Reset_Visitor(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
// This test is too overloaded, but it's also a great end-to-end a test.
|
// This test is too overloaded, but it's also a great end-to-end a test.
|
||||||
//
|
//
|
||||||
// It tests:
|
// It tests:
|
||||||
@@ -415,9 +424,11 @@ func TestPayments_Checkout_Success_And_Increase_Rate_Limits_Reset_Visitor(t *tes
|
|||||||
require.Equal(t, int64(220), account.Limits.Messages)
|
require.Equal(t, int64(220), account.Limits.Messages)
|
||||||
require.Equal(t, int64(220), account.Stats.Messages)
|
require.Equal(t, int64(220), account.Stats.Messages)
|
||||||
require.Equal(t, int64(0), account.Stats.MessagesRemaining)
|
require.Equal(t, int64(0), account.Stats.MessagesRemaining)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_Webhook_Subscription_Updated_Downgrade_From_PastDue_To_Active(t *testing.T) {
|
func TestPayments_Webhook_Subscription_Updated_Downgrade_From_PastDue_To_Active(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
// This tests incoming webhooks from Stripe to update a subscription:
|
// This tests incoming webhooks from Stripe to update a subscription:
|
||||||
@@ -544,9 +555,11 @@ func TestPayments_Webhook_Subscription_Updated_Downgrade_From_PastDue_To_Active(
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 0, len(ms))
|
require.Equal(t, 0, len(ms))
|
||||||
require.NoFileExists(t, filepath.Join(s.config.AttachmentCacheDir, z2.ID))
|
require.NoFileExists(t, filepath.Join(s.config.AttachmentCacheDir, z2.ID))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_Webhook_Subscription_Deleted(t *testing.T) {
|
func TestPayments_Webhook_Subscription_Deleted(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
// This tests incoming webhooks from Stripe to delete a subscription. It verifies that the database is
|
// This tests incoming webhooks from Stripe to delete a subscription. It verifies that the database is
|
||||||
// updated (all Stripe fields are deleted, and the tier is removed).
|
// updated (all Stripe fields are deleted, and the tier is removed).
|
||||||
//
|
//
|
||||||
@@ -609,9 +622,11 @@ func TestPayments_Webhook_Subscription_Deleted(t *testing.T) {
|
|||||||
r, err := s.userManager.Reservations("phil")
|
r, err := s.userManager.Reservations("phil")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 0, len(r))
|
require.Equal(t, 0, len(r))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_Subscription_Update_Different_Tier(t *testing.T) {
|
func TestPayments_Subscription_Update_Different_Tier(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -673,9 +688,11 @@ func TestPayments_Subscription_Update_Different_Tier(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "phil"),
|
"Authorization": util.BasicAuth("phil", "phil"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_Subscription_Delete_At_Period_End(t *testing.T) {
|
func TestPayments_Subscription_Delete_At_Period_End(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -704,9 +721,11 @@ func TestPayments_Subscription_Delete_At_Period_End(t *testing.T) {
|
|||||||
"Authorization": util.BasicAuth("phil", "phil"),
|
"Authorization": util.BasicAuth("phil", "phil"),
|
||||||
})
|
})
|
||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayments_CreatePortalSession(t *testing.T) {
|
func TestPayments_CreatePortalSession(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
stripeMock := &testStripeAPI{}
|
stripeMock := &testStripeAPI{}
|
||||||
defer stripeMock.AssertExpectations(t)
|
defer stripeMock.AssertExpectations(t)
|
||||||
|
|
||||||
@@ -740,6 +759,7 @@ func TestPayments_CreatePortalSession(t *testing.T) {
|
|||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
ps, _ := util.UnmarshalJSON[apiAccountBillingPortalRedirectResponse](io.NopCloser(rr.Body))
|
ps, _ := util.UnmarshalJSON[apiAccountBillingPortalRedirectResponse](io.NopCloser(rr.Body))
|
||||||
require.Equal(t, "https://billing.stripe.com/blablabla", ps.RedirectURL)
|
require.Equal(t, "https://billing.stripe.com/blablabla", ps.RedirectURL)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type testStripeAPI struct {
|
type testStripeAPI struct {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -14,6 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Add_Verify_Call_Delete_Success(t *testing.T) {
|
func TestServer_Twilio_Call_Add_Verify_Call_Delete_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
var called, verified atomic.Bool
|
var called, verified atomic.Bool
|
||||||
var code atomic.Pointer[string]
|
var code atomic.Pointer[string]
|
||||||
twilioVerifyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
twilioVerifyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -112,9 +113,11 @@ func TestServer_Twilio_Call_Add_Verify_Call_Delete_Success(t *testing.T) {
|
|||||||
phoneNumbers, err = s.userManager.PhoneNumbers(u.ID)
|
phoneNumbers, err = s.userManager.PhoneNumbers(u.ID)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 0, len(phoneNumbers))
|
require.Equal(t, 0, len(phoneNumbers))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Success(t *testing.T) {
|
func TestServer_Twilio_Call_Success(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
var called atomic.Bool
|
var called atomic.Bool
|
||||||
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if called.Load() {
|
if called.Load() {
|
||||||
@@ -157,9 +160,11 @@ func TestServer_Twilio_Call_Success(t *testing.T) {
|
|||||||
waitFor(t, func() bool {
|
waitFor(t, func() bool {
|
||||||
return called.Load()
|
return called.Load()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Success_With_Yes(t *testing.T) {
|
func TestServer_Twilio_Call_Success_With_Yes(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
var called atomic.Bool
|
var called atomic.Bool
|
||||||
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if called.Load() {
|
if called.Load() {
|
||||||
@@ -202,9 +207,11 @@ func TestServer_Twilio_Call_Success_With_Yes(t *testing.T) {
|
|||||||
waitFor(t, func() bool {
|
waitFor(t, func() bool {
|
||||||
return called.Load()
|
return called.Load()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Success_with_custom_twiml(t *testing.T) {
|
func TestServer_Twilio_Call_Success_with_custom_twiml(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
var called atomic.Bool
|
var called atomic.Bool
|
||||||
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
twilioServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if called.Load() {
|
if called.Load() {
|
||||||
@@ -263,9 +270,11 @@ func TestServer_Twilio_Call_Success_with_custom_twiml(t *testing.T) {
|
|||||||
waitFor(t, func() bool {
|
waitFor(t, func() bool {
|
||||||
return called.Load()
|
return called.Load()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_UnverifiedNumber(t *testing.T) {
|
func TestServer_Twilio_Call_UnverifiedNumber(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.TwilioCallsBaseURL = "http://dummy.invalid"
|
c.TwilioCallsBaseURL = "http://dummy.invalid"
|
||||||
c.TwilioAccount = "AC1234567890"
|
c.TwilioAccount = "AC1234567890"
|
||||||
@@ -288,9 +297,11 @@ func TestServer_Twilio_Call_UnverifiedNumber(t *testing.T) {
|
|||||||
"x-call": "+11122233344",
|
"x-call": "+11122233344",
|
||||||
})
|
})
|
||||||
require.Equal(t, 40034, toHTTPError(t, response.Body.String()).Code)
|
require.Equal(t, 40034, toHTTPError(t, response.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_InvalidNumber(t *testing.T) {
|
func TestServer_Twilio_Call_InvalidNumber(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.TwilioCallsBaseURL = "https://127.0.0.1"
|
c.TwilioCallsBaseURL = "https://127.0.0.1"
|
||||||
c.TwilioAccount = "AC1234567890"
|
c.TwilioAccount = "AC1234567890"
|
||||||
@@ -302,9 +313,11 @@ func TestServer_Twilio_Call_InvalidNumber(t *testing.T) {
|
|||||||
"x-call": "+invalid",
|
"x-call": "+invalid",
|
||||||
})
|
})
|
||||||
require.Equal(t, 40033, toHTTPError(t, response.Body.String()).Code)
|
require.Equal(t, 40033, toHTTPError(t, response.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Anonymous(t *testing.T) {
|
func TestServer_Twilio_Call_Anonymous(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
c := newTestConfigWithAuthFile(t)
|
c := newTestConfigWithAuthFile(t)
|
||||||
c.TwilioCallsBaseURL = "https://127.0.0.1"
|
c.TwilioCallsBaseURL = "https://127.0.0.1"
|
||||||
c.TwilioAccount = "AC1234567890"
|
c.TwilioAccount = "AC1234567890"
|
||||||
@@ -316,12 +329,15 @@ func TestServer_Twilio_Call_Anonymous(t *testing.T) {
|
|||||||
"x-call": "+123123",
|
"x-call": "+123123",
|
||||||
})
|
})
|
||||||
require.Equal(t, 40035, toHTTPError(t, response.Body.String()).Code)
|
require.Equal(t, 40035, toHTTPError(t, response.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_Twilio_Call_Unconfigured(t *testing.T) {
|
func TestServer_Twilio_Call_Unconfigured(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
response := request(t, s, "POST", "/mytopic", "test", map[string]string{
|
response := request(t, s, "POST", "/mytopic", "test", map[string]string{
|
||||||
"x-call": "+1234",
|
"x-call": "+1234",
|
||||||
})
|
})
|
||||||
require.Equal(t, 40032, toHTTPError(t, response.Body.String()).Code)
|
require.Equal(t, 40032, toHTTPError(t, response.Body.String()).Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestServer_WebPush_Enabled(t *testing.T) {
|
func TestServer_WebPush_Enabled(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
conf := newTestConfig(t)
|
conf := newTestConfig(t)
|
||||||
conf.WebRoot = "" // Disable web app
|
conf.WebRoot = "" // Disable web app
|
||||||
s := newTestServer(t, conf)
|
s := newTestServer(t, conf)
|
||||||
@@ -46,15 +47,19 @@ func TestServer_WebPush_Enabled(t *testing.T) {
|
|||||||
require.Equal(t, 200, rr.Code)
|
require.Equal(t, 200, rr.Code)
|
||||||
require.Equal(t, "application/manifest+json", rr.Header().Get("Content-Type"))
|
require.Equal(t, "application/manifest+json", rr.Header().Get("Content-Type"))
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
func TestServer_WebPush_Disabled(t *testing.T) {
|
func TestServer_WebPush_Disabled(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfig(t))
|
s := newTestServer(t, newTestConfig(t))
|
||||||
|
|
||||||
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, testWebPushEndpoint), nil)
|
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, testWebPushEndpoint), nil)
|
||||||
require.Equal(t, 404, response.Code)
|
require.Equal(t, 404, response.Code)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicAdd(t *testing.T) {
|
func TestServer_WebPush_TopicAdd(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, testWebPushEndpoint), nil)
|
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, testWebPushEndpoint), nil)
|
||||||
@@ -69,17 +74,21 @@ func TestServer_WebPush_TopicAdd(t *testing.T) {
|
|||||||
require.Equal(t, subs[0].P256dh, "p256dh-key")
|
require.Equal(t, subs[0].P256dh, "p256dh-key")
|
||||||
require.Equal(t, subs[0].Auth, "auth-key")
|
require.Equal(t, subs[0].Auth, "auth-key")
|
||||||
require.Equal(t, subs[0].UserID, "")
|
require.Equal(t, subs[0].UserID, "")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicAdd_InvalidEndpoint(t *testing.T) {
|
func TestServer_WebPush_TopicAdd_InvalidEndpoint(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, "https://ddos-target.example.com/webpush"), nil)
|
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, []string{"test-topic"}, "https://ddos-target.example.com/webpush"), nil)
|
||||||
require.Equal(t, 400, response.Code)
|
require.Equal(t, 400, response.Code)
|
||||||
require.Equal(t, `{"code":40039,"http":400,"error":"invalid request: web push endpoint unknown"}`+"\n", response.Body.String())
|
require.Equal(t, `{"code":40039,"http":400,"error":"invalid request: web push endpoint unknown"}`+"\n", response.Body.String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicAdd_TooManyTopics(t *testing.T) {
|
func TestServer_WebPush_TopicAdd_TooManyTopics(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
topicList := make([]string, 51)
|
topicList := make([]string, 51)
|
||||||
@@ -90,9 +99,11 @@ func TestServer_WebPush_TopicAdd_TooManyTopics(t *testing.T) {
|
|||||||
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, topicList, testWebPushEndpoint), nil)
|
response := request(t, s, "POST", "/v1/webpush", payloadForTopics(t, topicList, testWebPushEndpoint), nil)
|
||||||
require.Equal(t, 400, response.Code)
|
require.Equal(t, 400, response.Code)
|
||||||
require.Equal(t, `{"code":40040,"http":400,"error":"invalid request: too many web push topic subscriptions"}`+"\n", response.Body.String())
|
require.Equal(t, `{"code":40040,"http":400,"error":"invalid request: too many web push topic subscriptions"}`+"\n", response.Body.String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicUnsubscribe(t *testing.T) {
|
func TestServer_WebPush_TopicUnsubscribe(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
addSubscription(t, s, testWebPushEndpoint, "test-topic")
|
addSubscription(t, s, testWebPushEndpoint, "test-topic")
|
||||||
@@ -103,9 +114,11 @@ func TestServer_WebPush_TopicUnsubscribe(t *testing.T) {
|
|||||||
require.Equal(t, `{"success":true}`+"\n", response.Body.String())
|
require.Equal(t, `{"success":true}`+"\n", response.Body.String())
|
||||||
|
|
||||||
requireSubscriptionCount(t, s, "test-topic", 0)
|
requireSubscriptionCount(t, s, "test-topic", 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_Delete(t *testing.T) {
|
func TestServer_WebPush_Delete(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
addSubscription(t, s, testWebPushEndpoint, "test-topic")
|
addSubscription(t, s, testWebPushEndpoint, "test-topic")
|
||||||
@@ -116,9 +129,11 @@ func TestServer_WebPush_Delete(t *testing.T) {
|
|||||||
require.Equal(t, `{"success":true}`+"\n", response.Body.String())
|
require.Equal(t, `{"success":true}`+"\n", response.Body.String())
|
||||||
|
|
||||||
requireSubscriptionCount(t, s, "test-topic", 0)
|
requireSubscriptionCount(t, s, "test-topic", 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicSubscribeProtected_Allowed(t *testing.T) {
|
func TestServer_WebPush_TopicSubscribeProtected_Allowed(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
config := configureAuth(t, newTestConfigWithWebPush(t))
|
config := configureAuth(t, newTestConfigWithWebPush(t))
|
||||||
config.AuthDefault = user.PermissionDenyAll
|
config.AuthDefault = user.PermissionDenyAll
|
||||||
s := newTestServer(t, config)
|
s := newTestServer(t, config)
|
||||||
@@ -136,9 +151,11 @@ func TestServer_WebPush_TopicSubscribeProtected_Allowed(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Len(t, subs, 1)
|
require.Len(t, subs, 1)
|
||||||
require.True(t, strings.HasPrefix(subs[0].UserID, "u_"))
|
require.True(t, strings.HasPrefix(subs[0].UserID, "u_"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_TopicSubscribeProtected_Denied(t *testing.T) {
|
func TestServer_WebPush_TopicSubscribeProtected_Denied(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
config := configureAuth(t, newTestConfigWithWebPush(t))
|
config := configureAuth(t, newTestConfigWithWebPush(t))
|
||||||
config.AuthDefault = user.PermissionDenyAll
|
config.AuthDefault = user.PermissionDenyAll
|
||||||
s := newTestServer(t, config)
|
s := newTestServer(t, config)
|
||||||
@@ -147,9 +164,11 @@ func TestServer_WebPush_TopicSubscribeProtected_Denied(t *testing.T) {
|
|||||||
require.Equal(t, 403, response.Code)
|
require.Equal(t, 403, response.Code)
|
||||||
|
|
||||||
requireSubscriptionCount(t, s, "test-topic", 0)
|
requireSubscriptionCount(t, s, "test-topic", 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_DeleteAccountUnsubscribe(t *testing.T) {
|
func TestServer_WebPush_DeleteAccountUnsubscribe(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
config := configureAuth(t, newTestConfigWithWebPush(t))
|
config := configureAuth(t, newTestConfigWithWebPush(t))
|
||||||
s := newTestServer(t, config)
|
s := newTestServer(t, config)
|
||||||
|
|
||||||
@@ -170,9 +189,11 @@ func TestServer_WebPush_DeleteAccountUnsubscribe(t *testing.T) {
|
|||||||
})
|
})
|
||||||
// should've been deleted with the account
|
// should've been deleted with the account
|
||||||
requireSubscriptionCount(t, s, "test-topic", 0)
|
requireSubscriptionCount(t, s, "test-topic", 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_Publish(t *testing.T) {
|
func TestServer_WebPush_Publish(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
var received atomic.Bool
|
var received atomic.Bool
|
||||||
@@ -192,9 +213,11 @@ func TestServer_WebPush_Publish(t *testing.T) {
|
|||||||
waitFor(t, func() bool {
|
waitFor(t, func() bool {
|
||||||
return received.Load()
|
return received.Load()
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_Publish_RemoveOnError(t *testing.T) {
|
func TestServer_WebPush_Publish_RemoveOnError(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
var received atomic.Bool
|
var received atomic.Bool
|
||||||
@@ -220,9 +243,11 @@ func TestServer_WebPush_Publish_RemoveOnError(t *testing.T) {
|
|||||||
|
|
||||||
requireSubscriptionCount(t, s, "test-topic", 0)
|
requireSubscriptionCount(t, s, "test-topic", 0)
|
||||||
requireSubscriptionCount(t, s, "test-topic-abc", 0)
|
requireSubscriptionCount(t, s, "test-topic-abc", 0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_WebPush_Expiry(t *testing.T) {
|
func TestServer_WebPush_Expiry(t *testing.T) {
|
||||||
|
forEachBackend(t, func(t *testing.T) {
|
||||||
s := newTestServer(t, newTestConfigWithWebPush(t))
|
s := newTestServer(t, newTestConfigWithWebPush(t))
|
||||||
|
|
||||||
var received atomic.Bool
|
var received atomic.Bool
|
||||||
@@ -257,6 +282,7 @@ func TestServer_WebPush_Expiry(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
return len(subs) == 0
|
return len(subs) == 0
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func payloadForTopics(t *testing.T, topics []string, endpoint string) string {
|
func payloadForTopics(t *testing.T, topics []string, endpoint string) string {
|
||||||
@@ -285,7 +311,9 @@ func newTestConfigWithWebPush(t *testing.T) *Config {
|
|||||||
conf := newTestConfig(t)
|
conf := newTestConfig(t)
|
||||||
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
|
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
if conf.DatabaseURL == "" {
|
||||||
conf.WebPushFile = filepath.Join(t.TempDir(), "webpush.db")
|
conf.WebPushFile = filepath.Join(t.TempDir(), "webpush.db")
|
||||||
|
}
|
||||||
conf.WebPushEmailAddress = "testing@example.com"
|
conf.WebPushEmailAddress = "testing@example.com"
|
||||||
conf.WebPushPrivateKey = privateKey
|
conf.WebPushPrivateKey = privateKey
|
||||||
conf.WebPushPublicKey = publicKey
|
conf.WebPushPublicKey = publicKey
|
||||||
|
|||||||
Reference in New Issue
Block a user