diff --git a/server/server.go b/server/server.go index 169ccd7..d910284 100644 --- a/server/server.go +++ b/server/server.go @@ -618,7 +618,7 @@ func (s *Server) handlePublishWithoutResponse(r *http.Request, v *visitor) (*mes } m.Sender = v.IP() m.User = v.MaybeUserID() - m.Expires = time.Now().Add(v.Limits().MessageExpiryDuration).Unix() + m.Expires = time.Unix(m.Time, 0).Add(v.Limits().MessageExpiryDuration).Unix() if err := s.handlePublishBody(r, v, m, body, unifiedpush); err != nil { return nil, err } diff --git a/server/server_test.go b/server/server_test.go index 375a590..fb78523 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -324,6 +324,18 @@ func TestServer_PublishAt(t *testing.T) { require.Equal(t, "9.9.9.9", messages[0].Sender.String()) // It's stored in the DB though! } +func TestServer_PublishAt_Expires(t *testing.T) { + s := newTestServer(t, newTestConfig(t)) + + response := request(t, s, "PUT", "/mytopic", "a message", map[string]string{ + "In": "2 days", + }) + require.Equal(t, 200, response.Code) + m := toMessage(t, response.Body.String()) + require.True(t, m.Expires > time.Now().Add(12*time.Hour+48*time.Hour-time.Minute).Unix()) + require.True(t, m.Expires < time.Now().Add(12*time.Hour+48*time.Hour+time.Minute).Unix()) +} + func TestServer_PublishAtWithCacheError(t *testing.T) { s := newTestServer(t, newTestConfig(t))