Skip to content
GitLab
Menu
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
c548e66f
Commit
c548e66f
authored
Dec 22, 2018
by
Sietse Ringers
Browse files
Update unit tests
parent
d554ba44
Changes
4
Hide whitespace changes
Inline
Side-by-side
internal/sessiontest/main_test.go
View file @
c548e66f
...
...
@@ -15,10 +15,6 @@ func TestMain(m *testing.M) {
test
.
StartSchemeManagerHttpServer
()
defer
test
.
StopSchemeManagerHttpServer
()
TestType
=
"irmaserver-jwt"
StartIrmaServer
(
JwtServerConfiguration
)
defer
StopIrmaServer
()
test
.
CreateTestStorage
(
nil
)
defer
test
.
ClearTestStorage
(
nil
)
...
...
internal/sessiontest/requestor_test.go
View file @
c548e66f
...
...
@@ -8,7 +8,6 @@ import (
"github.com/Sirupsen/logrus"
"github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/fs"
"github.com/privacybydesign/irmago/internal/test"
"github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmarequestor"
...
...
@@ -23,25 +22,23 @@ func StartIrmaClientServer(t *testing.T) {
logger
:=
logrus
.
New
()
logger
.
Level
=
logrus
.
WarnLevel
logger
.
Formatter
=
&
logrus
.
TextFormatter
{}
cachepath
:=
filepath
.
Join
(
testdata
,
"storage"
,
"test"
,
"cache"
)
fs
.
EnsureDirectoryExists
(
cachepath
)
require
.
NoError
(
t
,
irmarequestor
.
Initialize
(
&
server
.
Configuration
{
URL
:
"http://localhost:48680"
,
Logger
:
logger
,
IrmaConfigurationPath
:
filepath
.
Join
(
testdata
,
"irma_configuration"
),
IssuerPrivateKeysPath
:
filepath
.
Join
(
testdata
,
"privatekeys"
),
CachePath
:
cachepath
,
}))
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/"
,
irmarequestor
.
HttpHandlerFunc
(
"/"
))
mux
.
HandleFunc
(
"/"
,
irmarequestor
.
HttpHandlerFunc
())
irmaServer
=
&
http
.
Server
{
Addr
:
":48680"
,
Handler
:
mux
}
go
func
()
{
irmaServer
.
ListenAndServe
()
_
=
irmaServer
.
ListenAndServe
()
}()
}
func
StopIrmaClientServer
()
{
irmaServer
.
Close
()
_
=
irmaServer
.
Close
()
}
func
requestorSessionHelper
(
t
*
testing
.
T
,
request
irma
.
SessionRequest
)
*
server
.
SessionResult
{
...
...
@@ -58,7 +55,6 @@ func requestorSessionHelper(t *testing.T, request irma.SessionRequest) *server.S
serverChan
<-
result
})
require
.
NoError
(
t
,
err
)
qr
.
URL
=
"http://localhost:48680/"
+
qr
.
URL
h
:=
TestHandler
{
t
,
clientChan
,
client
}
j
,
err
:=
json
.
Marshal
(
qr
)
...
...
internal/sessiontest/server_test.go
View file @
c548e66f
...
...
@@ -36,6 +36,7 @@ func StopIrmaServer() {
var
IrmaServerConfiguration
=
&
irmaserver
.
Configuration
{
Configuration
:
&
server
.
Configuration
{
URL
:
"http://localhost:48682/irma"
,
Logger
:
logger
,
IrmaConfigurationPath
:
filepath
.
Join
(
testdata
,
"irma_configuration"
),
IssuerPrivateKeysPath
:
filepath
.
Join
(
testdata
,
"privatekeys"
),
...
...
@@ -46,6 +47,7 @@ var IrmaServerConfiguration = &irmaserver.Configuration{
var
JwtServerConfiguration
=
&
irmaserver
.
Configuration
{
Configuration
:
&
server
.
Configuration
{
URL
:
"http://localhost:48682/irma"
,
Logger
:
logger
,
IrmaConfigurationPath
:
filepath
.
Join
(
testdata
,
"irma_configuration"
),
IssuerPrivateKeysPath
:
filepath
.
Join
(
testdata
,
"privatekeys"
),
...
...
@@ -58,7 +60,7 @@ var JwtServerConfiguration = &irmaserver.Configuration{
Issuing
:
[]
string
{
"*"
},
},
Requestors
:
map
[
string
]
irmaserver
.
Requestor
{
"requestor1"
:
irmaserver
.
Requestor
{
"requestor1"
:
{
AuthenticationMethod
:
irmaserver
.
AuthenticationMethodPublicKey
,
AuthenticationKey
:
filepath
.
Join
(
testdata
,
"jwtkeys"
,
"requestor1.pem"
),
},
...
...
internal/sessiontest/session_test.go
View file @
c548e66f
...
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"time"
...
...
@@ -108,7 +109,7 @@ func getCombinedIssuanceRequest(id irma.AttributeTypeIdentifier) *irma.IssuanceR
return
request
}
var
TestType
=
"irmaserver"
var
TestType
=
"irmaserver
-jwt
"
func
startSession
(
t
*
testing
.
T
,
request
irma
.
SessionRequest
,
sessiontype
string
)
(
*
irma
.
Qr
,
string
)
{
var
qr
irma
.
Qr
...
...
@@ -124,13 +125,11 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string)
case
"irmaserver-jwt"
:
url
:=
"http://localhost:48682"
err
=
irma
.
NewHTTPTransport
(
url
)
.
Post
(
"session"
,
&
qr
,
getJwt
(
t
,
request
,
sessiontype
,
true
))
token
=
qr
.
URL
qr
.
URL
=
url
+
"/irma/"
+
qr
.
URL
token
=
tokenFromURL
(
qr
.
URL
)
case
"irmaserver"
:
url
:=
"http://localhost:48682"
err
=
irma
.
NewHTTPTransport
(
url
)
.
Post
(
"session"
,
&
qr
,
request
)
token
=
qr
.
URL
qr
.
URL
=
url
+
"/irma/"
+
qr
.
URL
token
=
tokenFromURL
(
qr
.
URL
)
default
:
t
.
Fatal
(
"Invalid TestType"
)
}
...
...
@@ -139,6 +138,14 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string)
return
&
qr
,
token
}
func
tokenFromURL
(
url
string
)
string
{
parts
:=
strings
.
Split
(
url
,
"/"
)
if
len
(
parts
)
==
0
{
return
""
}
return
parts
[
len
(
parts
)
-
1
]
}
func
getJwt
(
t
*
testing
.
T
,
request
irma
.
SessionRequest
,
sessiontype
string
,
signed
bool
)
string
{
var
jwtcontents
irma
.
RequestorJwt
var
kid
string
...
...
@@ -180,6 +187,11 @@ func sessionHelper(t *testing.T, request irma.SessionRequest, sessiontype string
defer
test
.
ClearTestStorage
(
t
)
}
if
TestType
==
"irmaserver"
||
TestType
==
"irmaserver-jwt"
{
StartIrmaServer
(
JwtServerConfiguration
)
defer
StopIrmaServer
()
}
qr
,
_
:=
startSession
(
t
,
request
,
sessiontype
)
c
:=
make
(
chan
*
SessionResult
)
...
...
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