server_test.go 3.19 KB
Newer Older
1
2
3
package sessiontest

import (
4
	"net/http"
5
	"path/filepath"
6
	"testing"
7
8
9
	"time"

	"github.com/privacybydesign/irmago/internal/test"
Sietse Ringers's avatar
Sietse Ringers committed
10
11
	"github.com/privacybydesign/irmago/server"
	"github.com/privacybydesign/irmago/server/irmaserver"
12
	"github.com/sirupsen/logrus"
13
	"github.com/stretchr/testify/require"
14
15
)

16
var (
17
	httpServer     *http.Server
18
	irmaServer     *irmaserver.Server
19
20
	combinedServer *irmaserver.Server

21
22
23
	logger   = logrus.New()
	testdata = test.FindTestdataFolder(nil)
)
24

25
func init() {
26
	logger.Level = logrus.ErrorLevel
27
	logger.Formatter = &logrus.TextFormatter{}
28
}
29

30
func StartIrmaServer(configuration *irmaserver.Configuration) {
31
	go func() {
32
33
34
35
36
		var err error
		if combinedServer, err = irmaserver.New(configuration); err != nil {
			panic(err)
		}
		if err = combinedServer.Start(configuration); err != nil {
37
38
			panic("Starting server failed: " + err.Error())
		}
39
	}()
40
	time.Sleep(100 * time.Millisecond) // Give server time to start
41
42
}

Sietse Ringers's avatar
Sietse Ringers committed
43
func StopIrmaServer() {
44
45
46
47
48
49
50
51
52
53
54
	_ = combinedServer.Stop()
}

func StartIrmaClientServer(t *testing.T) {
	testdata := test.FindTestdataFolder(t)

	logger := logrus.New()
	logger.Level = logrus.WarnLevel
	logger.Formatter = &logrus.TextFormatter{}

	var err error
55
	irmaServer, err = irmaserver.New(&server.Configuration{
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
		URL:                   "http://localhost:48680",
		Logger:                logger,
		SchemesPath:           filepath.Join(testdata, "irma_configuration"),
		IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
	})

	require.NoError(t, err)

	mux := http.NewServeMux()
	mux.HandleFunc("/", irmaServer.HttpHandlerFunc())
	httpServer = &http.Server{Addr: ":48680", Handler: mux}
	go func() {
		_ = httpServer.ListenAndServe()
	}()
}

func StopIrmaClientServer() {
	_ = httpServer.Close()
74
75
}

76
77
var IrmaServerConfiguration = &irmaserver.Configuration{
	Configuration: &server.Configuration{
Sietse Ringers's avatar
Sietse Ringers committed
78
		URL:                   "http://localhost:48682/irma",
79
		Logger:                logger,
80
		SchemesPath:           filepath.Join(testdata, "irma_configuration"),
81
82
		IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
	},
83
	DisableRequestorAuthentication: true,
84
	Port: 48682,
85
86
}

87
88
var JwtServerConfiguration = &irmaserver.Configuration{
	Configuration: &server.Configuration{
Sietse Ringers's avatar
Sietse Ringers committed
89
		URL:                   "http://localhost:48682/irma",
90
		Logger:                logger,
91
		SchemesPath:           filepath.Join(testdata, "irma_configuration"),
92
93
94
		IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
	},
	Port: 48682,
95
	DisableRequestorAuthentication: false,
96
97
	MaxRequestAge:                  3,
	Permissions: irmaserver.Permissions{
98
99
100
101
102
		Disclosing: []string{"*"},
		Signing:    []string{"*"},
		Issuing:    []string{"*"},
	},
	Requestors: map[string]irmaserver.Requestor{
Sietse Ringers's avatar
Sietse Ringers committed
103
		"requestor1": {
104
105
			AuthenticationMethod:  irmaserver.AuthenticationMethodPublicKey,
			AuthenticationKeyFile: filepath.Join(testdata, "jwtkeys", "requestor1.pem"),
106
107
		},
		"requestor2": {
108
			AuthenticationMethod: irmaserver.AuthenticationMethodToken,
109
110
			AuthenticationKey:    "xa6=*&9?8jeUu5>.f-%rVg`f63pHim",
		},
111
112
113
114
		"requestor3": {
			AuthenticationMethod: irmaserver.AuthenticationMethodHmac,
			AuthenticationKey:    "eGE2PSomOT84amVVdTU+LmYtJXJWZ2BmNjNwSGltCg==",
		},
115
	},
116
	JwtPrivateKeyFile: filepath.Join(testdata, "jwtkeys", "sk.pem"),
117
}