Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
41996fd5
Commit
41996fd5
authored
Jan 22, 2020
by
Ivar Derksen
Committed by
Sietse Ringers
Feb 05, 2020
Browse files
Fixed some storage bugs and added tests
parent
5a60e273
Changes
6
Hide whitespace changes
Inline
Side-by-side
internal/sessiontest/legacy_test.go
View file @
41996fd5
...
...
@@ -21,7 +21,6 @@ func TestSessionUsingLegacyStorage(t *testing.T) {
require
.
NoError
(
t
,
err
)
// Test whether credential is still there
require
.
NoError
(
t
,
err
)
id
:=
irma
.
NewAttributeTypeIdentifier
(
"irma-demo.MijnOverheid.root.BSN"
)
sessionHelper
(
t
,
getDisclosureRequest
(
id
),
"verification"
,
client
)
}
internal/sessiontest/main_test.go
View file @
41996fd5
...
...
@@ -37,6 +37,10 @@ func TestMain(m *testing.M) {
func
parseStorage
(
t
*
testing
.
T
)
(
*
irmaclient
.
Client
,
*
TestClientHandler
)
{
test
.
SetupTestStorage
(
t
)
return
parseExistingStorage
(
t
)
}
func
parseExistingStorage
(
t
*
testing
.
T
)
(
*
irmaclient
.
Client
,
*
TestClientHandler
)
{
handler
:=
&
TestClientHandler
{
t
:
t
,
c
:
make
(
chan
error
)}
path
:=
test
.
FindTestdataFolder
(
t
)
client
,
err
:=
irmaclient
.
New
(
...
...
internal/sessiontest/session_test.go
View file @
41996fd5
...
...
@@ -109,6 +109,11 @@ func TestIssuanceSameAttributesNotSingleton(t *testing.T) {
req
=
getIssuanceRequest
(
false
)
sessionHelper
(
t
,
req
,
"issue"
,
client
)
require
.
Equal
(
t
,
prevLen
+
1
,
len
(
client
.
CredentialInfoList
()))
// Also check whether this is actually stored
require
.
NoError
(
t
,
client
.
Close
())
client
,
_
=
parseExistingStorage
(
t
)
require
.
Equal
(
t
,
prevLen
+
1
,
len
(
client
.
CredentialInfoList
()))
}
func
TestLargeAttribute
(
t
*
testing
.
T
)
{
...
...
@@ -140,6 +145,12 @@ func TestIssuanceSingletonCredential(t *testing.T) {
sessionHelper
(
t
,
request
,
"issue"
,
client
)
require
.
NotNil
(
t
,
client
.
Attributes
(
credid
,
0
))
require
.
Nil
(
t
,
client
.
Attributes
(
credid
,
1
))
// Also check whether this is actually stored
require
.
NoError
(
t
,
client
.
Close
())
client
,
_
=
parseExistingStorage
(
t
)
require
.
NotNil
(
t
,
client
.
Attributes
(
credid
,
0
))
require
.
Nil
(
t
,
client
.
Attributes
(
credid
,
1
))
}
func
TestUnsatisfiableDisclosureSession
(
t
*
testing
.
T
)
{
...
...
@@ -475,3 +486,16 @@ func TestStaticQRSession(t *testing.T) {
require
.
NoError
(
t
,
s
.
Shutdown
(
context
.
Background
()))
require
.
True
(
t
,
received
)
}
func
TestIssuedCredentialIsStored
(
t
*
testing
.
T
)
{
client
,
_
:=
parseStorage
(
t
)
defer
test
.
ClearTestStorage
(
t
)
issuanceRequest
:=
getNameIssuanceRequest
()
sessionHelper
(
t
,
issuanceRequest
,
"issue"
,
client
)
require
.
NoError
(
t
,
client
.
Close
())
client
,
_
=
parseExistingStorage
(
t
)
id
:=
irma
.
NewAttributeTypeIdentifier
(
"irma-demo.MijnOverheid.fullName.familyname"
)
sessionHelper
(
t
,
getDisclosureRequest
(
id
),
"verification"
,
client
)
}
irmaclient/client.go
View file @
41996fd5
...
...
@@ -209,7 +209,7 @@ func (client *Client) CredentialInfoList() irma.CredentialInfoList {
// addCredential adds the specified credential to the Client, saving its signature
// imediately, and optionally cm.attributes as well.
func
(
client
*
Client
)
addCredential
(
cred
*
credential
,
storeAttributes
bool
)
(
err
error
)
{
func
(
client
*
Client
)
addCredential
(
cred
*
credential
)
(
err
error
)
{
id
:=
irma
.
NewCredentialTypeIdentifier
(
""
)
if
cred
.
CredentialType
()
!=
nil
{
id
=
cred
.
CredentialType
()
.
Identifier
()
...
...
@@ -253,9 +253,7 @@ func (client *Client) addCredential(cred *credential, storeAttributes bool) (err
if
err
=
client
.
storage
.
StoreSignature
(
cred
);
err
!=
nil
{
return
}
if
storeAttributes
{
err
=
client
.
storage
.
StoreAttributes
(
id
,
client
.
attributes
[
id
])
}
err
=
client
.
storage
.
StoreAttributes
(
id
,
client
.
attributes
[
id
])
return
}
...
...
@@ -269,7 +267,7 @@ func generateSecretKey() (*secretKey, error) {
// Removal methods
func
(
client
*
Client
)
remove
(
id
irma
.
CredentialTypeIdentifier
,
index
int
,
store
now
bool
)
error
{
func
(
client
*
Client
)
remove
(
id
irma
.
CredentialTypeIdentifier
,
index
int
,
store
Log
bool
)
error
{
// Remove attributes
list
,
exists
:=
client
.
attributes
[
id
]
if
!
exists
||
index
>=
len
(
list
)
{
...
...
@@ -277,10 +275,9 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storen
}
attrs
:=
list
[
index
]
client
.
attributes
[
id
]
=
append
(
list
[
:
index
],
list
[
index
+
1
:
]
...
)
if
storenow
{
if
err
:=
client
.
storage
.
StoreAttributes
(
id
,
client
.
attributes
[
id
]);
err
!=
nil
{
return
err
}
if
err
:=
client
.
storage
.
StoreAttributes
(
id
,
client
.
attributes
[
id
]);
err
!=
nil
{
return
err
}
// Remove credential
...
...
@@ -299,7 +296,7 @@ func (client *Client) remove(id irma.CredentialTypeIdentifier, index int, storen
removed
:=
map
[
irma
.
CredentialTypeIdentifier
][]
irma
.
TranslatedString
{}
removed
[
id
]
=
attrs
.
Strings
()
if
store
now
{
if
store
Log
{
return
client
.
storage
.
AddLogEntry
(
&
LogEntry
{
Type
:
ActionRemoval
,
Time
:
irma
.
Timestamp
(
time
.
Now
()),
...
...
@@ -814,7 +811,7 @@ func (client *Client) ConstructCredentials(msg []*gabi.IssueSignatureMessage, re
if
err
!=
nil
{
return
err
}
if
err
=
client
.
addCredential
(
newcred
,
true
);
err
!=
nil
{
if
err
=
client
.
addCredential
(
newcred
);
err
!=
nil
{
return
err
}
}
...
...
irmaclient/irmaclient_test.go
View file @
41996fd5
...
...
@@ -29,6 +29,10 @@ func TestMain(m *testing.M) {
func
parseStorage
(
t
*
testing
.
T
)
*
Client
{
test
.
SetupTestStorage
(
t
)
return
parseExistingStorage
(
t
)
}
func
parseExistingStorage
(
t
*
testing
.
T
)
*
Client
{
client
,
err
:=
New
(
filepath
.
Join
(
".."
,
"testdata"
,
"storage"
,
"test"
),
filepath
.
Join
(
".."
,
"testdata"
,
"irma_configuration"
),
...
...
@@ -255,12 +259,7 @@ func TestCredentialRemoval(t *testing.T) {
// 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
)
client
=
parseExistingStorage
(
t
)
cred
,
err
=
client
.
credential
(
id2
,
0
)
require
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
cred
)
...
...
irmaclient/storage.go
View file @
41996fd5
...
...
@@ -116,7 +116,7 @@ func (s *storage) DeleteAllSignatures() error {
func
(
s
*
storage
)
StoreSignature
(
cred
*
credential
)
error
{
return
s
.
db
.
Update
(
func
(
tx
*
bbolt
.
Tx
)
error
{
return
s
.
TxStoreSignature
(
tx
,
cred
.
a
ttr
s
.
Hash
(),
cred
.
Signature
)
return
s
.
TxStoreSignature
(
tx
,
cred
.
A
ttr
ibuteList
()
.
Hash
(),
cred
.
Signature
)
})
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment