Commit 028c591d authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers
Browse files

Fix: also remove legacy storage on DeleteAll

parent be22b76e
......@@ -447,6 +447,9 @@ func (client *Client) RemoveStorage() error {
if err = client.storage.DeleteAll(); err != nil {
return err
}
if err = client.fileStorage.DeleteAll(); err != nil {
return err
}
// Client assumes there is always a secret key, so we have to load a new one
client.secretkey, err = client.storage.LoadSecretKey()
......
......@@ -20,4 +20,5 @@ func TestConvertingLegacyStorage(t *testing.T) {
// TestFreshStorage is not needed, because this test does not use an existing storage
t.Run("TestKeyshareEnrollmentRemoval", TestKeyshareEnrollmentRemoval)
t.Run("TestUpdatingStorage", TestUpdatingStorage)
t.Run("TestRemoveStorage", TestRemoveStorage)
}
......@@ -324,7 +324,11 @@ func TestRemoveStorage(t *testing.T) {
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
bucketsBefore := map[string]bool{"attrs": true, "sigs": true, "userdata": true, "logs": true} // Test storage has 1 log
// Check whether we have logs in storage to know whether the logs bucket is there
logs, err := client.LoadNewestLogs(1)
require.NoError(t, err)
bucketsBefore := map[string]bool{"attrs": true, "sigs": true, "userdata": true, "logs": len(logs) > 0}
bucketsAfter := map[string]bool{"attrs": false, "sigs": false, "userdata": true, "logs": false} // Userdata should hold a new secret key
old_sk := *client.secretkey
......
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"github.com/privacybydesign/gabi"
......@@ -134,3 +135,22 @@ func (f *fileStorage) LoadPreferences() (Preferences, error) {
func (f *fileStorage) LoadLogs() (logs []*LogEntry, err error) {
return logs, f.load(&logs, logsFile)
}
func (f *fileStorage) DeleteAll() error {
// Remove all legacy storage files
files := []string{skFile, attributesFile, kssFile, updatesFile, logsFile, preferencesFile}
for _, file := range files {
path := f.path(file)
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
return err
}
}
// Remove all legacy signatures
path := f.path(signaturesDir)
if err := os.RemoveAll(path); err != nil && !os.IsNotExist(err) {
return err
}
return nil
}
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