Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
irmago
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
IRMA
Github mirrors
irmago
Commits
6f601047
Commit
6f601047
authored
Nov 22, 2019
by
Hugo van de Pol
Committed by
Sietse Ringers
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for CanIssue
parent
7167a5be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
0 deletions
+145
-0
server/requestorserver/conf_test.go
server/requestorserver/conf_test.go
+145
-0
No files found.
server/requestorserver/conf_test.go
0 → 100644
View file @
6f601047
package
requestorserver
import
(
"encoding/json"
"testing"
"time"
irma
"github.com/privacybydesign/irmago"
"github.com/stretchr/testify/require"
)
func
createCredentialRequest
(
identifier
string
,
attributes
map
[
string
]
string
)
[]
*
irma
.
CredentialRequest
{
expiry
:=
irma
.
Timestamp
(
irma
.
FloorToEpochBoundary
(
time
.
Now
()
.
AddDate
(
1
,
0
,
0
)))
return
[]
*
irma
.
CredentialRequest
{
{
Validity
:
&
expiry
,
CredentialTypeID
:
irma
.
NewCredentialTypeIdentifier
(
identifier
),
Attributes
:
attributes
,
},
}
}
func
TestCanIssue
(
t
*
testing
.
T
)
{
confJSON
:=
`{
"requestors": {
"myapp": {
"disclose_perms": [ "irma-demo.MijnOverheid.ageLower.over18" ],
"sign_perms": [ "irma-demo.MijnOverheid.ageLower.*" ],
"issue_perms": [ "irma-demo.MijnOverheid.ageLower" ],
"auth_method": "token",
"key": "eGE2PSomOT84amVVdTU"
}
}
}`
t
.
Run
(
"allowed credential request"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
True
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
t
.
Run
(
"allowed credential request different attribute value"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over16"
:
"no"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
True
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
t
.
Run
(
"allowed credential request wrong requestor id"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"yourapp"
,
credentialRequest
)
require
.
False
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
t
.
Run
(
"allowed credential request wrong credential identifier"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageUpper"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
False
(
t
,
result
)
require
.
Equal
(
t
,
"irma-demo.MijnOverheid.ageUpper"
,
message
)
})
t
.
Run
(
"allowed credential request attribute wildcard"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
conf
.
Requestors
[
"myapp"
]
.
Issuing
[
0
]
=
"irma-demo.MijnOverheid.*"
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
True
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
t
.
Run
(
"allowed credential request issuer wildcard"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
conf
.
Requestors
[
"myapp"
]
.
Issuing
[
0
]
=
"irma-demo.*"
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
True
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
t
.
Run
(
"allowed credential request issuer wildcard with attribute name"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
conf
.
Requestors
[
"myapp"
]
.
Issuing
[
0
]
=
"irma-demo.*.ageLower"
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
False
(
t
,
result
)
require
.
Equal
(
t
,
"irma-demo.MijnOverheid.ageLower"
,
message
)
})
t
.
Run
(
"allowed credential request wrong issuer wildcard"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
conf
.
Requestors
[
"myapp"
]
.
Issuing
[
0
]
=
"irma-demo.**"
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
False
(
t
,
result
)
require
.
Equal
(
t
,
"irma-demo.MijnOverheid.ageLower"
,
message
)
})
t
.
Run
(
"allowed credential request single wildcard"
,
func
(
t
*
testing
.
T
)
{
var
conf
Configuration
require
.
NoError
(
t
,
json
.
Unmarshal
([]
byte
(
confJSON
),
&
conf
))
conf
.
Requestors
[
"myapp"
]
.
Issuing
[
0
]
=
"*"
credentialRequest
:=
createCredentialRequest
(
"irma-demo.MijnOverheid.ageLower"
,
map
[
string
]
string
{
"over12"
:
"yes"
})
result
,
message
:=
conf
.
CanIssue
(
"myapp"
,
credentialRequest
)
require
.
True
(
t
,
result
)
require
.
Empty
(
t
,
message
)
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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