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) { ...@@ -26,7 +26,7 @@ func TestLogging(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+1) require.True(t, len(logs) == oldLogLength+1)
entry := logs[len(logs)-1] entry := logs[0]
require.NotNil(t, entry) require.NotNil(t, entry)
require.NoError(t, err) require.NoError(t, err)
issued, err := entry.GetIssuedCredentials(client.Configuration) issued, err := entry.GetIssuedCredentials(client.Configuration)
...@@ -36,6 +36,8 @@ func TestLogging(t *testing.T) { ...@@ -36,6 +36,8 @@ func TestLogging(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, disclosed) require.NotEmpty(t, disclosed)
time.Sleep(2 * time.Second)
// Do disclosure session // Do disclosure session
request = getDisclosureRequest(attrid) request = getDisclosureRequest(attrid)
sessionHelper(t, request, "verification", client) sessionHelper(t, request, "verification", client)
...@@ -43,20 +45,25 @@ func TestLogging(t *testing.T) { ...@@ -43,20 +45,25 @@ func TestLogging(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+2) require.True(t, len(logs) == oldLogLength+2)
entry = logs[len(logs)-1] entry = logs[0]
require.NotNil(t, entry) require.NotNil(t, entry)
require.NoError(t, err) require.NoError(t, err)
disclosed, err = entry.GetDisclosedCredentials(client.Configuration) disclosed, err = entry.GetDisclosedCredentials(client.Configuration)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, disclosed) 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 // Do signature session
request = getSigningRequest(attrid) request = getSigningRequest(attrid)
sessionHelper(t, request, "signature", client) sessionHelper(t, request, "signature", client)
logs, err = client.LoadLogs(time.Now(), 100) logs, err = client.LoadLogs(time.Now(), 100)
require.NoError(t, err) require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+3) require.True(t, len(logs) == oldLogLength+3)
entry = logs[len(logs)-1] entry = logs[0]
require.NotNil(t, entry) require.NotNil(t, entry)
require.NoError(t, err) require.NoError(t, err)
sig, err := entry.GetSignedMessage() sig, err := entry.GetSignedMessage()
......
...@@ -3,6 +3,7 @@ package irmaclient ...@@ -3,6 +3,7 @@ package irmaclient
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"math"
"os" "os"
"path/filepath" "path/filepath"
...@@ -128,7 +129,8 @@ func (s *storage) AddLogEntry(entry *LogEntry) error { ...@@ -128,7 +129,8 @@ func (s *storage) AddLogEntry(entry *LogEntry) error {
} }
func (s *storage) logEntryKey(entry *LogEntry) interface{} { 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 { func (s *storage) StorePreferences(prefs Preferences) error {
...@@ -205,9 +207,10 @@ func (s *storage) LoadKeyshareServers() (ksses map[irma.SchemeManagerIdentifier] ...@@ -205,9 +207,10 @@ func (s *storage) LoadKeyshareServers() (ksses map[irma.SchemeManagerIdentifier]
} }
func (s *storage) LoadLogs(before time.Time, max int) ([]*LogEntry, error) { func (s *storage) LoadLogs(before time.Time, max int) ([]*LogEntry, error) {
// Bolthold key uses inverted times, so before is inverted
var logs []*LogEntry var logs []*LogEntry
return logs, s.db.Find(&logs, 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