Commit 3b35bfd6 authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers
Browse files

Invert bolthold keys to achieve right sorting order + test

parent 563bd417
......@@ -26,7 +26,7 @@ func TestLogging(t *testing.T) {
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+1)
entry := logs[len(logs)-1]
entry := logs[0]
require.NotNil(t, entry)
require.NoError(t, err)
issued, err := entry.GetIssuedCredentials(client.Configuration)
......@@ -36,6 +36,8 @@ func TestLogging(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, disclosed)
time.Sleep(2 * time.Second)
// Do disclosure session
request = getDisclosureRequest(attrid)
sessionHelper(t, request, "verification", client)
......@@ -43,20 +45,25 @@ func TestLogging(t *testing.T) {
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+2)
entry = logs[len(logs)-1]
entry = logs[0]
require.NotNil(t, entry)
require.NoError(t, err)
disclosed, err = entry.GetDisclosedCredentials(client.Configuration)
require.NoError(t, err)
require.NotEmpty(t, disclosed)
// Test before parameter
logs, err = client.LoadLogs(time.Time(entry.Time), 100)
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+1)
// Do signature session
request = getSigningRequest(attrid)
sessionHelper(t, request, "signature", client)
logs, err = client.LoadLogs(time.Now(), 100)
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+3)
entry = logs[len(logs)-1]
entry = logs[0]
require.NotNil(t, entry)
require.NoError(t, err)
sig, err := entry.GetSignedMessage()
......
......@@ -3,6 +3,7 @@ package irmaclient
import (
"encoding/json"
"io/ioutil"
"math"
"os"
"path/filepath"
......@@ -128,7 +129,8 @@ func (s *storage) AddLogEntry(entry *LogEntry) error {
}
func (s *storage) logEntryKey(entry *LogEntry) interface{} {
return time.Time(entry.Time).UnixNano()
// Time is inverted to reverse sorting order
return math.MaxInt64 ^ time.Time(entry.Time).UnixNano()
}
func (s *storage) StorePreferences(prefs Preferences) error {
......@@ -205,9 +207,10 @@ func (s *storage) LoadKeyshareServers() (ksses map[irma.SchemeManagerIdentifier]
}
func (s *storage) LoadLogs(before time.Time, max int) ([]*LogEntry, error) {
// Bolthold key uses inverted times, so before is inverted
var logs []*LogEntry
return logs, s.db.Find(&logs,
bolthold.Where(bolthold.Key).Lt(before.UnixNano()).SortBy("Time").Reverse().Limit(max),
bolthold.Where(bolthold.Key).Gt(math.MaxInt64^before.UnixNano()).Limit(max),
)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment