commit cc6012c0ceaa6373fc4e8400dab62976c7e27309
parent 58ce9b952b22f268275dabcf7feaaf2d0ecccb06
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Sun, 15 Feb 2026 22:37:14 +0100
make tests pass again
Diffstat:
5 files changed, 182 insertions(+), 71 deletions(-)
diff --git a/cmd/mailbox-server/main_test.go b/cmd/mailbox-server/main_test.go
@@ -5,9 +5,11 @@ import (
"crypto/ed25519"
"crypto/rand"
"crypto/sha512"
+ "database/sql"
"encoding/binary"
"encoding/json"
"fmt"
+ "log"
"net/http"
"net/http/httptest"
"os"
@@ -19,7 +21,6 @@ import (
"github.com/schanzen/taler-go/pkg/merchant"
talerutil "github.com/schanzen/taler-go/pkg/util"
"gopkg.in/ini.v1"
- "gorm.io/driver/sqlite"
"taler.net/taler-mailbox/internal/gana"
"taler.net/taler-mailbox/internal/util"
"taler.net/taler-mailbox/pkg/rest"
@@ -82,7 +83,19 @@ func TestMain(m *testing.M) {
fmt.Printf("Failed to read config: %v", err)
os.Exit(1)
}
- db := sqlite.Open("file::memory:?cache=shared")
+ psqlconn := cfg.Section("mailbox-pq").Key("connection_string").MustString("postgres:///taler-mailbox")
+ segments := strings.Split(strings.Split(psqlconn, "?")[0], "/")
+ dbName := segments[len(segments)-1]
+
+ db, err := sql.Open("postgres", psqlconn)
+ if err != nil {
+ log.Panic(err)
+ }
+ defer db.Close()
+ err = talerutil.DBInit(db, "../..", dbName, "taler-mailbox")
+ if err != nil {
+ log.Fatalf("Failed to apply versioning or patches: %v", err)
+ }
merchServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var orderResp merchant.PostOrderRequest
if r.URL.Path == "/config" {
@@ -131,12 +144,12 @@ func TestMain(m *testing.M) {
code := m.Run()
// Purge DB
- a.DB.Where("1 = 1").Delete(&mailbox.InboxEntry{})
+ mailbox.DeleteAllInboxEntriesFromDatabase(a.DB)
os.Exit(code)
}
func TestEmptyMailbox(t *testing.T) {
- a.DB.Where("1 = 1").Delete(&mailbox.InboxEntry{})
+ mailbox.DeleteAllInboxEntriesFromDatabase(a.DB)
req, _ := http.NewRequest("GET", "/"+testAliceHashedSigningKeyString, nil)
response := executeRequest(req)
@@ -150,7 +163,7 @@ func TestEmptyMailbox(t *testing.T) {
func TestSendMessage(t *testing.T) {
testMessage := make([]byte, 256)
- a.DB.Where("1 = 1").Delete(&mailbox.InboxEntry{})
+ mailbox.DeleteAllInboxEntriesFromDatabase(a.DB)
req, _ := http.NewRequest("POST", "/"+testAliceHashedSigningKeyString, bytes.NewReader(testMessage))
response := executeRequest(req)
@@ -179,7 +192,7 @@ func TestSendMessagePaid(t *testing.T) {
setMailboxPaid(true)
// Cleanup
- a.DB.Where("1 = 1").Delete(&mailbox.InboxEntry{})
+ mailbox.DeleteAllInboxEntriesFromDatabase(a.DB)
testMessage := make([]byte, 256)
rand.Read(testMessage)
@@ -219,7 +232,7 @@ func TestMailboxRegistration(t *testing.T) {
aliceSigningKey := util.Base32CrockfordEncode(testAliceSigningKey)
msg.MailboxMetadata.EncryptionKey = util.Base32CrockfordEncode(encKey)
msg.MailboxMetadata.EncryptionKeyType = "X25519"
- msg.MailboxMetadata.Expiration = mailbox.Timestamp{Seconds: uint64(time.Now().Add(time.Hour*24*365).UnixMilli() / 1000)}
+ msg.MailboxMetadata.Expiration.Seconds = uint64(time.Now().Add(time.Hour*24*365).Unix())
msg.MailboxMetadata.SigningKey = aliceSigningKey
msg.MailboxMetadata.SigningKeyType = "EdDSA"
expNbo := make([]byte, 8)
@@ -262,8 +275,8 @@ func TestMailboxRegistration(t *testing.T) {
if respMsg.EncryptionKey != msg.MailboxMetadata.EncryptionKey {
fmt.Printf("Keys mismatch! %v %v\n", respMsg, msg.MailboxMetadata)
}
- a.DB.Where("1 = 1").Delete(&mailbox.MailboxMetadata{})
- a.DB.Where("1 = 1").Delete(&mailbox.PendingMailboxRegistration{})
+ mailbox.DeleteAllMailboxesFromDatabase(a.DB)
+ mailbox.DeleteAllPendingRegistrationsFromDatabase(a.DB)
}
func TestMailboxRegistrationPaid(t *testing.T) {
@@ -280,7 +293,7 @@ func TestMailboxRegistrationPaid(t *testing.T) {
aliceSigningKey := util.Base32CrockfordEncode(testAliceSigningKey)
msg.MailboxMetadata.EncryptionKey = util.Base32CrockfordEncode(encKey)
msg.MailboxMetadata.EncryptionKeyType = "X25519"
- msg.MailboxMetadata.Expiration = mailbox.Timestamp{Seconds: uint64(time.Now().Add(time.Hour * 24 * 365).UnixMicro())}
+ msg.MailboxMetadata.Expiration.Seconds = uint64(time.Now().Add(time.Hour * 24 * 365).Unix())
msg.MailboxMetadata.SigningKey = aliceSigningKey
msg.MailboxMetadata.SigningKeyType = "EdDSA"
expNbo := make([]byte, 8)
@@ -339,7 +352,7 @@ func TestPostThenDeleteMessage(t *testing.T) {
numMessagesToPost := (a.MessageResponseLimit + 7)
testMessages := make([]byte, 256*numMessagesToPost)
_, _ = rand.Read(testMessages)
- a.DB.Where("1 = 1").Delete(&mailbox.InboxEntry{})
+ mailbox.DeleteAllInboxEntriesFromDatabase(a.DB)
for i := 0; i < int(numMessagesToPost); i++ {
testMessage := testMessages[i*256 : (i+1)*256]
diff --git a/cmd/mailbox-server/test-mailbox.conf b/cmd/mailbox-server/test-mailbox.conf
@@ -8,8 +8,4 @@ message_response_limit = 25
pending_registration_expiration = 24h
[mailbox-pq]
-host = localhost
-port = 5432
-user = mar33597
-password = secret
-db_name = taler-mailbox-test
+connection_string = postgres:///taler-mailbox?host=/var/run/postgresql
diff --git a/pkg/rest/db.go b/pkg/rest/db.go
@@ -22,10 +22,13 @@ import (
"context"
"database/sql"
"errors"
- "fmt"
"time"
)
+type Timestamp struct {
+ Seconds uint64 `json:"t_s"`
+}
+
type MailboxMetadata struct {
// ORM
Serial int64 `json:"-"`
@@ -57,7 +60,7 @@ type MailboxMetadata struct {
EncryptionKeyType string `json:"encryption_key_type"`
// Expiration of this mapping (UNIX Epoch seconds).
- Expiration int64 `json:"expiration" gorm:"embedded;embeddedPrefix:expiration_"`
+ Expiration Timestamp `json:"expiration"`
// Keyoxide claim proof
KoxClaimProof string `json:"kox_claim_proof,omitempty"`
@@ -67,6 +70,9 @@ type PendingMailboxRegistration struct {
// ORM
Serial int64 `json:"-"`
+ // Created timestamp (in Seconds / UNIX Epoch)
+ CreatedAt int64
+
// Hash of the inbox for this entry
HashedSigningKey string // Requested registration duration
@@ -100,9 +106,10 @@ func InsertInboxEntryIntoDatabase(db *sql.DB, e *InboxEntry) error {
}
func InsertPendingRegistrationIntoDatabase(db *sql.DB, pr *PendingMailboxRegistration) error {
+ pr.CreatedAt = time.Now().Unix()
query := `INSERT INTO taler_mailbox.pending_mailbox_registrations
- VALUES (DEFAULT, $1, $2, $3);`
- rows, err := db.Query(query, pr.HashedSigningKey, pr.Duration, pr.OrderID)
+ VALUES (DEFAULT, $1, $2, $3, $4);`
+ rows, err := db.Query(query, pr.CreatedAt, pr.HashedSigningKey, pr.OrderID, pr.Duration)
if err != nil {
return err
}
@@ -113,7 +120,7 @@ func InsertPendingRegistrationIntoDatabase(db *sql.DB, pr *PendingMailboxRegistr
func InsertMailboxRegistrationIntoDatabase(db *sql.DB, mb *MailboxMetadata) error {
query := `INSERT INTO taler_mailbox.mailbox_metadata
VALUES (DEFAULT, $1, $2, $3, $4, $5, $6, $7);`
- rows, err := db.Query(query, mb.HashedSigningKey, mb.SigningKey, mb.SigningKeyType, mb.EncryptionKey, mb.EncryptionKeyType, mb.Expiration, mb.KoxClaimProof)
+ rows, err := db.Query(query, mb.HashedSigningKey, mb.SigningKey, mb.SigningKeyType, mb.EncryptionKey, mb.EncryptionKeyType, mb.Expiration.Seconds, mb.KoxClaimProof)
if err != nil {
return err
}
@@ -139,7 +146,7 @@ func UpdateMailboxExpirationInDatabase(db *sql.DB, mb *MailboxMetadata) error {
SET
"expiration" = $2
WHERE "hashed_signing_key" = $1;`
- rows, err := db.Query(query, mb.HashedSigningKey, mb.Expiration)
+ rows, err := db.Query(query, mb.HashedSigningKey, mb.Expiration.Seconds)
if err != nil {
return err
}
@@ -151,7 +158,7 @@ func GetPendingRegistrationFromDatabaseBySigningKey(db *sql.DB, pr *PendingMailb
query := `SELECT
"serial",
"hashed_signing_key",
- "duration",
+ "registration_duration",
"order_id"
FROM taler_mailbox.pending_mailbox_registrations
WHERE
@@ -166,8 +173,7 @@ func GetPendingRegistrationFromDatabaseBySigningKey(db *sql.DB, pr *PendingMailb
defer rows.Close()
// Iterate over first
if !rows.Next() {
- fmt.Printf("error val %v\n", rows.Err())
- return errors.New("Mailbox metadata does not exist")
+ return errors.New("mailbox metadata does not exist")
}
return rows.Scan(
&pr.Serial,
@@ -181,10 +187,10 @@ func GetMailboxMetadataFromDatabaseBySigningKey(db *sql.DB, mb *MailboxMetadata,
query := `SELECT
"serial",
"hashed_signing_key",
- "signing_key"
- "signing_key_type"
- "encryption_key"
- "encryption_key_type"
+ "signing_key",
+ "signing_key_type",
+ "encryption_key",
+ "encryption_key_type",
"expiration"
FROM taler_mailbox.mailbox_metadata
WHERE
@@ -199,7 +205,6 @@ func GetMailboxMetadataFromDatabaseBySigningKey(db *sql.DB, mb *MailboxMetadata,
defer rows.Close()
// Iterate over first
if !rows.Next() {
- fmt.Printf("error val %v\n", rows.Err())
return errors.New("Mailbox metadata does not exist")
}
return rows.Scan(
@@ -209,7 +214,7 @@ func GetMailboxMetadataFromDatabaseBySigningKey(db *sql.DB, mb *MailboxMetadata,
&mb.SigningKeyType,
&mb.EncryptionKey,
&mb.EncryptionKeyType,
- &mb.Expiration,
+ &mb.Expiration.Seconds,
)
}
@@ -231,8 +236,7 @@ func GetInboxEntryFromDatabaseBySigningKeyAndBody(db *sql.DB, e *InboxEntry, has
defer rows.Close()
// Iterate over first
if !rows.Next() {
- fmt.Printf("error val %v\n", rows.Err())
- return errors.New("Inbox entry does not exist")
+ return errors.New("inbox entry does not exist")
}
return rows.Scan(
&e.Serial,
@@ -259,8 +263,7 @@ func GetInboxEntryFromDatabaseBySerial(db *sql.DB, e *InboxEntry, hashedKey stri
defer rows.Close()
// Iterate over first
if !rows.Next() {
- fmt.Printf("error val %v\n", rows.Err())
- return errors.New("Inbox entry does not exist")
+ return errors.New("inbox entry does not exist")
}
return rows.Scan(
&e.Serial,
@@ -295,8 +298,8 @@ func DeletePendingRegistrationFromDatabase(db *sql.DB, pr *PendingMailboxRegistr
return rows, nil
}
-// DeleteInboxEntryFromSerialFromDatabase Deletes all entries starting from given serial
-func DeleteInboxEntryFromSerialFromDatabase(db *sql.DB, e *InboxEntry) (int64, error) {
+// DeleteInboxEntryFromDatabaseBySerial Deletes all entries starting from given serial
+func DeleteInboxEntryFromDatabaseBySerial(db *sql.DB, e *InboxEntry, count int) (int64, error) {
var ctx context.Context
ctx, stop := context.WithCancel(context.Background())
defer stop()
@@ -305,14 +308,17 @@ func DeleteInboxEntryFromSerialFromDatabase(db *sql.DB, e *InboxEntry) (int64, e
return 0, err
}
defer conn.Close()
- query := `DELETE
- FROM taler_mailbox.inbox_entries
- WHERE
- "hashed_signing_key" = $1 AND
- "serial" >= $2
+ query := `DELETE FROM taler_mailbox.inbox_entries
+ WHERE serial IN (
+ SELECT serial FROM taler_mailbox.inbox_entries
+ WHERE
+ "hashed_signing_key"=$1 AND
+ "serial">=$2
+ LIMIT $3
+ )
;`
// Execute Query
- result, err := conn.ExecContext(ctx, query, e.HashedSigningKey, e.Serial)
+ result, err := conn.ExecContext(ctx, query, e.HashedSigningKey, e.Serial, count)
if err != nil {
return 0, err
}
@@ -376,3 +382,85 @@ func DeleteStalePendingRegistrationsFromDatabase(db *sql.DB, registrationExpirat
}
return rows, nil
}
+
+func DeleteAllPendingRegistrationsFromDatabase(db *sql.DB) (int64, error) {
+ var ctx context.Context
+ ctx, stop := context.WithCancel(context.Background())
+ defer stop()
+ conn, err := db.Conn(ctx)
+ if err != nil {
+ return 0, err
+ }
+ defer conn.Close()
+ query := `DELETE
+ FROM taler_mailbox.pending_mailbox_registrations
+ WHERE
+ 1=1
+ ;`
+ // Execute Query
+ result, err := conn.ExecContext(ctx, query)
+ if err != nil {
+ return 0, err
+ }
+ rows, err := result.RowsAffected()
+ if err != nil {
+ return 0, err
+ }
+ return rows, nil
+}
+
+
+func DeleteAllMailboxesFromDatabase(db *sql.DB) (int64, error) {
+ var ctx context.Context
+ ctx, stop := context.WithCancel(context.Background())
+ defer stop()
+ conn, err := db.Conn(ctx)
+ if err != nil {
+ return 0, err
+ }
+ defer conn.Close()
+ query := `DELETE
+ FROM taler_mailbox.mailbox_metadata
+ WHERE
+ 1=1
+ ;`
+ // Execute Query
+ result, err := conn.ExecContext(ctx, query)
+ if err != nil {
+ return 0, err
+ }
+ rows, err := result.RowsAffected()
+ if err != nil {
+ return 0, err
+ }
+ return rows, nil
+}
+
+
+func DeleteAllInboxEntriesFromDatabase(db *sql.DB) (int64, error) {
+ var ctx context.Context
+ ctx, stop := context.WithCancel(context.Background())
+ defer stop()
+ conn, err := db.Conn(ctx)
+ if err != nil {
+ return 0, err
+ }
+ defer conn.Close()
+ query := `DELETE
+ FROM taler_mailbox.inbox_entries
+ WHERE
+ 1=1
+ ;`
+ // Execute Query
+ result, err := conn.ExecContext(ctx, query)
+ if err != nil {
+ return 0, err
+ }
+ rows, err := result.RowsAffected()
+ if err != nil {
+ return 0, err
+ }
+ return rows, nil
+}
+
+
diff --git a/pkg/rest/mailbox.go b/pkg/rest/mailbox.go
@@ -133,10 +133,6 @@ type RelativeTime struct {
Microseconds uint64 `json:"d_us"`
}
-type Timestamp struct {
- Seconds uint64 `json:"t_s"`
-}
-
// 1 Month as Go duration
const monthDuration = time.Hour * 24 * 30
@@ -235,7 +231,7 @@ func GetMessagesCountFromDatabase(db *sql.DB, hashedKey string) (int64, error) {
query := `SELECT COUNT(*) AS num_messages
FROM taler_mailbox.inbox_entries
WHERE
- "hashed_signing_key" = $1
+ "hashed_signing_key"=$1
;`
// Execute Query
rows, err := db.Query(query, hashedKey)
@@ -299,7 +295,7 @@ func (m *Mailbox) getMessagesResponse(w http.ResponseWriter, r *http.Request) {
m.checkPendingRegistrationUpdates(vars["h_mailbox"])
entries, err := GetMessagesFromDatabase(m.DB, vars["h_mailbox"], int(m.MessageResponseLimit))
if err != nil {
- log.Printf("%v", err)
+ m.Logf(LogError, "Error getting messages: %v", err)
w.WriteHeader(http.StatusNotFound)
return
}
@@ -336,7 +332,7 @@ func (m *Mailbox) sendMessageResponse(w http.ResponseWriter, r *http.Request) {
var count int64
count, err = GetMessagesCountFromDatabase(m.DB, vars["h_mailbox"])
if nil != err {
- m.Logf(LogError, "%v", err)
+ m.Logf(LogError, "Error getting messages: %v", err)
http.Error(w, "Cannot look for entries", http.StatusBadRequest)
return
}
@@ -355,6 +351,11 @@ func (m *Mailbox) sendMessageResponse(w http.ResponseWriter, r *http.Request) {
entry.HashedSigningKey = vars["h_mailbox"]
entry.Body = body
err = InsertInboxEntryIntoDatabase(m.DB, &entry)
+ if err != nil {
+ m.Logf(LogError, "Error storing message: %v", err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
w.WriteHeader(http.StatusNoContent)
}
@@ -364,11 +365,12 @@ func (m *Mailbox) getKeysResponse(w http.ResponseWriter, r *http.Request) {
m.checkPendingRegistrationUpdates(vars["h_mailbox"])
err := GetMailboxMetadataFromDatabaseBySigningKey(m.DB, &keyEntry, vars["h_mailbox"])
if err != nil {
+ m.Logf(LogError, "Error finding mailbox: %v", err)
w.WriteHeader(http.StatusNotFound)
return
}
m.Logf(LogDebug, "entry expires at %d, have %d", keyEntry.Expiration, time.Now().Unix())
- if keyEntry.Expiration < int64(time.Now().Unix()) {
+ if int64(keyEntry.Expiration.Seconds) < int64(time.Now().Unix()) {
w.WriteHeader(http.StatusNotFound)
return
}
@@ -392,7 +394,7 @@ func (m *Mailbox) validateRegistrationSignature(msg MailboxRegistrationRequest)
if nil != err {
return fmt.Errorf("unable to decode signature")
}
- binary.BigEndian.PutUint64(expNbo[:], uint64(msg.MailboxMetadata.Expiration))
+ binary.BigEndian.PutUint64(expNbo[:], msg.MailboxMetadata.Expiration.Seconds)
size := signedMsg[0:4]
binary.BigEndian.PutUint32(size, 64+4+4)
purp := signedMsg[4:8]
@@ -467,7 +469,7 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
hMailbox := util.Base32CrockfordEncode(h.Sum(nil))
pendingRegistration.HashedSigningKey = hMailbox
// Round to the nearest multiple of a month
- reqExpiration := time.Unix(msg.MailboxMetadata.Expiration, 0)
+ reqExpiration := time.Unix(int64(msg.MailboxMetadata.Expiration.Seconds), 0)
now := time.Now()
reqDuration := reqExpiration.Sub(now).Round(monthDuration)
err = GetMailboxMetadataFromDatabaseBySigningKey(m.DB, ®istrationEntry, hMailbox)
@@ -483,12 +485,13 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
} else {
// Entry does not yet exist, add but immediately expire it
registrationEntry = msg.MailboxMetadata
- registrationEntry.Expiration = time.Now().Unix() - 1
+ registrationEntry.Expiration.Seconds = uint64(time.Now().Unix() - 1)
hAddr := sha512.New()
hAddr.Write(pk)
registrationEntry.HashedSigningKey = util.Base32CrockfordEncode(hAddr.Sum(nil))
err = InsertMailboxRegistrationIntoDatabase(m.DB, ®istrationEntry)
if nil != err {
+ m.Logf(LogError, "%v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -500,11 +503,13 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
pendingRegistration.Duration = reqDuration.Microseconds()
err = InsertPendingRegistrationIntoDatabase(m.DB, &pendingRegistration)
if nil != err {
+ m.Logf(LogError, "Error inserting pending registration: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = GetPendingRegistrationFromDatabaseBySigningKey(m.DB, &pendingRegistration, hMailbox)
if nil != err {
+ m.Logf(LogError, "Error getting pending registration: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -515,7 +520,7 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
reqDuration,
monthDuration)
if err != nil {
- fmt.Println(err)
+ m.Logf(LogError, "Error calculating cost: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -524,7 +529,7 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
// Add new order
orderID, newOrderErr := m.Merchant.AddNewOrder(*cost, "Mailbox registration", m.BaseURL)
if newOrderErr != nil {
- m.Logf(LogError, "%v", newOrderErr)
+ m.Logf(LogError, "Error adding order: %v", newOrderErr)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -538,13 +543,13 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
if paytoErr != nil {
fmt.Println(paytoErr)
w.WriteHeader(http.StatusInternalServerError)
- m.Logf(LogError, "%s\n", paytoErr.Error())
+ m.Logf(LogError, "Error checking if order is paid: %s\n", paytoErr.Error())
return
}
if len(payto) != 0 {
err = UpdatePendingRegistrationOrderIdInDatabase(m.DB, &pendingRegistration)
if err != nil {
- fmt.Println(err)
+ m.Logf(LogError, "Error updating pending registration: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -554,10 +559,16 @@ func (m *Mailbox) registerMailboxResponse(w http.ResponseWriter, r *http.Request
}
}
// Update expiration time of registration.
- registrationEntry.Expiration += int64(reqDuration.Seconds())
+ registrationEntry.Expiration.Seconds += uint64(reqDuration.Seconds())
_, err = DeletePendingRegistrationFromDatabase(m.DB, &pendingRegistration)
+ if nil != err {
+ m.Logf(LogError, "Error deleting pending registration: %v\n", err)
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
err = UpdateMailboxExpirationInDatabase(m.DB, ®istrationEntry)
if nil != err {
+ m.Logf(LogError, "Error updating mailbox registration: %v\n", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -579,7 +590,7 @@ func (m *Mailbox) checkPendingRegistrationUpdates(hMailbox string) {
}
_, err = DeletePendingRegistrationFromDatabase(m.DB, &pendingEntry)
if nil != err {
- m.Logf(LogInfo, "%v\n", err)
+ m.Logf(LogInfo, "Error deleting pending registration: %v\n", err)
}
return
}
@@ -589,14 +600,14 @@ func (m *Mailbox) checkPendingRegistrationUpdates(hMailbox string) {
err = GetMailboxMetadataFromDatabaseBySigningKey(m.DB, ®istrationEntry, hMailbox)
if err == nil {
m.Logf(LogDebug, "Adding %d seconds to entry expiration", pendingEntry.Duration)
- registrationEntry.Expiration += pendingEntry.Duration
+ registrationEntry.Expiration.Seconds += uint64(pendingEntry.Duration)
err = UpdateMailboxExpirationInDatabase(m.DB, ®istrationEntry)
if nil != err {
- m.Logf(LogInfo, "%v\n", err)
+ m.Logf(LogInfo, "Error updating mailbox expiration: %v\n", err)
}
_, err = DeletePendingRegistrationFromDatabase(m.DB, &pendingEntry)
if nil != err {
- m.Logf(LogInfo, "%v\n", err)
+ m.Logf(LogInfo, "Error deleting pending registration: %v\n", err)
}
}
return
@@ -666,12 +677,14 @@ func (m *Mailbox) deleteMessagesResponse(w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusNotFound)
return
}
- num, err := DeleteInboxEntryFromSerialFromDatabase(m.DB, &entry)
+ m.Logf(LogError, "Deleting from entry %v up to %d messages\n", entry, count)
+ num, err := DeleteInboxEntryFromDatabaseBySerial(m.DB, &entry, count)
if err != nil {
+ m.Logf(LogDebug, "Failed to delete messages: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
- m.Logf(LogDebug, "Found matching ID, deleted %d messages", num)
+ m.Logf(LogDebug, "Found matching ID (serial: %d), deleted %d messages", entry.Serial, num)
w.WriteHeader(http.StatusNoContent)
}
diff --git a/sql/taler-mailbox-0001.sql b/sql/taler-mailbox-0001.sql
@@ -33,9 +33,9 @@ SET search_path TO taler_mailbox;
---------------- Entries ---------------------------
CREATE TABLE IF NOT EXISTS inbox_entries
- (entry_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ (serial BIGSERIAL PRIMARY KEY
+ ,hashed_signing_key BYTEA
,body BYTEA NOT NULL
- ,hashed_signing_key BYTEA NOT NULL
);
COMMENT ON TABLE inbox_entries
IS 'Mailbox entries (messages)';
@@ -45,25 +45,26 @@ COMMENT ON COLUMN inbox_entries.hashed_signing_key
---------------- Validations ---------------------------
CREATE TABLE IF NOT EXISTS mailbox_metadata
- (mailbox_metadata_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ (serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
,hashed_signing_key BYTEA NOT NULL
,signing_key BYTEA NOT NULL
,signing_key_type BYTEA NOT NULL
,encryption_key BYTEA NOT NULL
,encryption_key_type BYTEA NOT NULL
- ,expiration_ts INT8 NOT NULL
+ ,expiration INT8 NOT NULL
,kox_claim_proof BYTEA NOT NULL
);
COMMENT ON TABLE mailbox_metadata
IS 'Mailbox configurations / instances';
CREATE TABLE IF NOT EXISTS pending_mailbox_registrations
- (pending_registrations_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ (serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
+ ,created_at INT8 NOT NULL
,hashed_signing_key BYTEA NOT NULL
,order_id BYTEA NOT NULL
,registration_duration INT8 NOT NULL
);
-COMMENT ON TABLE pending_mailbox_regitration
+COMMENT ON TABLE pending_mailbox_registrations
IS 'Pending mailbox registrations';