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

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

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

31
func StartIrmaServer(configuration *irmaserver.Configuration) {
32
	go func() {
33
34
35
36
37
		var err error
		if combinedServer, err = irmaserver.New(configuration); err != nil {
			panic(err)
		}
		if err = combinedServer.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 StopIrmaServer() {
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
	_ = 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
	irmaServer, err = irmarequestor.New(&server.Configuration{
		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()
75
76
}

77
78
var IrmaServerConfiguration = &irmaserver.Configuration{
	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
}

88
89
var JwtServerConfiguration = &irmaserver.Configuration{
	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
98
	MaxRequestAge:                  3,
	Permissions: irmaserver.Permissions{
99
100
101
102
103
		Disclosing: []string{"*"},
		Signing:    []string{"*"},
		Issuing:    []string{"*"},
	},
	Requestors: map[string]irmaserver.Requestor{
Sietse Ringers's avatar
Sietse Ringers committed
104
		"requestor1": {
105
106
			AuthenticationMethod:  irmaserver.AuthenticationMethodPublicKey,
			AuthenticationKeyFile: filepath.Join(testdata, "jwtkeys", "requestor1.pem"),
107
108
		},
		"requestor2": {
109
			AuthenticationMethod: irmaserver.AuthenticationMethodToken,
110
111
			AuthenticationKey:    "xa6=*&9?8jeUu5>.f-%rVg`f63pHim",
		},
112
113
114
115
		"requestor3": {
			AuthenticationMethod: irmaserver.AuthenticationMethodHmac,
			AuthenticationKey:    "eGE2PSomOT84amVVdTU+LmYtJXJWZ2BmNjNwSGltCg==",
		},
116
	},
117
	JwtPrivateKeyFile: filepath.Join(testdata, "jwtkeys", "sk.pem"),
118
}