manual_session_test.go 2.77 KB
Newer Older
1
2
3
package irmaclient

import (
Koen van Ingen's avatar
Koen van Ingen committed
4
5
6
	"fmt"
	"github.com/privacybydesign/irmago"
	"testing"
7
8
9
10
11
)

type ManualSessionHandler struct {
	permissionHandler PermissionHandler
	pinHandler        PinHandler
Koen van Ingen's avatar
Koen van Ingen committed
12
13
	t                 *testing.T
	c                 chan *irma.SessionError
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
}

var client *Client

func TestManualSession(t *testing.T) {
	request := "{\"nonce\": 0, \"message\":\"I owe you everything\",\"messageType\":\"STRING\",\"content\":[{\"label\":\"Student number (RU)\",\"attributes\":[\"irma-demo.RU.studentCard.studentID\"]}]}"

	channel := make(chan *irma.SessionError)
	manualSessionHandler := ManualSessionHandler{t: t, c: channel}

	client = parseStorage(t)
	TestAndroidParse(t)

	client.NewManualSession(request, &manualSessionHandler)

	teardown(t)

	if err := <-channel; err != nil {
		t.Fatal(*err)
	}
}

func TestManualKeyShareSession(t *testing.T) {
	keyshareRequest := "{\"nonce\": 0, \"message\":\"I owe you everything\",\"messageType\":\"STRING\",\"content\":[{\"label\":\"Student number (RU)\",\"attributes\":[\"test.test.mijnirma.email\"]}]}"

	channel := make(chan *irma.SessionError)
	manualSessionHandler := ManualSessionHandler{t: t, c: channel}

	client = parseStorage(t)
	TestAndroidParse(t)

	client.NewManualSession(keyshareRequest, &manualSessionHandler)

	teardown(t)

	if err := <-channel; err != nil {
		t.Fatal(*err)
	}
}

54
func (sh *ManualSessionHandler) Success(irmaAction irma.Action, result string) {
55
56
	sh.c <- nil
}
Koen van Ingen's avatar
Koen van Ingen committed
57
58
59
func (sh *ManualSessionHandler) UnsatisfiableRequest(irmaAction irma.Action, missingAttributes irma.AttributeDisjunctionList) {
	sh.t.Fail()
}
60
61

// Done in irma bridge?
Koen van Ingen's avatar
Koen van Ingen committed
62
func (sh *ManualSessionHandler) StatusUpdate(irmaAction irma.Action, status irma.Status) {}
63
64
65
66
67
68
69
70
func (sh *ManualSessionHandler) RequestPin(remainingAttempts int, ph PinHandler) {
	ph(true, "12345")
}
func (sh *ManualSessionHandler) RequestSignaturePermission(request irma.SignatureRequest, requesterName string, ph PermissionHandler) {
	c := irma.DisclosureChoice{request.Candidates[0]}
	ph(true, &c)
}

71
// These handlers should not be called, fail test if they are called
72
func (sh *ManualSessionHandler) Cancelled(irmaAction irma.Action) { sh.t.Fail() }
Koen van Ingen's avatar
Koen van Ingen committed
73
74
75
76
77
78
79
80
81
82
83
84
func (sh *ManualSessionHandler) MissingKeyshareEnrollment(manager irma.SchemeManagerIdentifier) {
	sh.t.Fail()
}
func (sh *ManualSessionHandler) RequestIssuancePermission(request irma.IssuanceRequest, issuerName string, ph PermissionHandler) {
	sh.t.Fail()
}
func (sh *ManualSessionHandler) RequestSchemeManagerPermission(manager *irma.SchemeManager, callback func(proceed bool)) {
	sh.t.Fail()
}
func (sh *ManualSessionHandler) RequestVerificationPermission(request irma.DisclosureRequest, verifierName string, ph PermissionHandler) {
	sh.t.Fail()
}
85
86
87
88
func (sh *ManualSessionHandler) Failure(irmaAction irma.Action, err *irma.SessionError) {
	fmt.Println(err.Err)
	sh.t.Fail()
}