Commit c548e66f authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Update unit tests

parent d554ba44
...@@ -15,10 +15,6 @@ func TestMain(m *testing.M) { ...@@ -15,10 +15,6 @@ func TestMain(m *testing.M) {
test.StartSchemeManagerHttpServer() test.StartSchemeManagerHttpServer()
defer test.StopSchemeManagerHttpServer() defer test.StopSchemeManagerHttpServer()
TestType = "irmaserver-jwt"
StartIrmaServer(JwtServerConfiguration)
defer StopIrmaServer()
test.CreateTestStorage(nil) test.CreateTestStorage(nil)
defer test.ClearTestStorage(nil) defer test.ClearTestStorage(nil)
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/privacybydesign/irmago" "github.com/privacybydesign/irmago"
"github.com/privacybydesign/irmago/internal/fs"
"github.com/privacybydesign/irmago/internal/test" "github.com/privacybydesign/irmago/internal/test"
"github.com/privacybydesign/irmago/server" "github.com/privacybydesign/irmago/server"
"github.com/privacybydesign/irmago/server/irmarequestor" "github.com/privacybydesign/irmago/server/irmarequestor"
...@@ -23,25 +22,23 @@ func StartIrmaClientServer(t *testing.T) { ...@@ -23,25 +22,23 @@ func StartIrmaClientServer(t *testing.T) {
logger := logrus.New() logger := logrus.New()
logger.Level = logrus.WarnLevel logger.Level = logrus.WarnLevel
logger.Formatter = &logrus.TextFormatter{} logger.Formatter = &logrus.TextFormatter{}
cachepath := filepath.Join(testdata, "storage", "test", "cache")
fs.EnsureDirectoryExists(cachepath)
require.NoError(t, irmarequestor.Initialize(&server.Configuration{ require.NoError(t, irmarequestor.Initialize(&server.Configuration{
URL: "http://localhost:48680",
Logger: logger, Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"), IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"), IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
CachePath: cachepath,
})) }))
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/", irmarequestor.HttpHandlerFunc("/")) mux.HandleFunc("/", irmarequestor.HttpHandlerFunc())
irmaServer = &http.Server{Addr: ":48680", Handler: mux} irmaServer = &http.Server{Addr: ":48680", Handler: mux}
go func() { go func() {
irmaServer.ListenAndServe() _ = irmaServer.ListenAndServe()
}() }()
} }
func StopIrmaClientServer() { func StopIrmaClientServer() {
irmaServer.Close() _ = irmaServer.Close()
} }
func requestorSessionHelper(t *testing.T, request irma.SessionRequest) *server.SessionResult { func requestorSessionHelper(t *testing.T, request irma.SessionRequest) *server.SessionResult {
...@@ -58,7 +55,6 @@ func requestorSessionHelper(t *testing.T, request irma.SessionRequest) *server.S ...@@ -58,7 +55,6 @@ func requestorSessionHelper(t *testing.T, request irma.SessionRequest) *server.S
serverChan <- result serverChan <- result
}) })
require.NoError(t, err) require.NoError(t, err)
qr.URL = "http://localhost:48680/" + qr.URL
h := TestHandler{t, clientChan, client} h := TestHandler{t, clientChan, client}
j, err := json.Marshal(qr) j, err := json.Marshal(qr)
......
...@@ -36,6 +36,7 @@ func StopIrmaServer() { ...@@ -36,6 +36,7 @@ func StopIrmaServer() {
var IrmaServerConfiguration = &irmaserver.Configuration{ var IrmaServerConfiguration = &irmaserver.Configuration{
Configuration: &server.Configuration{ Configuration: &server.Configuration{
URL: "http://localhost:48682/irma",
Logger: logger, Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"), IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"), IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
...@@ -46,6 +47,7 @@ var IrmaServerConfiguration = &irmaserver.Configuration{ ...@@ -46,6 +47,7 @@ var IrmaServerConfiguration = &irmaserver.Configuration{
var JwtServerConfiguration = &irmaserver.Configuration{ var JwtServerConfiguration = &irmaserver.Configuration{
Configuration: &server.Configuration{ Configuration: &server.Configuration{
URL: "http://localhost:48682/irma",
Logger: logger, Logger: logger,
IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"), IrmaConfigurationPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"), IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
...@@ -58,7 +60,7 @@ var JwtServerConfiguration = &irmaserver.Configuration{ ...@@ -58,7 +60,7 @@ var JwtServerConfiguration = &irmaserver.Configuration{
Issuing: []string{"*"}, Issuing: []string{"*"},
}, },
Requestors: map[string]irmaserver.Requestor{ Requestors: map[string]irmaserver.Requestor{
"requestor1": irmaserver.Requestor{ "requestor1": {
AuthenticationMethod: irmaserver.AuthenticationMethodPublicKey, AuthenticationMethod: irmaserver.AuthenticationMethodPublicKey,
AuthenticationKey: filepath.Join(testdata, "jwtkeys", "requestor1.pem"), AuthenticationKey: filepath.Join(testdata, "jwtkeys", "requestor1.pem"),
}, },
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strings"
"testing" "testing"
"time" "time"
...@@ -108,7 +109,7 @@ func getCombinedIssuanceRequest(id irma.AttributeTypeIdentifier) *irma.IssuanceR ...@@ -108,7 +109,7 @@ func getCombinedIssuanceRequest(id irma.AttributeTypeIdentifier) *irma.IssuanceR
return request return request
} }
var TestType = "irmaserver" var TestType = "irmaserver-jwt"
func startSession(t *testing.T, request irma.SessionRequest, sessiontype string) (*irma.Qr, string) { func startSession(t *testing.T, request irma.SessionRequest, sessiontype string) (*irma.Qr, string) {
var qr irma.Qr var qr irma.Qr
...@@ -124,13 +125,11 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string) ...@@ -124,13 +125,11 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string)
case "irmaserver-jwt": case "irmaserver-jwt":
url := "http://localhost:48682" url := "http://localhost:48682"
err = irma.NewHTTPTransport(url).Post("session", &qr, getJwt(t, request, sessiontype, true)) err = irma.NewHTTPTransport(url).Post("session", &qr, getJwt(t, request, sessiontype, true))
token = qr.URL token = tokenFromURL(qr.URL)
qr.URL = url + "/irma/" + qr.URL
case "irmaserver": case "irmaserver":
url := "http://localhost:48682" url := "http://localhost:48682"
err = irma.NewHTTPTransport(url).Post("session", &qr, request) err = irma.NewHTTPTransport(url).Post("session", &qr, request)
token = qr.URL token = tokenFromURL(qr.URL)
qr.URL = url + "/irma/" + qr.URL
default: default:
t.Fatal("Invalid TestType") t.Fatal("Invalid TestType")
} }
...@@ -139,6 +138,14 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string) ...@@ -139,6 +138,14 @@ func startSession(t *testing.T, request irma.SessionRequest, sessiontype string)
return &qr, token 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 { func getJwt(t *testing.T, request irma.SessionRequest, sessiontype string, signed bool) string {
var jwtcontents irma.RequestorJwt var jwtcontents irma.RequestorJwt
var kid string var kid string
...@@ -180,6 +187,11 @@ func sessionHelper(t *testing.T, request irma.SessionRequest, sessiontype string ...@@ -180,6 +187,11 @@ func sessionHelper(t *testing.T, request irma.SessionRequest, sessiontype string
defer test.ClearTestStorage(t) defer test.ClearTestStorage(t)
} }
if TestType == "irmaserver" || TestType == "irmaserver-jwt" {
StartIrmaServer(JwtServerConfiguration)
defer StopIrmaServer()
}
qr, _ := startSession(t, request, sessiontype) qr, _ := startSession(t, request, sessiontype)
c := make(chan *SessionResult) c := make(chan *SessionResult)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment