Commit c0fc4c6f authored by Ivar Derksen's avatar Ivar Derksen Committed by Sietse Ringers

Added legacy tests for irmaclient

parent c3b43386
......@@ -30,6 +30,7 @@ func checkError(t *testing.T, err error) {
var schemeServer *http.Server
var badServer *http.Server
var badServerCount int
var testStorageDir = "teststorage"
func StartSchemeManagerHttpServer() {
path := FindTestdataFolder(nil)
......@@ -108,7 +109,7 @@ func CreateTestStorage(t *testing.T) {
func SetupTestStorage(t *testing.T) {
CreateTestStorage(t)
path := FindTestdataFolder(t)
err := fs.CopyDirectory(filepath.Join(path, "teststorage"), filepath.Join(path, "storage", "test"))
err := fs.CopyDirectory(filepath.Join(path, testStorageDir), filepath.Join(path, "storage", "test"))
checkError(t, err)
}
......@@ -117,3 +118,7 @@ func PrettyPrint(t *testing.T, ob interface{}) string {
require.NoError(t, err)
return string(b)
}
func SetTestStorageDir(dir string) {
testStorageDir = dir
}
package irmaclient
import (
"github.com/privacybydesign/irmago/internal/test"
"testing"
)
func TestConvertingLegacyStorage(t *testing.T) {
test.SetTestStorageDir("legacy_teststorage")
// Test all tests in this file with legacy storage too
t.Run("TestVerify", TestVerify)
t.Run("TestStorageDeserialization", TestStorageDeserialization)
t.Run("TestCandidates", TestCandidates)
t.Run("TestCandidateConjunctionOrder", TestCandidateConjunctionOrder)
t.Run("TestCredentialRemoval", TestCredentialRemoval)
t.Run("TestWrongSchemeManager", TestWrongSchemeManager)
t.Run("TestCredentialInfoListNewAttribute", TestCredentialInfoListNewAttribute)
// TestFreshStorage is not needed, because this test does not use an existing storage
t.Run("TestKeyshareEnrollmentRemoval", TestKeyshareEnrollmentRemoval)
t.Run("TestUpdatePreferences", TestUpdatePreferences)
test.SetTestStorageDir("teststorage")
}
......@@ -3,6 +3,7 @@ package irmaclient
import (
"encoding/json"
"errors"
"github.com/privacybydesign/irmago/internal/fs"
"os"
"path/filepath"
"testing"
......@@ -250,6 +251,19 @@ func TestCredentialRemoval(t *testing.T) {
cred, err = client.credential(id2, 0)
require.NoError(t, err)
require.Nil(t, cred)
// Also check whether credential is removed after reloading the storage
err = client.storage.db.Close()
require.NoError(t, err)
client, err = New(
filepath.Join("..", "testdata", "storage", "test"),
filepath.Join("..", "testdata", "irma_configuration"),
&TestClientHandler{t: t},
)
require.NoError(t, err)
cred, err = client.credential(id2, 0)
require.NoError(t, err)
require.Nil(t, cred)
}
func TestWrongSchemeManager(t *testing.T) {
......@@ -295,6 +309,58 @@ func TestCredentialInfoListNewAttribute(t *testing.T) {
require.Fail(t, "studentCard credential not found")
}
func TestFreshStorage(t *testing.T) {
test.CreateTestStorage(t)
defer test.ClearTestStorage(t)
path := filepath.Join(test.FindTestdataFolder(t), "storage", "test")
err := fs.EnsureDirectoryExists(path)
require.NoError(t, err)
client, err := New(
filepath.Join("..", "testdata", "storage", "test"),
filepath.Join("..", "testdata", "irma_configuration"),
&TestClientHandler{t: t},
)
require.NoError(t, err)
require.NotNil(t, client)
}
func TestKeyshareEnrollmentRemoval(t *testing.T) {
client := parseStorage(t)
defer test.ClearTestStorage(t)
err := client.KeyshareRemove(irma.NewSchemeManagerIdentifier("test"))
require.NoError(t, err)
err = client.storage.db.Close()
require.NoError(t, err)
client, err = New(
filepath.Join("..", "testdata", "storage", "test"),
filepath.Join("..", "testdata", "irma_configuration"),
&TestClientHandler{t: t},
)
require.NoError(t, err)
require.NotContains(t, client.keyshareServers, "test")
}
func TestUpdatePreferences(t *testing.T) {
client := parseStorage(t)
defer test.ClearTestStorage(t)
client.SetCrashReportingPreference(!defaultPreferences.EnableCrashReporting)
client.applyPreferences()
err := client.storage.db.Close()
require.NoError(t, err)
client, err = New(
filepath.Join("..", "testdata", "storage", "test"),
filepath.Join("..", "testdata", "irma_configuration"),
&TestClientHandler{t: t},
)
require.NoError(t, err)
require.Equal(t, false, client.Preferences.EnableCrashReporting)
}
// ------
type TestClientHandler struct {
......
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