keyshare_test.go 3.84 KB
Newer Older
1
2
3
4
5
package sessiontest

import (
	"testing"

6
	irma "github.com/privacybydesign/irmago"
7
	"github.com/privacybydesign/irmago/internal/test"
8
	"github.com/privacybydesign/irmago/internal/testkeyshare"
9
	"github.com/privacybydesign/irmago/irmaclient"
10
11
12
	"github.com/stretchr/testify/require"
)

13
func TestManualKeyshareSession(t *testing.T) {
14
	testkeyshare.StartKeyshareServer(t, logger)
15
	defer testkeyshare.StopKeyshareServer(t)
16
	request := irma.NewSignatureRequest("I owe you everything", irma.NewAttributeTypeIdentifier("test.test.mijnirma.email"))
17
18
19
20
	ms := createManualSessionHandler(t, nil)

	_, status := manualSessionHelper(t, nil, ms, request, request, false)
	require.Equal(t, irma.ProofStatusValid, status)
21
	_, status = manualSessionHelper(t, nil, ms, request, nil, false)
22
23
24
25
	require.Equal(t, irma.ProofStatusValid, status)
}

func TestRequestorIssuanceKeyshareSession(t *testing.T) {
26
	testkeyshare.StartKeyshareServer(t, logger)
27
	defer testkeyshare.StopKeyshareServer(t)
28
	testRequestorIssuance(t, true, nil)
29
30
}

31
func TestKeyshareRegister(t *testing.T) {
32
	testkeyshare.StartKeyshareServer(t, logger)
33
	defer testkeyshare.StopKeyshareServer(t)
34
	client, handler := parseStorage(t)
35
	defer test.ClearTestStorage(t, handler.storage)
36
37

	require.NoError(t, client.KeyshareRemoveAll())
38
	require.NoError(t, client.RemoveStorage())
39

40
	client.SetPreferences(irmaclient.Preferences{DeveloperMode: true})
41
42
43
44
45
	client.KeyshareEnroll(irma.NewSchemeManagerIdentifier("test"), nil, "12345", "en")
	require.NoError(t, <-handler.c)

	require.Len(t, client.CredentialInfoList(), 1)

46
47
48
49
	StartIrmaServer(t, false, "")
	defer StopIrmaServer()

	requestorSessionHelper(t, getIssuanceRequest(true), client, sessionOptionReuseServer)
50
51
52
	keyshareSessions(t, client)
}

53
54
55
// Use the existing keyshare enrollment and credentials
// in a keyshare session of each session type.
func TestKeyshareSessions(t *testing.T) {
56
	testkeyshare.StartKeyshareServer(t, logger)
57
	defer testkeyshare.StopKeyshareServer(t)
58
59
	client, handler := parseStorage(t)
	defer test.ClearTestStorage(t, handler.storage)
60
61
	StartIrmaServer(t, false, "")
	defer StopIrmaServer()
62
63
	keyshareSessions(t, client)
}
64

65
func keyshareSessions(t *testing.T, client *irmaclient.Client) {
66
67
68
69
70
71
72
73
74
75
	id := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
	expiry := irma.Timestamp(irma.NewMetadataAttribute(0).Expiry())
	issuanceRequest := getCombinedIssuanceRequest(id)
	issuanceRequest.Credentials = append(issuanceRequest.Credentials,
		&irma.CredentialRequest{
			Validity:         &expiry,
			CredentialTypeID: irma.NewCredentialTypeIdentifier("test.test.mijnirma"),
			Attributes:       map[string]string{"email": "testusername"},
		},
	)
76
	requestorSessionHelper(t, issuanceRequest, client, sessionOptionReuseServer)
77
78

	disclosureRequest := getDisclosureRequest(id)
79
	disclosureRequest.AddSingle(irma.NewAttributeTypeIdentifier("test.test.mijnirma.email"), nil, nil)
80
	requestorSessionHelper(t, disclosureRequest, client, sessionOptionReuseServer)
81
82

	sigRequest := getSigningRequest(id)
83
	sigRequest.AddSingle(irma.NewAttributeTypeIdentifier("test.test.mijnirma.email"), nil, nil)
84
	requestorSessionHelper(t, sigRequest, client, sessionOptionReuseServer)
85
}
Sietse Ringers's avatar
Sietse Ringers committed
86
87

func TestIssuanceCombinedMultiSchemeSession(t *testing.T) {
88
89
	StartIrmaServer(t, false, "")
	defer StopIrmaServer()
90
	testkeyshare.StartKeyshareServer(t, logger)
91
	defer testkeyshare.StopKeyshareServer(t)
92

Sietse Ringers's avatar
Sietse Ringers committed
93
94
	id := irma.NewAttributeTypeIdentifier("test.test.mijnirma.email")
	request := getCombinedIssuanceRequest(id)
95
	requestorSessionHelper(t, request, nil, sessionOptionReuseServer)
Sietse Ringers's avatar
Sietse Ringers committed
96

97
98
	id = irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
	request = irma.NewIssuanceRequest([]*irma.CredentialRequest{
Sietse Ringers's avatar
Sietse Ringers committed
99
		{
Sietse Ringers's avatar
Sietse Ringers committed
100
			CredentialTypeID: irma.NewCredentialTypeIdentifier("test.test.mijnirma"),
Sietse Ringers's avatar
Sietse Ringers committed
101
102
103
104
			Attributes: map[string]string{
				"email": "example@example.com",
			},
		},
105
106
	}, id)
	requestorSessionHelper(t, request, nil, sessionOptionReuseServer)
Sietse Ringers's avatar
Sietse Ringers committed
107
}