server_test.go 3.3 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"
Sietse Ringers's avatar
Sietse Ringers committed
12
	"github.com/privacybydesign/irmago/server/requestorserver"
13
	"github.com/sirupsen/logrus"
14
	"github.com/stretchr/testify/require"
15
16
)

17
var (
Sietse Ringers's avatar
Sietse Ringers committed
18
19
20
	httpServer      *http.Server
	irmaServer      *irmaserver.Server
	requestorServer *requestorserver.Server
21

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

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

Sietse Ringers's avatar
Sietse Ringers committed
31
func StartRequestorServer(configuration *requestorserver.Configuration) {
32
	go func() {
33
		var err error
Sietse Ringers's avatar
Sietse Ringers committed
34
		if requestorServer, err = requestorserver.New(configuration); err != nil {
35
36
			panic(err)
		}
Sietse Ringers's avatar
Sietse Ringers committed
37
		if err = requestorServer.Start(configuration); err != nil {
38
39
			panic("Starting server failed: " + err.Error())
		}
40
	}()
41
	time.Sleep(100 * time.Millisecond) // Give server time to start
42
43
}

Sietse Ringers's avatar
Sietse Ringers committed
44
func StopRequestorServer() {
45
	requestorServer.Stop()
46
47
}

Sietse Ringers's avatar
Sietse Ringers committed
48
func StartIrmaServer(t *testing.T) {
49
50
51
	testdata := test.FindTestdataFolder(t)

	logger := logrus.New()
52
	logger.Level = logrus.ErrorLevel
53
54
55
	logger.Formatter = &logrus.TextFormatter{}

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

	require.NoError(t, err)

	mux := http.NewServeMux()
Sietse Ringers's avatar
Sietse Ringers committed
66
	mux.HandleFunc("/", irmaServer.HandlerFunc())
67
68
69
70
71
72
	httpServer = &http.Server{Addr: ":48680", Handler: mux}
	go func() {
		_ = httpServer.ListenAndServe()
	}()
}

Sietse Ringers's avatar
Sietse Ringers committed
73
func StopIrmaServer() {
74
	_ = httpServer.Close()
75
76
}

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

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