session_test.go 17.6 KB
Newer Older
1
package sessiontest
Sietse Ringers's avatar
Sietse Ringers committed
2
3

import (
4
	"encoding/base64"
Sietse Ringers's avatar
Sietse Ringers committed
5
	"encoding/json"
6
7
	"io/ioutil"
	"path/filepath"
Sietse Ringers's avatar
Sietse Ringers committed
8
	"testing"
9
	"time"
Sietse Ringers's avatar
Sietse Ringers committed
10

11
	"github.com/dgrijalva/jwt-go"
12
	"github.com/privacybydesign/irmago"
13
	"github.com/privacybydesign/irmago/internal/fs"
14
	"github.com/privacybydesign/irmago/internal/test"
15
	"github.com/privacybydesign/irmago/irmaclient"
Sietse Ringers's avatar
Sietse Ringers committed
16
17
18
	"github.com/stretchr/testify/require"
)

19
20
21
22
func init() {
	irma.ForceHttps = false
}

Sietse Ringers's avatar
Sietse Ringers committed
23
24
25
func getDisclosureRequest(id irma.AttributeTypeIdentifier) *irma.DisclosureRequest {
	return &irma.DisclosureRequest{
		BaseRequest: irma.BaseRequest{Type: irma.ActionDisclosing},
26
		Content: irma.AttributeDisjunctionList([]*irma.AttributeDisjunction{{
Sietse Ringers's avatar
Sietse Ringers committed
27
			Label:      "foo",
28
			Attributes: []irma.AttributeTypeIdentifier{id},
Sietse Ringers's avatar
Sietse Ringers committed
29
		}}),
Sietse Ringers's avatar
Sietse Ringers committed
30
	}
Sietse Ringers's avatar
Sietse Ringers committed
31
32
}

Sietse Ringers's avatar
Sietse Ringers committed
33
34
func getSigningRequest(id irma.AttributeTypeIdentifier) *irma.SignatureRequest {
	return &irma.SignatureRequest{
35
		Message: "test",
36
		DisclosureRequest: irma.DisclosureRequest{
Sietse Ringers's avatar
Sietse Ringers committed
37
			BaseRequest: irma.BaseRequest{Type: irma.ActionSigning},
38
			Content: irma.AttributeDisjunctionList([]*irma.AttributeDisjunction{{
Sietse Ringers's avatar
Sietse Ringers committed
39
				Label:      "foo",
40
				Attributes: []irma.AttributeTypeIdentifier{id},
Sietse Ringers's avatar
Sietse Ringers committed
41
42
			}}),
		},
Sietse Ringers's avatar
Sietse Ringers committed
43
	}
Sietse Ringers's avatar
Sietse Ringers committed
44
45
}

46
func getIssuanceRequest(defaultValidity bool) *irma.IssuanceRequest {
47
	temp := irma.Timestamp(irma.FloorToEpochBoundary(time.Now().AddDate(1, 0, 0)))
48
	var expiry *irma.Timestamp
49

50
51
52
53
	if !defaultValidity {
		expiry = &temp
	}

54
	return &irma.IssuanceRequest{
Sietse Ringers's avatar
Sietse Ringers committed
55
		BaseRequest: irma.BaseRequest{Type: irma.ActionIssuing},
56
		Credentials: []*irma.CredentialRequest{
Sietse Ringers's avatar
Sietse Ringers committed
57
			{
58
				Validity:         expiry,
59
				CredentialTypeID: irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard"),
Sietse Ringers's avatar
Sietse Ringers committed
60
61
				Attributes: map[string]string{
					"university":        "Radboud",
62
					"studentCardNumber": "31415927",
Sietse Ringers's avatar
Sietse Ringers committed
63
64
65
66
					"studentID":         "s1234567",
					"level":             "42",
				},
			}, {
67
				Validity:         expiry,
68
				CredentialTypeID: irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.root"),
Sietse Ringers's avatar
Sietse Ringers committed
69
70
71
72
73
				Attributes: map[string]string{
					"BSN": "299792458",
				},
			},
		},
74
75
76
	}
}

77
78
func getNameIssuanceRequest() *irma.IssuanceRequest {
	expiry := irma.Timestamp(irma.NewMetadataAttribute(0).Expiry())
79
80

	req := &irma.IssuanceRequest{
Sietse Ringers's avatar
Sietse Ringers committed
81
		BaseRequest: irma.BaseRequest{Type: irma.ActionIssuing},
82
83
84
		Credentials: []*irma.CredentialRequest{
			{
				Validity:         &expiry,
85
				CredentialTypeID: irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.fullName"),
86
87
88
89
90
91
92
93
94
95
96
97
				Attributes: map[string]string{
					"firstnames": "Johan Pieter",
					"firstname":  "Johan",
					"familyname": "Stuivezand",
				},
			},
		},
	}

	return req
}

Sietse Ringers's avatar
Sietse Ringers committed
98
99
100
101
func getSpecialIssuanceRequest(defaultValidity bool, attribute string) *irma.IssuanceRequest {
	request := getIssuanceRequest(defaultValidity)
	request.Credentials[0].Attributes["studentCardNumber"] = attribute
	return request
102
103
}

Sietse Ringers's avatar
Sietse Ringers committed
104
105
106
func getCombinedIssuanceRequest(id irma.AttributeTypeIdentifier) *irma.IssuanceRequest {
	request := getIssuanceRequest(false)
	request.Disclose = irma.AttributeDisjunctionList{
107
108
		&irma.AttributeDisjunction{Label: "foo", Attributes: []irma.AttributeTypeIdentifier{id}},
	}
Sietse Ringers's avatar
Sietse Ringers committed
109
	return request
Sietse Ringers's avatar
Sietse Ringers committed
110
111
}

Sietse Ringers's avatar
Sietse Ringers committed
112
var TestType = "irmaserver-jwt"
113

114
func startSession(t *testing.T, request irma.SessionRequest, sessiontype string) *irma.Qr {
115
116
117
118
119
120
	var qr irma.Qr
	var err error

	switch TestType {
	case "apiserver":
		url := "http://localhost:8088/irma_api_server/api/v2/" + sessiontype
121
		err = irma.NewHTTPTransport(url).Post("", &qr, getJwt(t, request, sessiontype, jwt.SigningMethodNone))
122
123
124
		qr.URL = url + "/" + qr.URL
	case "irmaserver-jwt":
		url := "http://localhost:48682"
125
126
127
128
		err = irma.NewHTTPTransport(url).Post("session", &qr, getJwt(t, request, sessiontype, jwt.SigningMethodRS256))
	case "irmaserver-hmac-jwt":
		url := "http://localhost:48682"
		err = irma.NewHTTPTransport(url).Post("session", &qr, getJwt(t, request, sessiontype, jwt.SigningMethodHS256))
129
130
	case "irmaserver":
		url := "http://localhost:48682"
131
		err = irma.NewHTTPTransport(url).Post("session", &qr, request)
132
133
134
135
136
	default:
		t.Fatal("Invalid TestType")
	}

	require.NoError(t, err)
137
	return &qr
Sietse Ringers's avatar
Sietse Ringers committed
138
139
}

140
func getJwt(t *testing.T, request irma.SessionRequest, sessiontype string, alg jwt.SigningMethod) string {
141
	var jwtcontents irma.RequestorJwt
142
143
	var kid string
	switch sessiontype {
Sietse Ringers's avatar
Sietse Ringers committed
144
	case "issue":
145
		kid = "testip"
Sietse Ringers's avatar
Sietse Ringers committed
146
147
		jwtcontents = irma.NewIdentityProviderJwt("testip", request.(*irma.IssuanceRequest))
	case "verification":
148
		kid = "testsp"
Sietse Ringers's avatar
Sietse Ringers committed
149
150
		jwtcontents = irma.NewServiceProviderJwt("testsp", request.(*irma.DisclosureRequest))
	case "signature":
151
		kid = "testsigclient"
Sietse Ringers's avatar
Sietse Ringers committed
152
		jwtcontents = irma.NewSignatureRequestorJwt("testsigclient", request.(*irma.SignatureRequest))
153
154
	}

155
156
	var j string
	var err error
157
158
159

	switch alg {
	case jwt.SigningMethodRS256:
160
161
162
163
164
165
166
		skbts, err := ioutil.ReadFile(filepath.Join(test.FindTestdataFolder(t), "jwtkeys", "requestor1-sk.pem"))
		require.NoError(t, err)
		sk, err := jwt.ParseRSAPrivateKeyFromPEM(skbts)
		require.NoError(t, err)
		tok := jwt.NewWithClaims(jwt.SigningMethodRS256, jwtcontents)
		tok.Header["kid"] = "requestor1"
		j, err = tok.SignedString(sk)
167
168
169
170
171
172
173
	case jwt.SigningMethodHS256:
		tok := jwt.NewWithClaims(jwt.SigningMethodHS256, jwtcontents)
		tok.Header["kid"] = "requestor3"
		bts, err := base64.StdEncoding.DecodeString(JwtServerConfiguration.Requestors["requestor3"].AuthenticationKey)
		require.NoError(t, err)
		j, err = tok.SignedString(bts)
	case jwt.SigningMethodNone:
174
175
176
177
		tok := jwt.NewWithClaims(jwt.SigningMethodNone, jwtcontents)
		tok.Header["kid"] = kid
		j, err = tok.SignedString(jwt.UnsafeAllowNoneSignatureType)
	}
178
179
	require.NoError(t, err)

180
	return j
Sietse Ringers's avatar
Sietse Ringers committed
181
182
}

183
func sessionHelper(t *testing.T, request irma.SessionRequest, sessiontype string, client *irmaclient.Client) {
Sietse Ringers's avatar
Sietse Ringers committed
184
185
186
187
188
	if client == nil {
		client = parseStorage(t)
		defer test.ClearTestStorage(t)
	}

189
	if TestType == "irmaserver" || TestType == "irmaserver-jwt" || TestType == "irmaserver-hmac-jwt" {
Sietse Ringers's avatar
Sietse Ringers committed
190
191
		StartRequestorServer(JwtServerConfiguration)
		defer StopRequestorServer()
Sietse Ringers's avatar
Sietse Ringers committed
192
193
	}

194
	qr := startSession(t, request, sessiontype)
195
196
197

	c := make(chan *SessionResult)
	h := TestHandler{t, c, client}
198
	qrjson, err := json.Marshal(qr)
199
	require.NoError(t, err)
200
	client.NewSession(string(qrjson), h)
201
202
203
204
205
206

	if result := <-c; result != nil {
		require.NoError(t, result.Err)
	}
}

207
func keyshareSessions(t *testing.T, client *irmaclient.Client) {
208
209
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
	expiry := irma.Timestamp(irma.NewMetadataAttribute(0).Expiry())
Sietse Ringers's avatar
Sietse Ringers committed
210
211
	issuanceRequest := getCombinedIssuanceRequest(id)
	issuanceRequest.Credentials = append(issuanceRequest.Credentials,
212
213
		&irma.CredentialRequest{
			Validity:         &expiry,
214
			CredentialTypeID: irma.NewCredentialTypeIdentifier("test.test.mijnirma"),
215
216
217
			Attributes:       map[string]string{"email": "testusername"},
		},
	)
Sietse Ringers's avatar
Sietse Ringers committed
218
	sessionHelper(t, issuanceRequest, "issue", client)
219

Sietse Ringers's avatar
Sietse Ringers committed
220
221
	disclosureRequest := getDisclosureRequest(id)
	disclosureRequest.Content = append(disclosureRequest.Content,
222
223
224
225
226
		&irma.AttributeDisjunction{
			Label:      "foo",
			Attributes: []irma.AttributeTypeIdentifier{irma.NewAttributeTypeIdentifier("test.test.mijnirma.email")},
		},
	)
Sietse Ringers's avatar
Sietse Ringers committed
227
	sessionHelper(t, disclosureRequest, "verification", client)
228

Sietse Ringers's avatar
Sietse Ringers committed
229
230
	sigRequest := getSigningRequest(id)
	sigRequest.Content = append(sigRequest.Content,
231
232
233
234
235
		&irma.AttributeDisjunction{
			Label:      "foo",
			Attributes: []irma.AttributeTypeIdentifier{irma.NewAttributeTypeIdentifier("test.test.mijnirma.email")},
		},
	)
Sietse Ringers's avatar
Sietse Ringers committed
236
	sessionHelper(t, sigRequest, "signature", client)
237
238
}

Sietse Ringers's avatar
Sietse Ringers committed
239
func TestSigningSession(t *testing.T) {
240
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
Sietse Ringers's avatar
Sietse Ringers committed
241
242
	request := getSigningRequest(id)
	sessionHelper(t, request, "signature", nil)
Sietse Ringers's avatar
Sietse Ringers committed
243
244
245
}

func TestDisclosureSession(t *testing.T) {
246
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
Sietse Ringers's avatar
Sietse Ringers committed
247
248
	request := getDisclosureRequest(id)
	sessionHelper(t, request, "verification", nil)
Sietse Ringers's avatar
Sietse Ringers committed
249
250
}

251
252
func TestNoAttributeDisclosureSession(t *testing.T) {
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard")
Sietse Ringers's avatar
Sietse Ringers committed
253
254
	request := getDisclosureRequest(id)
	sessionHelper(t, request, "verification", nil)
255
256
}

Sietse Ringers's avatar
Sietse Ringers committed
257
func TestIssuanceSession(t *testing.T) {
258
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
Sietse Ringers's avatar
Sietse Ringers committed
259
260
	request := getCombinedIssuanceRequest(id)
	sessionHelper(t, request, "issue", nil)
Sietse Ringers's avatar
Sietse Ringers committed
261
262
}

263
264
func TestDefaultCredentialValidity(t *testing.T) {
	client := parseStorage(t)
Sietse Ringers's avatar
Sietse Ringers committed
265
266
	request := getIssuanceRequest(true)
	sessionHelper(t, request, "issue", client)
267
268
}

269
func TestIssuanceOptionalEmptyAttributes(t *testing.T) {
270
	req := getNameIssuanceRequest()
Sietse Ringers's avatar
Sietse Ringers committed
271
	sessionHelper(t, req, "issue", nil)
272
273
274
275
276
}

func TestIssuanceOptionalZeroLengthAttributes(t *testing.T) {
	req := getNameIssuanceRequest()
	req.Credentials[0].Attributes["prefix"] = ""
Sietse Ringers's avatar
Sietse Ringers committed
277
	sessionHelper(t, req, "issue", nil)
278
279
280
}

func TestIssuanceOptionalSetAttributes(t *testing.T) {
281
282
	req := getNameIssuanceRequest()
	req.Credentials[0].Attributes["prefix"] = "van"
Sietse Ringers's avatar
Sietse Ringers committed
283
	sessionHelper(t, req, "issue", nil)
284
285
}

286
287
func TestLargeAttribute(t *testing.T) {
	client := parseStorage(t)
288
289
	defer test.ClearTestStorage(t)

290
291
	require.NoError(t, client.RemoveAllCredentials())

Sietse Ringers's avatar
Sietse Ringers committed
292
293
	issuanceRequest := getSpecialIssuanceRequest(false, "1234567890123456789012345678901234567890") // 40 chars
	sessionHelper(t, issuanceRequest, "issue", client)
294

Sietse Ringers's avatar
Sietse Ringers committed
295
296
	disclosureRequest := getDisclosureRequest(irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.university"))
	sessionHelper(t, disclosureRequest, "verification", client)
297
298
}

299
300
func TestIssuanceSingletonCredential(t *testing.T) {
	client := parseStorage(t)
301
302
	defer test.ClearTestStorage(t)

Sietse Ringers's avatar
Sietse Ringers committed
303
	request := getIssuanceRequest(true)
304
305
	credid := irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.root")

306
	require.Nil(t, client.Attributes(credid, 0))
307

Sietse Ringers's avatar
Sietse Ringers committed
308
	sessionHelper(t, request, "issue", client)
309
310
	require.NotNil(t, client.Attributes(credid, 0))
	require.Nil(t, client.Attributes(credid, 1))
311

Sietse Ringers's avatar
Sietse Ringers committed
312
	sessionHelper(t, request, "issue", client)
313
314
	require.NotNil(t, client.Attributes(credid, 0))
	require.Nil(t, client.Attributes(credid, 1))
315
316
}

317
318
319
320
321
322
323
324
/* There is an annoying difference between how Java and Go convert big integers to and from
byte arrays: in Java the sign of the integer is taken into account, but not in Go. This means
that in Java, when converting a bigint to or from a byte array, the most significant bit
indicates the sign of the integer. In Go this is not the case. This resulted in invalid
signatures being issued in the issuance protocol in two distinct ways, of which we test here
that they have been fixed. */
func TestAttributeByteEncoding(t *testing.T) {
	client := parseStorage(t)
325
	defer test.ClearTestStorage(t)
326
327
328
329
330
331
332
	require.NoError(t, client.RemoveAllCredentials())

	/* After bitshifting the presence bit into the large attribute below, the most significant
	bit is 1. In the bigint->[]byte conversion that happens before hashing this attribute, in
	Java this results in an extra 0 byte being prepended in order to have a 0 instead as most
	significant (sign) bit. We test that the Java implementation correctly removes the extraneous
	0 byte. */
Sietse Ringers's avatar
Sietse Ringers committed
333
334
	request := getSpecialIssuanceRequest(false, "a23456789012345678901234567890")
	sessionHelper(t, request, "issue", client)
335
336
337
338
339
340
341

	/* After converting the attribute below to bytes (using UTF8, on which Java and Go do agree),
	the most significant bit of the byte version of this attribute is 1. In the []byte->bigint
	conversion that happens at that point in the Java implementation (bitshifting is done
	afterwards), this results in a negative number in Java and a positive number in Go. We test
	here that the Java correctly prepends a 0 byte just before this conversion in order to get
	the same positive bigint. */
Sietse Ringers's avatar
Sietse Ringers committed
342
343
	request = getSpecialIssuanceRequest(false, "é")
	sessionHelper(t, request, "issue", client)
344
345
}

346
// Use the existing keyshare enrollment and credentials
Sietse Ringers's avatar
Sietse Ringers committed
347
348
349
350
// in a keyshare session of each session type.
// Use keyshareuser.sql to enroll the user at the keyshare server.
func TestKeyshareSessions(t *testing.T) {
	client := parseStorage(t)
351
	defer test.ClearTestStorage(t)
Sietse Ringers's avatar
Sietse Ringers committed
352

353
	keyshareSessions(t, client)
Sietse Ringers's avatar
Sietse Ringers committed
354
}
355
356
357

func TestDisclosureNewAttributeUpdateSchemeManager(t *testing.T) {
	client := parseStorage(t)
358
	defer test.ClearTestStorage(t)
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

	schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
	credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
	attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.newAttribute")
	require.False(t, client.Configuration.CredentialTypes[credid].ContainsAttribute(attrid))

	client.Configuration.SchemeManagers[schemeid].URL = "http://localhost:48681/irma_configuration_updated/irma-demo"
	disclosureRequest := irma.DisclosureRequest{
		Content: irma.AttributeDisjunctionList{
			&irma.AttributeDisjunction{
				Label: "foo",
				Attributes: []irma.AttributeTypeIdentifier{
					attrid,
				},
			},
		},
	}

	client.Configuration.Download(&disclosureRequest)
	require.True(t, client.Configuration.CredentialTypes[credid].ContainsAttribute(attrid))
}

func TestIssueNewAttributeUpdateSchemeManager(t *testing.T) {
	client := parseStorage(t)
383
384
	defer test.ClearTestStorage(t)

385
386
387
388
389
390
391
392
393
394
395
396
397
398
	schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
	credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
	attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.newAttribute")
	require.False(t, client.Configuration.CredentialTypes[credid].ContainsAttribute(attrid))

	client.Configuration.SchemeManagers[schemeid].URL = "http://localhost:48681/irma_configuration_updated/irma-demo"
	issuanceRequest := getIssuanceRequest(true)
	issuanceRequest.Credentials[0].Attributes["newAttribute"] = "foobar"
	client.Configuration.Download(issuanceRequest)
	require.True(t, client.Configuration.CredentialTypes[credid].ContainsAttribute(attrid))
}

func TestIssueOptionalAttributeUpdateSchemeManager(t *testing.T) {
	client := parseStorage(t)
399
400
	defer test.ClearTestStorage(t)

401
402
403
404
405
406
407
408
409
410
411
412
	schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
	credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
	attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.level")
	require.False(t, client.Configuration.CredentialTypes[credid].AttributeType(attrid).IsOptional())

	client.Configuration.SchemeManagers[schemeid].URL = "http://localhost:48681/irma_configuration_updated/irma-demo"
	issuanceRequest := getIssuanceRequest(true)
	delete(issuanceRequest.Credentials[0].Attributes, "level")
	client.Configuration.Download(issuanceRequest)
	require.True(t, client.Configuration.CredentialTypes[credid].AttributeType(attrid).IsOptional())
}

Sietse Ringers's avatar
Sietse Ringers committed
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
func TestIssueNewCredTypeUpdateSchemeManager(t *testing.T) {
	client := parseStorage(t)
	schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
	credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")

	delete(client.Configuration.CredentialTypes, credid)
	require.NotContains(t, client.Configuration.CredentialTypes, credid)

	client.Configuration.SchemeManagers[schemeid].URL = "http://localhost:48681/irma_configuration_updated/irma-demo"
	request := getIssuanceRequest(true)
	client.Configuration.Download(request)

	require.Contains(t, client.Configuration.CredentialTypes, credid)

	test.ClearTestStorage(t)
}

func TestDisclosureNewCredTypeUpdateSchemeManager(t *testing.T) {
	client := parseStorage(t)
	schemeid := irma.NewSchemeManagerIdentifier("irma-demo")
	credid := irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")
	attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.level")

	delete(client.Configuration.CredentialTypes, credid)
	require.NotContains(t, client.Configuration.CredentialTypes, credid)

	client.Configuration.SchemeManagers[schemeid].URL = "http://localhost:48681/irma_configuration_updated/irma-demo"
	request := &irma.DisclosureRequest{
		Content: irma.AttributeDisjunctionList([]*irma.AttributeDisjunction{{
			Label:      "foo",
			Attributes: []irma.AttributeTypeIdentifier{attrid},
		}}),
	}
	client.Configuration.Download(request)

	require.Contains(t, client.Configuration.CredentialTypes, credid)

	test.ClearTestStorage(t)
}

453
454
455
456
457
// Test installing a new scheme manager from a qr, and do a(n issuance) session
// within this manager to test the autmatic downloading of credential definitions,
// issuers, and public keys.
func TestDownloadSchemeManager(t *testing.T) {
	client := parseStorage(t)
458
	defer test.ClearTestStorage(t)
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479

	// Remove irma-demo scheme manager as we need to test adding it
	irmademo := irma.NewSchemeManagerIdentifier("irma-demo")
	require.Contains(t, client.Configuration.SchemeManagers, irmademo)
	require.NoError(t, client.Configuration.RemoveSchemeManager(irmademo, true))
	require.NotContains(t, client.Configuration.SchemeManagers, irmademo)

	// Do an add-scheme-manager-session
	c := make(chan *SessionResult)
	qr, err := json.Marshal(&irma.SchemeManagerRequest{
		Type: irma.ActionSchemeManager,
		URL:  "http://localhost:48681/irma_configuration/irma-demo",
	})
	require.NoError(t, err)
	client.NewSession(string(qr), TestHandler{t, c, client})
	if result := <-c; result != nil {
		require.NoError(t, result.Err)
	}
	require.Contains(t, client.Configuration.SchemeManagers, irmademo)

	// Do a session to test downloading of cred types, issuers and keys
Sietse Ringers's avatar
Sietse Ringers committed
480
481
	request := getCombinedIssuanceRequest(irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID"))
	sessionHelper(t, request, "issue", client)
482
483
484
485
486

	require.Contains(t, client.Configuration.SchemeManagers, irmademo)
	require.Contains(t, client.Configuration.Issuers, irma.NewIssuerIdentifier("irma-demo.RU"))
	require.Contains(t, client.Configuration.CredentialTypes, irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard"))

487
	basepath := test.FindTestdataFolder(t) + "/storage/test/irma_configuration/irma-demo"
488
489
490
491
492
493
494
495
496
497
	exists, err := fs.PathExists(basepath + "/description.xml")
	require.NoError(t, err)
	require.True(t, exists)
	exists, err = fs.PathExists(basepath + "/RU/description.xml")
	require.NoError(t, err)
	require.True(t, exists)
	exists, err = fs.PathExists(basepath + "/RU/Issues/studentCard/description.xml")
	require.NoError(t, err)
	require.True(t, exists)
}