logs_test.go 2.19 KB
Newer Older
Sietse Ringers's avatar
Sietse Ringers committed
1
2
3
4
package sessiontest

import (
	"testing"
5
	"time"
Sietse Ringers's avatar
Sietse Ringers committed
6
7
8
9
10
11
12

	"github.com/privacybydesign/irmago"
	"github.com/privacybydesign/irmago/internal/test"
	"github.com/stretchr/testify/require"
)

func TestLogging(t *testing.T) {
13
	client, _ := parseStorage(t)
Sietse Ringers's avatar
Sietse Ringers committed
14

15
	logs, err := client.LoadLogs(time.Now(), 100)
Sietse Ringers's avatar
Sietse Ringers committed
16
17
18
19
20
21
22
23
24
	oldLogLength := len(logs)
	require.NoError(t, err)
	attrid := irma.NewAttributeTypeIdentifier("irma-demo.RU.studentCard.studentID")
	var request irma.SessionRequest

	// Do issuance session
	request = getCombinedIssuanceRequest(attrid)
	sessionHelper(t, request, "issue", client)

25
	logs, err = client.LoadLogs(time.Now(), 100)
Sietse Ringers's avatar
Sietse Ringers committed
26
27
28
	require.NoError(t, err)
	require.True(t, len(logs) == oldLogLength+1)

29
	entry := logs[0]
Sietse Ringers's avatar
Sietse Ringers committed
30
31
32
33
34
35
36
37
38
	require.NotNil(t, entry)
	require.NoError(t, err)
	issued, err := entry.GetIssuedCredentials(client.Configuration)
	require.NoError(t, err)
	require.NotNil(t, issued)
	disclosed, err := entry.GetDisclosedCredentials(client.Configuration)
	require.NoError(t, err)
	require.NotEmpty(t, disclosed)

39
40
	time.Sleep(2 * time.Second)

Sietse Ringers's avatar
Sietse Ringers committed
41
42
43
	// Do disclosure session
	request = getDisclosureRequest(attrid)
	sessionHelper(t, request, "verification", client)
44
	logs, err = client.LoadLogs(time.Now(), 100)
Sietse Ringers's avatar
Sietse Ringers committed
45
46
47
	require.NoError(t, err)
	require.True(t, len(logs) == oldLogLength+2)

48
	entry = logs[0]
Sietse Ringers's avatar
Sietse Ringers committed
49
50
51
52
53
54
	require.NotNil(t, entry)
	require.NoError(t, err)
	disclosed, err = entry.GetDisclosedCredentials(client.Configuration)
	require.NoError(t, err)
	require.NotEmpty(t, disclosed)

55
56
57
58
59
	// Test before parameter
	logs, err = client.LoadLogs(time.Time(entry.Time), 100)
	require.NoError(t, err)
	require.True(t, len(logs) == oldLogLength+1)

Sietse Ringers's avatar
Sietse Ringers committed
60
61
62
	// Do signature session
	request = getSigningRequest(attrid)
	sessionHelper(t, request, "signature", client)
63
	logs, err = client.LoadLogs(time.Now(), 100)
Sietse Ringers's avatar
Sietse Ringers committed
64
65
	require.NoError(t, err)
	require.True(t, len(logs) == oldLogLength+3)
66
	entry = logs[0]
Sietse Ringers's avatar
Sietse Ringers committed
67
68
69
70
71
72
73
74
75
	require.NotNil(t, entry)
	require.NoError(t, err)
	sig, err := entry.GetSignedMessage()
	require.NoError(t, err)
	require.NotNil(t, sig)
	attrs, status, err := sig.Verify(client.Configuration, nil)
	require.NoError(t, err)
	require.Equal(t, irma.ProofStatusValid, status)
	require.NotEmpty(t, attrs)
76
	require.Equal(t, attrid, attrs[0][0].Identifier)
Sietse Ringers's avatar
Sietse Ringers committed
77
78
79

	test.ClearTestStorage(t)
}