forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
180 lines (159 loc) · 4.75 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package kbtest
import (
"fmt"
"sync"
"golang.org/x/net/context"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
type gpgtestui struct {
index int
}
func (g *gpgtestui) SelectKeyAndPushOption(_ context.Context, arg keybase1.SelectKeyAndPushOptionArg) (keybase1.SelectKeyRes, error) {
if len(arg.Keys) == 0 {
return keybase1.SelectKeyRes{}, fmt.Errorf("no keys in arg")
}
if g.index >= len(arg.Keys) {
return keybase1.SelectKeyRes{}, fmt.Errorf("test index %d outside bounds (num keys = %d)", g.index, len(arg.Keys))
}
key := arg.Keys[g.index]
return keybase1.SelectKeyRes{KeyID: key.KeyID, DoSecretPush: true}, nil
}
func (g *gpgtestui) SelectKey(_ context.Context, arg keybase1.SelectKeyArg) (string, error) {
if len(arg.Keys) == 0 {
return "", fmt.Errorf("no keys in arg")
}
if g.index >= len(arg.Keys) {
return "", fmt.Errorf("test index %d outside bounds (num keys = %d)", g.index, len(arg.Keys))
}
key := arg.Keys[g.index]
return key.KeyID, nil
}
func (g *gpgtestui) WantToAddGPGKey(_ context.Context, _ int) (bool, error) {
return true, nil
}
func (g *gpgtestui) ConfirmDuplicateKeyChosen(_ context.Context, _ int) (bool, error) {
return true, nil
}
func (g *gpgtestui) Sign(_ context.Context, _ keybase1.SignArg) (string, error) {
return "", fmt.Errorf("not implemented")
}
func (g *gpgtestui) GetTTY(_ context.Context) (string, error) {
return "", nil
}
//
// FakeIdentifyUI
//
type FakeIdentifyUI struct {
Proofs map[string]string
ProofResults map[string]keybase1.LinkCheckResult
User *keybase1.User
Confirmed bool
Keys map[libkb.PGPFingerprint]*keybase1.TrackDiff
DisplayKeyCalls int
Outcome *keybase1.IdentifyOutcome
StartCount int
Token keybase1.TrackToken
BrokenTracking bool
DisplayTLFArg keybase1.DisplayTLFCreateWithInviteArg
DisplayTLFCount int
sync.Mutex
}
var _ libkb.IdentifyUI = (*FakeIdentifyUI)(nil)
func (ui *FakeIdentifyUI) FinishWebProofCheck(proof keybase1.RemoteProof, result keybase1.LinkCheckResult) error {
ui.Lock()
defer ui.Unlock()
if ui.Proofs == nil {
ui.Proofs = make(map[string]string)
}
ui.Proofs[proof.Key] = proof.Value
if ui.ProofResults == nil {
ui.ProofResults = make(map[string]keybase1.LinkCheckResult)
}
ui.ProofResults[proof.Key] = result
if result.BreaksTracking {
ui.BrokenTracking = true
}
return nil
}
func (ui *FakeIdentifyUI) FinishSocialProofCheck(proof keybase1.RemoteProof, result keybase1.LinkCheckResult) error {
ui.Lock()
defer ui.Unlock()
if ui.Proofs == nil {
ui.Proofs = make(map[string]string)
}
ui.Proofs[proof.Key] = proof.Value
if ui.ProofResults == nil {
ui.ProofResults = make(map[string]keybase1.LinkCheckResult)
}
ui.ProofResults[proof.Key] = result
if result.BreaksTracking {
ui.BrokenTracking = true
}
return nil
}
func (ui *FakeIdentifyUI) Confirm(outcome *keybase1.IdentifyOutcome) (result keybase1.ConfirmResult, err error) {
ui.Lock()
defer ui.Unlock()
ui.Outcome = outcome
result.IdentityConfirmed = outcome.TrackOptions.BypassConfirm
result.RemoteConfirmed = outcome.TrackOptions.BypassConfirm && !outcome.TrackOptions.ExpiringLocal
return
}
func (ui *FakeIdentifyUI) DisplayCryptocurrency(keybase1.Cryptocurrency) error {
return nil
}
func (ui *FakeIdentifyUI) DisplayKey(ik keybase1.IdentifyKey) error {
ui.Lock()
defer ui.Unlock()
if ui.Keys == nil {
ui.Keys = make(map[libkb.PGPFingerprint]*keybase1.TrackDiff)
}
fp := libkb.ImportPGPFingerprintSlice(ik.PGPFingerprint)
ui.Keys[*fp] = ik.TrackDiff
ui.DisplayKeyCalls++
return nil
}
func (ui *FakeIdentifyUI) ReportLastTrack(*keybase1.TrackSummary) error {
return nil
}
func (ui *FakeIdentifyUI) Start(username string, _ keybase1.IdentifyReason, forceDisplay bool) error {
ui.Lock()
defer ui.Unlock()
ui.StartCount++
return nil
}
func (ui *FakeIdentifyUI) Cancel() error {
return nil
}
func (ui *FakeIdentifyUI) Finish() error {
return nil
}
func (ui *FakeIdentifyUI) Dismiss(_ string, _ keybase1.DismissReason) error {
return nil
}
func (ui *FakeIdentifyUI) LaunchNetworkChecks(id *keybase1.Identity, user *keybase1.User) error {
ui.Lock()
defer ui.Unlock()
ui.User = user
return nil
}
func (ui *FakeIdentifyUI) DisplayTrackStatement(string) error {
return nil
}
func (ui *FakeIdentifyUI) DisplayUserCard(keybase1.UserCard) error {
return nil
}
func (ui *FakeIdentifyUI) ReportTrackToken(tok keybase1.TrackToken) error {
ui.Token = tok
return nil
}
func (ui *FakeIdentifyUI) SetStrict(b bool) {
}
func (ui *FakeIdentifyUI) DisplayTLFCreateWithInvite(arg keybase1.DisplayTLFCreateWithInviteArg) error {
ui.DisplayTLFCount++
ui.DisplayTLFArg = arg
return nil
}