forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbtest.go
68 lines (60 loc) · 1.62 KB
/
kbtest.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package kbtest
import (
"crypto/rand"
"encoding/hex"
"fmt"
"github.com/keybase/client/go/engine"
"github.com/keybase/client/go/libkb"
)
const testInviteCode = "202020202020202020202020"
type FakeUser struct {
Username string
Email string
Passphrase string
User *libkb.User
}
func NewFakeUser(prefix string) (*FakeUser, error) {
buf := make([]byte, 5)
if _, err := rand.Read(buf); err != nil {
return nil, err
}
username := fmt.Sprintf("%s_%s", prefix, hex.EncodeToString(buf))
email := fmt.Sprintf("%s@noemail.keybase.io", username)
buf = make([]byte, 12)
if _, err := rand.Read(buf); err != nil {
return nil, err
}
passphrase := hex.EncodeToString(buf)
return &FakeUser{username, email, passphrase, nil}, nil
}
func (fu *FakeUser) NewSecretUI() *libkb.TestSecretUI {
return &libkb.TestSecretUI{Passphrase: fu.Passphrase}
}
func CreateAndSignupFakeUser(prefix string, g *libkb.GlobalContext) (*FakeUser, error) {
fu, err := NewFakeUser(prefix)
if err != nil {
return nil, err
}
arg := engine.SignupEngineRunArg{
Username: fu.Username,
Email: fu.Email,
InviteCode: testInviteCode,
Passphrase: fu.Passphrase,
DeviceName: "my device",
SkipGPG: true,
SkipMail: true,
}
ctx := &engine.Context{
LogUI: g.UI.GetLogUI(),
GPGUI: &gpgtestui{},
SecretUI: fu.NewSecretUI(),
LoginUI: &libkb.TestLoginUI{Username: fu.Username},
}
s := engine.NewSignupEngine(&arg, g)
if err := engine.RunEngine(s, ctx); err != nil {
return nil, err
}
return fu, nil
}