-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
82 lines (61 loc) · 1.69 KB
/
utils.go
File metadata and controls
82 lines (61 loc) · 1.69 KB
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
//go:build integration
package integration
import (
"context"
"crypto/rand"
"math/big"
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/corbado/corbado-go/v2"
"github.com/corbado/corbado-go/v2/pkg/generated/api"
)
func SDK(t *testing.T) corbado.SDK {
config, err := corbado.NewConfigFromEnv()
require.NoError(t, err)
sdk, err := corbado.NewSDK(config)
require.NoError(t, err)
return sdk
}
func CreateRandomTestName(t *testing.T) *string {
value, err := generateString(10)
require.NoError(t, err)
return &value
}
func CreateRandomTestEmail(t *testing.T) string {
value, err := generateString(10)
require.NoError(t, err)
return "integration-test+" + value + "@corbado.com"
}
func CreateUser(t *testing.T) string {
rsp, err := SDK(t).Users().Create(context.TODO(), api.UserCreateReq{
FullName: CreateRandomTestName(t),
Status: "active",
})
require.NoError(t, err)
return rsp.UserID
}
func CreateIdentifier(t *testing.T) string {
userID := CreateUser(t)
email := CreateRandomTestEmail(t)
rsp, err := SDK(t).Identifiers().Create(context.TODO(), userID, api.IdentifierCreateReq{
IdentifierType: "email",
IdentifierValue: email,
Status: "verified",
})
require.NoError(t, err)
return rsp.IdentifierID
}
func generateString(length int) (string, error) {
// Removed I, 1, 0 and O because of risk of confusion
const letters = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz23456789"
res := make([]byte, length)
for i := 0; i < length; i++ {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
return "", errors.WithStack(err)
}
res[i] = letters[num.Int64()]
}
return string(res), nil
}