Commit e15c7b6d authored by Sietse Ringers's avatar Sietse Ringers

test: refactor: use unique directory per test that touches files

parent fcac30c3
......@@ -16,6 +16,7 @@ type TestClientHandler struct {
t *testing.T
c chan error
revoked *irma.CredentialIdentifier
storage string
}
func (i *TestClientHandler) UpdateConfiguration(new *irma.IrmaIdentifierSet) {}
......
......@@ -27,7 +27,7 @@ func TestRequestorIssuanceKeyshareSession(t *testing.T) {
func TestKeyshareRegister(t *testing.T) {
client, handler := parseStorage(t)
defer test.ClearTestStorage(t)
defer test.ClearTestStorage(t, handler.storage)
require.NoError(t, client.KeyshareRemoveAll())
require.NoError(t, client.RemoveStorage())
......@@ -45,8 +45,8 @@ func TestKeyshareRegister(t *testing.T) {
// in a keyshare session of each session type.
// Use keyshareuser.sql to enroll the user at the keyshare server.
func TestKeyshareSessions(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
keyshareSessions(t, client)
}
......@@ -92,7 +92,7 @@ func TestKeyshareRevocation(t *testing.T) {
startRevocationServer(t, true)
defer stopRevocationServer()
client, handler := parseStorage(t)
defer test.ClearTestStorage(t)
defer test.ClearTestStorage(t, handler.storage)
testRevocation(t, revKeyshareTestAttr, client, handler)
})
......@@ -101,7 +101,7 @@ func TestKeyshareRevocation(t *testing.T) {
startRevocationServer(t, true)
defer stopRevocationServer()
client, handler := parseStorage(t)
defer test.ClearTestStorage(t)
defer test.ClearTestStorage(t, handler.storage)
testRevocation(t, revKeyshareTestAttr, client, handler)
testRevocation(t, revocationTestAttr, client, handler)
......
......@@ -12,8 +12,8 @@ func TestSessionUsingLegacyStorage(t *testing.T) {
test.SetTestStorageDir("client_legacy")
defer test.SetTestStorageDir("client")
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
// Test whether credential from legacy storage is still usable
idStudentCard := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
......@@ -29,7 +29,7 @@ func TestSessionUsingLegacyStorage(t *testing.T) {
// Re-open client
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
// Test whether credential is still there after the storage has been reloaded
sessionHelper(t, getDisclosureRequest(idRoot), "verification", client)
......
......@@ -9,7 +9,8 @@ import (
)
func TestLogging(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
logs, err := client.LoadNewestLogs(100)
oldLogLength := len(logs)
......@@ -27,7 +28,7 @@ func TestLogging(t *testing.T) {
// Check whether newly issued credential is actually stored
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
logs, err = client.LoadNewestLogs(100)
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+1)
......@@ -51,7 +52,7 @@ func TestLogging(t *testing.T) {
// Check whether log entry for disclosing session is actually stored
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
logs, err = client.LoadNewestLogs(100)
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+2)
......@@ -83,7 +84,7 @@ func TestLogging(t *testing.T) {
// Check whether log entry for signature session is actually stored
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
logs, err = client.LoadNewestLogs(100)
require.NoError(t, err)
require.True(t, len(logs) == oldLogLength+3)
......@@ -99,6 +100,4 @@ func TestLogging(t *testing.T) {
require.Equal(t, irma.ProofStatusValid, status)
require.NotEmpty(t, attrs)
require.Equal(t, attrid, attrs[0][0].Identifier)
test.ClearTestStorage(t)
}
......@@ -27,24 +27,25 @@ func init() {
func TestMain(m *testing.M) {
// Create HTTP server for scheme managers
test.StartSchemeManagerHttpServer()
defer test.StopSchemeManagerHttpServer()
test.CreateTestStorage(nil)
defer test.ClearTestStorage(nil)
retval := m.Run()
os.Exit(m.Run())
test.StopSchemeManagerHttpServer()
test.ClearAllTestStorage()
os.Exit(retval)
}
func parseStorage(t *testing.T) (*irmaclient.Client, *TestClientHandler) {
test.SetupTestStorage(t)
return parseExistingStorage(t)
storage := test.SetupTestStorage(t)
return parseExistingStorage(t, storage)
}
func parseExistingStorage(t *testing.T) (*irmaclient.Client, *TestClientHandler) {
handler := &TestClientHandler{t: t, c: make(chan error)}
func parseExistingStorage(t *testing.T, storage string) (*irmaclient.Client, *TestClientHandler) {
handler := &TestClientHandler{t: t, c: make(chan error), storage: storage}
path := test.FindTestdataFolder(t)
client, err := irmaclient.New(
filepath.Join(path, "tmp", "client"),
filepath.Join(storage, "client"),
filepath.Join(path, "irma_configuration"),
handler,
)
......@@ -203,8 +204,9 @@ func getJwt(t *testing.T, request irma.SessionRequest, sessiontype string, alg j
func sessionHelper(t *testing.T, request irma.SessionRequest, sessiontype string, client *irmaclient.Client) {
if client == nil {
client, _ = parseStorage(t)
defer test.ClearTestStorage(t)
var handler *TestClientHandler
client, handler = parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
}
if TestType == "irmaserver" || TestType == "irmaserver-jwt" || TestType == "irmaserver-hmac-jwt" {
......
......@@ -25,8 +25,9 @@ func createManualSessionHandler(t *testing.T, client *irmaclient.Client) *Manual
func manualSessionHelper(t *testing.T, client *irmaclient.Client, h *ManualTestHandler, request, verifyAs irma.SessionRequest, corrupt bool) ([][]*irma.DisclosedAttribute, irma.ProofStatus) {
if client == nil {
client, _ = parseStorage(t)
defer test.ClearTestStorage(t)
var handler *TestClientHandler
client, handler = parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
}
bts, err := json.Marshal(request)
......@@ -110,8 +111,8 @@ func TestManualSessionInvalidAttributeValue(t *testing.T) {
}
func TestManualSessionMultiProof(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
// First, we need to issue an extra credential (BSN)
sessionHelper(t, getMultipleIssuanceRequest(), "issue", client)
......
......@@ -42,8 +42,9 @@ func processOptions(options ...sessionOption) sessionOption {
func requestorSessionHelper(t *testing.T, request irma.SessionRequest, client *irmaclient.Client, options ...sessionOption) *requestorSessionResult {
if client == nil {
client, _ = parseStorage(t)
defer test.ClearTestStorage(t)
var handler *TestClientHandler
client, handler = parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
}
opts := processOptions(options...)
......@@ -133,7 +134,8 @@ func TestRequestorDoubleGET(t *testing.T) {
}
func TestRequestorSignatureSession(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
var serverResult *requestorSessionResult
......@@ -256,7 +258,8 @@ func testRequestorIssuance(t *testing.T, keyshare bool, client *irmaclient.Clien
}
func TestConDisCon(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
ir := getMultipleIssuanceRequest()
ir.Credentials = append(ir.Credentials, &irma.CredentialRequest{
Validity: ir.Credentials[0].Validity,
......@@ -295,7 +298,8 @@ func TestConDisCon(t *testing.T) {
}
func TestOptionalDisclosure(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
university := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.university")
studentid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
......
......@@ -100,7 +100,7 @@ func TestRevocationAll(t *testing.T) {
startRevocationServer(t, true)
defer stopRevocationServer()
client, handler := parseStorage(t)
defer test.ClearTestStorage(t)
defer test.ClearTestStorage(t, handler.storage)
testRevocation(t, revocationTestAttr, client, handler)
})
......@@ -116,7 +116,8 @@ func TestRevocationAll(t *testing.T) {
irmaServer = revocationServer
// issue a MijnOverheid.root instance with revocation enabled
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
request := revocationIssuanceRequest(t, revocationTestCred)
result := requestorSessionHelper(t, request, client, sessionOptionReuseServer)
require.Nil(t, result.Err)
......@@ -141,8 +142,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("AttributeBasedSignature", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t)
client, handler := revocationSetup(t)
defer test.ClearTestStorage(t, handler.storage)
defer stopRevocationServer()
request := revocationSigRequest()
......@@ -161,8 +162,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("VerifyAttributeBasedSignature", func(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
j := `{"@context":"https://irma.app/ld/signature/v2","signature":[{"c":"It0yT9OjFotXN0tUMZKaEo43WOugqv6GVlG0/WP03jE=","A":"WkB+1nj1vT5kdq7Q9hjoNlndvGtKoaLB/Ugs0rvjqMYBhCgXq19h/5ThesxLysVH15yPbVh+rlaZRYWfqKRvXs1z4aBhcHi+1hBB1JXENAnBpdfEQvZtzfz5I1fOIqEFkY+5kU6t7wkGj4QM7OhjHsquihoCnTT/vp6VIpYZnfI=","e_response":"wL+gwLa/myLy8HdilGKor4/Kfake1PvY0ZYfZyY4LZiO41hLC17MD6vYSTrsblkzuWO6ai3WsCIW","v_response":"DI3bQp04GNAIF7ylUqElTTwh4aLuytQOzFYVSGwtzlX8YGxsUZzOaLo0iCc2MKtqCiYBJp1LsQNW9f1lKub31ML2Xu53wYw99tGuqngl1wJaqHI6rQCSLlxTgyXzj0CJ6SXNkWEIBFpPcauMLnRG4eD20WtQ8oyFHQjfRrm0hZKMNlqb8CQOdDZNL8POnUHlap9FhFrM7IVCjUuOf8XHtgXo5PaFh7Gzj1dkyZKdofvM51hVvLi4T+qf4b9F5XZV4b1fVmmU70Sm/BA3eaonXv67vk5XBb8XW7cbLGtUqtg8tO/T5Cpdnw/fGGn0g61CJ11RmuEqbFa0uwp/rhIs","a_responses":{"0":"dBDhQm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QKgtPKNoWhX0k=","pk":2}}}],"indices":[[{"cred":0,"attr":2}]],"nonce":"OkdD8pg642lA3m7uCjW7Xw==","context":"AQ==","message":"message","timestamp":{"Time":1582816270,"ServerUrl":"https://keyshare.privacybydesign.foundation/atumd/","Sig":{"Alg":"ed25519","Data":"8E/Nj/acMLe8Xbn5IKWAoivS9xVRf7oPr0HmxmhGQ8TqurjIWyEuMdSTRZNORKjDATLjDrTHA6bL5UK2roxCCQ==","PublicKey":"MKdXxJxEWPRIwNP7SuvP0J/M/NV51VZvqCyO+7eDwJ8="}}}`
......@@ -214,8 +215,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("NoKnownAccumulator", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t)
client, handler := revocationSetup(t)
defer test.ClearTestStorage(t, handler.storage)
// stop revocation server so the verifier cannot fetch revocation state
stopRevocationServer()
......@@ -227,8 +228,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("OtherAccumulator", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t)
client, handler := revocationSetup(t)
defer test.ClearTestStorage(t, handler.storage)
defer stopRevocationServer()
// Prepare key material
......@@ -307,8 +308,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("ClientSessionServerUpdate", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t)
client, handler := revocationSetup(t)
defer test.ClearTestStorage(t, handler.storage)
defer stopRevocationServer()
conf := revocationConfiguration.IrmaConfiguration.Revocation
......@@ -325,8 +326,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("ClientAutoServerUpdate", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t) // revocation server is stopped manually below
client, handler := revocationSetup(t) // revocation server is stopped manually below
defer test.ClearTestStorage(t, handler.storage)
// Advance the accumulator by performing a few revocations
conf := revocationConfiguration.IrmaConfiguration.Revocation
......@@ -363,10 +364,10 @@ func TestRevocationAll(t *testing.T) {
t.Run("SameIrmaServer", func(t *testing.T) {
StartIrmaServer(t, false)
defer StopIrmaServer()
defer test.ClearTestStorage(t)
// issue a credential, populating irmaServer's revocation memdb
client, _ := revocationSetup(t, sessionOptionReuseServer)
client, handler := revocationSetup(t, sessionOptionReuseServer)
defer test.ClearTestStorage(t, handler.storage)
defer stopRevocationServer()
// disable serving revocation updates in revocation server
......@@ -488,8 +489,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("RevocationTolerance", func(t *testing.T) {
defer test.ClearTestStorage(t)
client, _ := revocationSetup(t)
client, handler := revocationSetup(t)
defer test.ClearTestStorage(t, handler.storage)
defer stopRevocationServer()
start := time.Now()
......@@ -550,7 +551,8 @@ func TestRevocationAll(t *testing.T) {
})
t.Run("NonRevocationAwareCredential", func(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
// Start irma server and hackily temporarily disable revocation for our credtype
// by editing its irma.Configuration instance
......@@ -637,7 +639,7 @@ func revocationSession(t *testing.T, client *irmaclient.Client, request irma.Ses
}
// revocationSetup sets up an irmaclient with a revocation-enabled credential, constants, and revocation key material.
func revocationSetup(t *testing.T, options ...sessionOption) (*irmaclient.Client, irmaclient.ClientHandler) {
func revocationSetup(t *testing.T, options ...sessionOption) (*irmaclient.Client, *TestClientHandler) {
startRevocationServer(t, true)
// issue a MijnOverheid.root instance with revocation enabled
......
......@@ -92,6 +92,7 @@ var IrmaServerConfiguration = &requestorserver.Configuration{
Configuration: &server.Configuration{
URL: "http://localhost:48682/irma",
Logger: logger,
DisableSchemesUpdate: true,
SchemesPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
RevocationSettings: irma.RevocationSettings{
......@@ -107,6 +108,7 @@ var JwtServerConfiguration = &requestorserver.Configuration{
Configuration: &server.Configuration{
URL: "http://localhost:48682/irma",
Logger: logger,
DisableSchemesUpdate: true,
SchemesPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
RevocationSettings: irma.RevocationSettings{
......
......@@ -66,14 +66,15 @@ func TestMultipleIssuanceSession(t *testing.T) {
}
func TestDefaultCredentialValidity(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
request := getIssuanceRequest(true)
sessionHelper(t, request, "issue", client)
}
func TestIssuanceDisclosureEmptyAttributes(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
req := getNameIssuanceRequest()
sessionHelper(t, req, "issue", client)
......@@ -98,8 +99,8 @@ func TestIssuanceOptionalSetAttributes(t *testing.T) {
}
func TestIssuanceSameAttributesNotSingleton(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
prevLen := len(client.CredentialInfoList())
......@@ -112,13 +113,13 @@ func TestIssuanceSameAttributesNotSingleton(t *testing.T) {
// Also check whether this is actually stored
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
require.Equal(t, prevLen+1, len(client.CredentialInfoList()))
}
func TestLargeAttribute(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
require.NoError(t, client.RemoveStorage())
......@@ -130,8 +131,8 @@ func TestLargeAttribute(t *testing.T) {
}
func TestIssuanceSingletonCredential(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
credid := irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.singleton")
request := getIssuanceRequest(false)
......@@ -155,14 +156,14 @@ func TestIssuanceSingletonCredential(t *testing.T) {
// Also check whether this is actually stored
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
require.NotNil(t, client.Attributes(credid, 0))
require.Nil(t, client.Attributes(credid, 1))
}
func TestUnsatisfiableDisclosureSession(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
request := irma.NewDisclosureRequest()
request.Disclose = irma.AttributeConDisCon{
......@@ -209,8 +210,8 @@ indicates the sign of the integer. In Go this is not the case. This resulted in
signatures being issued in the issuance protocol in two distinct ways, of which we test here
that they have been fixed. */
func TestAttributeByteEncoding(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
require.NoError(t, client.RemoveStorage())
/* After bitshifting the presence bit into the large attribute below, the most significant
......@@ -232,8 +233,8 @@ func TestAttributeByteEncoding(t *testing.T) {
}
func TestOutdatedClientIrmaConfiguration(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
// Remove old studentCard credential from before support for optional attributes, and issue a new one
require.NoError(t, client.RemoveStorage())
......@@ -247,8 +248,8 @@ func TestOutdatedClientIrmaConfiguration(t *testing.T) {
}
func TestDisclosureNewAttributeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
......@@ -284,8 +285,8 @@ func TestDisclosureNewAttributeUpdateSchemeManager(t *testing.T) {
}
func TestIssueNewAttributeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
......@@ -301,8 +302,8 @@ func TestIssueNewAttributeUpdateSchemeManager(t *testing.T) {
}
func TestIssueOptionalAttributeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
......@@ -345,7 +346,8 @@ func TestIssueOptionalAttributeUpdateSchemeManager(t *testing.T) {
}
func TestIssueNewCredTypeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
......@@ -358,12 +360,11 @@ func TestIssueNewCredTypeUpdateSchemeManager(t *testing.T) {
require.NoError(t, err)
require.Contains(t, client.Configuration.CredentialTypes, credid)
test.ClearTestStorage(t)
}
func TestDisclosureNewCredTypeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.level")
......@@ -376,12 +377,11 @@ func TestDisclosureNewCredTypeUpdateSchemeManager(t *testing.T) {
_, err := client.Configuration.Download(request)
require.NoError(t, err)
require.Contains(t, client.Configuration.CredentialTypes, credid)
test.ClearTestStorage(t)
}
func TestDisclosureNonexistingCredTypeUpdateSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
request := irma.NewDisclosureRequest(
irma.NewAttributeTypeIdentifier("irma-demo.baz.qux.abc"), // non-existing issuer
irma.NewAttributeTypeIdentifier("irma-demo.RU.foo.bar"), // non-existing credential
......@@ -414,8 +414,8 @@ func TestDisclosureNonexistingCredTypeUpdateSchemeManager(t *testing.T) {
// within this manager to test the autmatic downloading of credential definitions,
// issuers, and public keys.
func TestDownloadSchemeManager(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
// Remove irma-demo scheme manager as we need to test adding it
irmademo := irma.NewSchemeManagerIdentifier("irma-demo")
......@@ -444,7 +444,7 @@ func TestDownloadSchemeManager(t *testing.T) {
require.Contains(t, client.Configuration.Issuers, irma.NewIssuerIdentifier("irma-demo.RU"))
require.Contains(t, client.Configuration.CredentialTypes, irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard"))
basepath := filepath.Join(test.FindTestdataFolder(t), "tmp", "client", "irma_configuration", "irma-demo")
basepath := filepath.Join(handler.storage, "client", "irma_configuration", "irma-demo")
exists, err := fs.PathExists(filepath.Join(basepath, "description.xml"))
require.NoError(t, err)
require.True(t, exists)
......@@ -457,8 +457,8 @@ func TestDownloadSchemeManager(t *testing.T) {
}
func TestStaticQRSession(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
StartRequestorServer(JwtServerConfiguration)
defer StopRequestorServer()
......@@ -495,14 +495,14 @@ func TestStaticQRSession(t *testing.T) {
}
func TestIssuedCredentialIsStored(t *testing.T) {
client, _ := parseStorage(t)
defer test.ClearTestStorage(t)
client, handler := parseStorage(t)
defer test.ClearTestStorage(t, handler.storage)
issuanceRequest := getNameIssuanceRequest()
sessionHelper(t, issuanceRequest, "issue", client)
require.NoError(t, client.Close())
client, _ = parseExistingStorage(t)
client, handler = parseExistingStorage(t, handler.storage)
id := irma.NewAttributeTypeIdentifier("irma-demo.MijnOverheid.fullName.familyname")
sessionHelper(t, getDisclosureRequest(id), "verification", client)
}
......@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
......@@ -85,27 +86,33 @@ func FindTestdataFolder(t *testing.T) string {
return ""
}
// ClearTestStorage removes any output from previously run tests to ensure a clean state;
// some of the tests don't like it when there is existing state in storage.
func ClearTestStorage(t *testing.T) {
tmp := filepath.Join(FindTestdataFolder(t), "tmp")
checkError(t, os.RemoveAll(tmp))
checkError(t, fs.EnsureDirectoryExists(tmp))
// ClearTestStorage removes any output from previously run tests.
func ClearTestStorage(t *testing.T, storage string) {
checkError(t, os.RemoveAll(storage))
}
func CreateTestStorage(t *testing.T) {
ClearTestStorage(t)
tmp := filepath.Join(FindTestdataFolder(t), "tmp")
func ClearAllTestStorage() {
dir := filepath.Join(os.TempDir(), "irmatest*")
matches, err := filepath.Glob(dir)
checkError(nil, err)
for _, match := range matches {
checkError(nil, os.RemoveAll(match))
}
}
func CreateTestStorage(t *testing.T) string {
tmp, err := ioutil.TempDir("", "irmatest")
require.NoError(t, err)
checkError(t, fs.EnsureDirectoryExists(filepath.Join(tmp, "client")))
checkError(t, fs.EnsureDirectoryExists(filepath.Join(tmp, "revocation")))
checkError(t, fs.EnsureDirectoryExists(filepath.Join(tmp, "issuer")))
return tmp
}
func SetupTestStorage(t *testing.T) {
CreateTestStorage(t)
func SetupTestStorage(t *testing.T) string {
storage := CreateTestStorage(t)
path := FindTestdataFolder(t)