-
Notifications
You must be signed in to change notification settings - Fork 16
/
opaitokens_test.go
117 lines (102 loc) · 2.99 KB
/
opaitokens_test.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
package opaitokens
import (
"fmt"
"testing"
)
func TestUserCase(t *testing.T) {
email := "[email protected]"
password := "xxxxx"
tokens := NewOpaiTokens(email, password, true)
token := tokens.FetchToken()
fmt.Printf("token info: %v\n", token)
accessToken := token.OpenaiToken.AccessToken
// use the access token
fmt.Printf("i am using access token: %v \n", accessToken)
token = tokens.RefreshToken()
fmt.Printf("token info again: %v\n", token)
accessToken = token.RefreshedToken.AccessToken
//use the refresh token
fmt.Println("i am using refresh token: ", accessToken)
}
func TestNewOpaiTokensWithMFA(t *testing.T) {
email := "[email protected]"
password := "xxxxx"
mfa := "your mfa code"
tokens := NewOpaiTokensWithMFA(email, password, mfa, false)
token := tokens.FetchToken()
fmt.Printf("token info: %v\n", token)
accessToken := token.OpenaiToken.AccessToken
// use the access token
fmt.Printf("i am using access token: %v \n", accessToken)
token = tokens.RefreshToken()
fmt.Printf("token info again: %v\n", token)
accessToken = token.RefreshedToken.AccessToken
//use the refresh token
fmt.Println("i am using refresh token: ", accessToken)
}
func TestFakeOpenTokens_FetchSharedToken(t *testing.T) {
tokens := FakeOpenTokens{}
account := OpenaiAccount{
Email: "[email protected]",
Password: "xx@xx",
MFA: "",
}
// 设置自己的uniqueName
token, err := tokens.FetchSharedToken(account, "fireinrain")
if err != nil {
fmt.Println("error: ", err)
}
fmt.Println(token.TokenKey)
}
func TestFakeOpenTokens_FetchPooledToken(t *testing.T) {
var accounts []OpenaiAccount
account := OpenaiAccount{
Email: "[email protected]",
Password: "xx@xx",
MFA: "",
}
accounts = append(accounts, account)
tokens := FakeOpenTokens{}
token, err := tokens.FetchPooledToken(accounts, "fireinrain")
if err != nil {
fmt.Println("error: ", err)
}
fmt.Println(token)
}
func TestFakeOpenTokens_FetchMixedPooledToken(t *testing.T) {
var accounts []OpenaiAccount
account := OpenaiAccount{
Email: "[email protected]",
Password: "xx@xx",
MFA: "",
}
accounts = append(accounts, account)
var skKeys []string
skKeys = append(skKeys, "sk-xxxxxx")
tokens := FakeOpenTokens{}
token, err := tokens.FetchMixedPooledToken(accounts, skKeys, "fireinrain")
if err != nil {
fmt.Println("error: ", err)
}
fmt.Println(token)
}
func TestFakeOpenTokens_FetchSharedTokenWithRefreshToken(t *testing.T) {
openaiAccountEmail := "[email protected]"
openaiRefreshToken := "xxxxxxxx"
uniqueName := "fireinrain"
receiver := FakeOpenTokens{}
token, err := receiver.FetchSharedTokenWithRefreshToken(openaiAccountEmail, openaiRefreshToken, uniqueName)
if err != nil {
fmt.Println("error: ", err)
}
fmt.Printf("%v\n", token)
}
func TestFakeOpenTokens_FetchAccessTokenBySessionToken(t *testing.T) {
receiver := &FakeOpenTokens{}
session_token := "xxxxxxxxxxx"
token, err := receiver.FetchAccessTokenBySessionToken(session_token)
if err != nil {
println("error: ", err)
}
fmt.Println(token.AccessToken)
}