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
c837e1dd
Commit
c837e1dd
authored
Jul 27, 2018
by
Sietse Ringers
Browse files
Group test handlers in new file
parent
393b2dbd
Changes
4
Hide whitespace changes
Inline
Side-by-side
irmaclient/handlers_test.go
0 → 100644
View file @
c837e1dd
package
irmaclient
import
(
"encoding/json"
"testing"
"github.com/pkg/errors"
"github.com/privacybydesign/irmago"
)
type
TestClientHandler
struct
{
t
*
testing
.
T
c
chan
error
}
func
(
i
*
TestClientHandler
)
UpdateConfiguration
(
new
*
irma
.
IrmaIdentifierSet
)
{}
func
(
i
*
TestClientHandler
)
UpdateAttributes
()
{}
func
(
i
*
TestClientHandler
)
EnrollmentSuccess
(
manager
irma
.
SchemeManagerIdentifier
)
{
select
{
case
i
.
c
<-
nil
:
// nop
default
:
// nop
}
}
func
(
i
*
TestClientHandler
)
EnrollmentFailure
(
manager
irma
.
SchemeManagerIdentifier
,
err
error
)
{
select
{
case
i
.
c
<-
err
:
// nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinSuccess
(
manager
irma
.
SchemeManagerIdentifier
)
{
select
{
case
i
.
c
<-
nil
:
// nop
default
:
// nop
}
}
func
(
i
*
TestClientHandler
)
ChangePinFailure
(
manager
irma
.
SchemeManagerIdentifier
,
err
error
)
{
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinIncorrect
(
manager
irma
.
SchemeManagerIdentifier
,
attempts
int
)
{
err
:=
errors
.
New
(
"incorrect pin"
)
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
timeout
int
)
{
err
:=
errors
.
New
(
"blocked account"
)
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
type
TestHandler
struct
{
t
*
testing
.
T
c
chan
*
SessionResult
client
*
Client
}
func
(
th
TestHandler
)
KeyshareEnrollmentIncomplete
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareEnrollmentIncomplete"
)})
}
func
(
th
TestHandler
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareBlocked"
)})
}
func
(
th
TestHandler
)
KeyshareEnrollmentMissing
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
KeyshareEnrollmentDeleted
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Keyshare enrollment deleted for %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
StatusUpdate
(
action
irma
.
Action
,
status
irma
.
Status
)
{}
func
(
th
TestHandler
)
Success
(
result
string
)
{
th
.
c
<-
nil
}
func
(
th
TestHandler
)
Cancelled
()
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Cancelled"
)})
}
func
(
th
TestHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
th
.
t
.
Logf
(
"Session failed: %+v
\n
"
,
*
err
)
select
{
case
th
.
c
<-
&
SessionResult
{
Err
:
err
}
:
default
:
th
.
t
.
Fatal
(
err
)
}
}
func
(
th
TestHandler
)
UnsatisfiableRequest
(
serverName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
th
.
Failure
(
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorType
(
"UnsatisfiableRequest"
),
})
}
func
(
th
TestHandler
)
RequestVerificationPermission
(
request
irma
.
DisclosureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
choice
:=
&
irma
.
DisclosureChoice
{
Attributes
:
[]
*
irma
.
AttributeIdentifier
{},
}
var
candidates
[]
*
irma
.
AttributeIdentifier
for
_
,
disjunction
:=
range
request
.
Content
{
candidates
=
th
.
client
.
Candidates
(
disjunction
)
if
len
(
candidates
)
==
0
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"No disclosure candidates found"
)})
}
choice
.
Attributes
=
append
(
choice
.
Attributes
,
candidates
[
0
])
}
callback
(
true
,
choice
)
}
func
(
th
TestHandler
)
RequestIssuancePermission
(
request
irma
.
IssuanceRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
dreq
:=
irma
.
DisclosureRequest
{
BaseRequest
:
request
.
BaseRequest
,
Content
:
request
.
Disclose
,
}
th
.
RequestVerificationPermission
(
dreq
,
ServerName
,
callback
)
}
func
(
th
TestHandler
)
RequestSignaturePermission
(
request
irma
.
SignatureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
th
.
RequestVerificationPermission
(
request
.
DisclosureRequest
,
ServerName
,
callback
)
}
func
(
th
TestHandler
)
RequestSchemeManagerPermission
(
manager
*
irma
.
SchemeManager
,
callback
func
(
proceed
bool
))
{
callback
(
true
)
}
func
(
th
TestHandler
)
RequestPin
(
remainingAttempts
int
,
callback
PinHandler
)
{
callback
(
true
,
"12345"
)
}
type
SessionResult
struct
{
Err
error
Result
*
irma
.
SignedMessage
}
type
ManualSessionHandler
struct
{
TestHandler
}
func
(
th
*
ManualSessionHandler
)
Success
(
result
string
)
{
if
len
(
result
)
==
0
{
th
.
c
<-
nil
return
}
irmaSignedMessage
:=
&
irma
.
SignedMessage
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
result
),
irmaSignedMessage
);
err
!=
nil
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
err
,
ErrorType
:
irma
.
ErrorSerialization
,
})
return
}
th
.
c
<-
&
SessionResult
{
Result
:
irmaSignedMessage
,
}
}
func
(
th
*
ManualSessionHandler
)
RequestSignaturePermission
(
request
irma
.
SignatureRequest
,
requesterName
string
,
ph
PermissionHandler
)
{
var
attributes
[]
*
irma
.
AttributeIdentifier
for
_
,
cand
:=
range
request
.
Candidates
{
attributes
=
append
(
attributes
,
cand
[
0
])
}
c
:=
irma
.
DisclosureChoice
{
attributes
}
ph
(
true
,
&
c
)
}
func
(
th
*
ManualSessionHandler
)
RequestIssuancePermission
(
request
irma
.
IssuanceRequest
,
issuerName
string
,
ph
PermissionHandler
)
{
ph
(
true
,
nil
)
}
// These handlers should not be called, fail test if they are called
func
(
th
*
ManualSessionHandler
)
RequestSchemeManagerPermission
(
manager
*
irma
.
SchemeManager
,
callback
func
(
proceed
bool
))
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Unexpected session type"
)})
}
func
(
th
*
ManualSessionHandler
)
RequestVerificationPermission
(
request
irma
.
DisclosureRequest
,
verifierName
string
,
ph
PermissionHandler
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Unexpected session type"
)})
}
irmaclient/irmaclient_test.go
View file @
c837e1dd
...
...
@@ -2,7 +2,6 @@ package irmaclient
import
(
"encoding/json"
"errors"
"math/big"
"os"
"testing"
...
...
@@ -27,56 +26,6 @@ func TestMain(m *testing.M) {
os
.
Exit
(
retCode
)
}
type
TestClientHandler
struct
{
t
*
testing
.
T
c
chan
error
}
func
(
i
*
TestClientHandler
)
UpdateConfiguration
(
new
*
irma
.
IrmaIdentifierSet
)
{}
func
(
i
*
TestClientHandler
)
UpdateAttributes
()
{}
func
(
i
*
TestClientHandler
)
EnrollmentSuccess
(
manager
irma
.
SchemeManagerIdentifier
)
{
select
{
case
i
.
c
<-
nil
:
// nop
default
:
// nop
}
}
func
(
i
*
TestClientHandler
)
EnrollmentFailure
(
manager
irma
.
SchemeManagerIdentifier
,
err
error
)
{
select
{
case
i
.
c
<-
err
:
// nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinSuccess
(
manager
irma
.
SchemeManagerIdentifier
)
{
select
{
case
i
.
c
<-
nil
:
// nop
default
:
// nop
}
}
func
(
i
*
TestClientHandler
)
ChangePinFailure
(
manager
irma
.
SchemeManagerIdentifier
,
err
error
)
{
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinIncorrect
(
manager
irma
.
SchemeManagerIdentifier
,
attempts
int
)
{
err
:=
errors
.
New
(
"incorrect pin"
)
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
(
i
*
TestClientHandler
)
ChangePinBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
timeout
int
)
{
err
:=
errors
.
New
(
"blocked account"
)
select
{
case
i
.
c
<-
err
:
//nop
default
:
i
.
t
.
Fatal
(
err
)
}
}
func
parseStorage
(
t
*
testing
.
T
)
*
Client
{
require
.
NoError
(
t
,
fs
.
CopyDirectory
(
"../testdata/teststorage"
,
"../testdata/storage/test"
))
manager
,
err
:=
New
(
...
...
irmaclient/manual_session_test.go
View file @
c837e1dd
...
...
@@ -6,21 +6,10 @@ import (
"testing"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/test"
)
type
ManualSessionHandler
struct
{
permissionHandler
PermissionHandler
pinHandler
PinHandler
t
*
testing
.
T
errorChannel
chan
*
irma
.
SessionError
resultChannel
chan
*
irma
.
SignatureProofResult
sigRequest
*
irma
.
SignatureRequest
// Request used to create signature
sigVerifyRequest
*
irma
.
SignatureRequest
// Request used to verify signature
}
var
client
*
Client
// Issue BSN credential using sessionHelper
...
...
@@ -286,82 +275,3 @@ func TestManualSessionInvalidProof(t *testing.T) {
}
test
.
ClearTestStorage
(
t
)
}
func
(
sh
*
ManualSessionHandler
)
Success
(
result
string
)
{
if
len
(
result
)
==
0
{
sh
.
errorChannel
<-
nil
return
}
// Make proof corrupt if we want to test invalid proofs
resultBytes
:=
corruptAndConvertProofString
(
result
)
irmaSignedMessage
:=
&
irma
.
SignedMessage
{}
if
err
:=
json
.
Unmarshal
(
resultBytes
,
irmaSignedMessage
);
err
!=
nil
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
err
,
ErrorType
:
irma
.
ErrorSerialization
,
}
return
}
go
func
()
{
sh
.
resultChannel
<-
irmaSignedMessage
.
Verify
(
client
.
Configuration
,
sh
.
sigVerifyRequest
)
}()
sh
.
errorChannel
<-
nil
}
func
(
sh
*
ManualSessionHandler
)
UnsatisfiableRequest
(
serverName
string
,
missingAttributes
irma
.
AttributeDisjunctionList
)
{
// This function is called from main thread, which blocks go channel, so need go routine here
go
func
()
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorType
(
"UnsatisfiableRequest"
),
}
}()
}
func
(
sh
*
ManualSessionHandler
)
StatusUpdate
(
irmaAction
irma
.
Action
,
status
irma
.
Status
)
{}
func
(
sh
*
ManualSessionHandler
)
RequestPin
(
remainingAttempts
int
,
ph
PinHandler
)
{
ph
(
true
,
"12345"
)
}
func
(
sh
*
ManualSessionHandler
)
RequestSignaturePermission
(
request
irma
.
SignatureRequest
,
requesterName
string
,
ph
PermissionHandler
)
{
var
attributes
[]
*
irma
.
AttributeIdentifier
for
_
,
cand
:=
range
request
.
Candidates
{
attributes
=
append
(
attributes
,
cand
[
0
])
}
c
:=
irma
.
DisclosureChoice
{
attributes
}
ph
(
true
,
&
c
)
}
func
(
sh
*
ManualSessionHandler
)
RequestIssuancePermission
(
request
irma
.
IssuanceRequest
,
issuerName
string
,
ph
PermissionHandler
)
{
ph
(
true
,
nil
)
}
// These handlers should not be called, fail test if they are called
func
(
sh
*
ManualSessionHandler
)
Cancelled
()
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Session was cancelled"
)}
}
func
(
sh
*
ManualSessionHandler
)
MissingKeyshareEnrollment
(
manager
irma
.
SchemeManagerIdentifier
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())}
}
func
(
sh
*
ManualSessionHandler
)
RequestSchemeManagerPermission
(
manager
*
irma
.
SchemeManager
,
callback
func
(
proceed
bool
))
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Unexpected session type"
)}
}
func
(
sh
*
ManualSessionHandler
)
RequestVerificationPermission
(
request
irma
.
DisclosureRequest
,
verifierName
string
,
ph
PermissionHandler
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"Unexpected session type"
)}
}
func
(
sh
*
ManualSessionHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
fmt
.
Println
(
err
.
Err
)
sh
.
errorChannel
<-
err
}
func
(
sh
*
ManualSessionHandler
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareBlocked"
)}
}
func
(
sh
*
ManualSessionHandler
)
KeyshareEnrollmentIncomplete
(
manager
irma
.
SchemeManagerIdentifier
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareEnrollmentIncomplete"
)}
}
func
(
sh
*
ManualSessionHandler
)
KeyshareEnrollmentMissing
(
manager
irma
.
SchemeManagerIdentifier
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())}
}
func
(
sh
*
ManualSessionHandler
)
KeyshareEnrollmentDeleted
(
manager
irma
.
SchemeManagerIdentifier
)
{
sh
.
errorChannel
<-
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Keyshare enrollment deleted for %s"
,
manager
.
String
())}
}
irmaclient/session_test.go
View file @
c837e1dd
...
...
@@ -10,84 +10,11 @@ import (
"math/big"
"github.com/go-errors/errors"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/test"
"github.com/stretchr/testify/require"
)
type
TestHandler
struct
{
t
*
testing
.
T
c
chan
*
irma
.
SessionError
client
*
Client
}
func
(
th
TestHandler
)
KeyshareEnrollmentIncomplete
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareEnrollmentIncomplete"
)})
}
func
(
th
TestHandler
)
KeyshareBlocked
(
manager
irma
.
SchemeManagerIdentifier
,
duration
int
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"KeyshareBlocked"
)})
}
func
(
th
TestHandler
)
KeyshareEnrollmentMissing
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Missing keyshare server %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
KeyshareEnrollmentDeleted
(
manager
irma
.
SchemeManagerIdentifier
)
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
Errorf
(
"Keyshare enrollment deleted for %s"
,
manager
.
String
())})
}
func
(
th
TestHandler
)
StatusUpdate
(
action
irma
.
Action
,
status
irma
.
Status
)
{}
func
(
th
TestHandler
)
Success
(
result
string
)
{
th
.
c
<-
nil
}
func
(
th
TestHandler
)
Cancelled
()
{
th
.
c
<-
&
irma
.
SessionError
{}
}
func
(
th
TestHandler
)
Failure
(
err
*
irma
.
SessionError
)
{
select
{
case
th
.
c
<-
err
:
default
:
th
.
t
.
Fatal
(
err
)
}
}
func
(
th
TestHandler
)
UnsatisfiableRequest
(
serverName
string
,
missing
irma
.
AttributeDisjunctionList
)
{
th
.
c
<-
&
irma
.
SessionError
{
ErrorType
:
irma
.
ErrorType
(
"UnsatisfiableRequest"
),
}
}
func
(
th
TestHandler
)
RequestVerificationPermission
(
request
irma
.
DisclosureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
choice
:=
&
irma
.
DisclosureChoice
{
Attributes
:
[]
*
irma
.
AttributeIdentifier
{},
}
var
candidates
[]
*
irma
.
AttributeIdentifier
for
_
,
disjunction
:=
range
request
.
Content
{
candidates
=
th
.
client
.
Candidates
(
disjunction
)
if
len
(
candidates
)
==
0
{
th
.
Failure
(
&
irma
.
SessionError
{
Err
:
errors
.
New
(
"No disclosure candidates found"
)})
}
choice
.
Attributes
=
append
(
choice
.
Attributes
,
candidates
[
0
])
}
callback
(
true
,
choice
)
}
func
(
th
TestHandler
)
RequestIssuancePermission
(
request
irma
.
IssuanceRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
dreq
:=
irma
.
DisclosureRequest
{
BaseRequest
:
request
.
BaseRequest
,
Content
:
request
.
Disclose
,
}
th
.
RequestVerificationPermission
(
dreq
,
ServerName
,
callback
)
}
func
(
th
TestHandler
)
RequestSignaturePermission
(
request
irma
.
SignatureRequest
,
ServerName
string
,
callback
PermissionHandler
)
{
th
.
RequestVerificationPermission
(
request
.
DisclosureRequest
,
ServerName
,
callback
)
}
func
(
th
TestHandler
)
RequestSchemeManagerPermission
(
manager
*
irma
.
SchemeManager
,
callback
func
(
proceed
bool
))
{
callback
(
true
)
}
func
(
th
TestHandler
)
RequestPin
(
remainingAttempts
int
,
callback
PinHandler
)
{
callback
(
true
,
"12345"
)
}
func
getDisclosureJwt
(
name
string
,
id
irma
.
AttributeTypeIdentifier
)
interface
{}
{
return
irma
.
NewServiceProviderJwt
(
name
,
&
irma
.
DisclosureRequest
{
Content
:
irma
.
AttributeDisjunctionList
([]
*
irma
.
AttributeDisjunction
{{
...
...
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