@@ -13,7 +13,7 @@ import (
13
13
"github.com/stretchr/testify/assert"
14
14
)
15
15
16
- func TestClient_CreateKey (t * testing.T ) {
16
+ func TestClient_CreateAuthKey (t * testing.T ) {
17
17
t .Parallel ()
18
18
19
19
client , server := NewTestHarness (t )
@@ -36,7 +36,7 @@ func TestClient_CreateKey(t *testing.T) {
36
36
37
37
server .ResponseBody = expected
38
38
39
- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
39
+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
40
40
Capabilities : capabilities ,
41
41
})
42
42
assert .NoError (t , err )
@@ -51,7 +51,7 @@ func TestClient_CreateKey(t *testing.T) {
51
51
assert .EqualValues (t , "" , actualReq .Description )
52
52
}
53
53
54
- func TestClient_CreateKeyWithExpirySeconds (t * testing.T ) {
54
+ func TestClient_CreateAuthKeyWithExpirySeconds (t * testing.T ) {
55
55
t .Parallel ()
56
56
57
57
client , server := NewTestHarness (t )
@@ -74,7 +74,7 @@ func TestClient_CreateKeyWithExpirySeconds(t *testing.T) {
74
74
75
75
server .ResponseBody = expected
76
76
77
- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
77
+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
78
78
Capabilities : capabilities ,
79
79
ExpirySeconds : 1440 ,
80
80
})
@@ -90,7 +90,7 @@ func TestClient_CreateKeyWithExpirySeconds(t *testing.T) {
90
90
assert .EqualValues (t , "" , actualReq .Description )
91
91
}
92
92
93
- func TestClient_CreateKeyWithDescription (t * testing.T ) {
93
+ func TestClient_CreateAuthKeyWithDescription (t * testing.T ) {
94
94
t .Parallel ()
95
95
96
96
client , server := NewTestHarness (t )
@@ -113,7 +113,7 @@ func TestClient_CreateKeyWithDescription(t *testing.T) {
113
113
114
114
server .ResponseBody = expected
115
115
116
- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
116
+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
117
117
Capabilities : capabilities ,
118
118
Description : "key description" ,
119
119
})
@@ -129,6 +129,41 @@ func TestClient_CreateKeyWithDescription(t *testing.T) {
129
129
assert .EqualValues (t , "key description" , actualReq .Description )
130
130
}
131
131
132
+ func TestClient_CreateOAuthClient (t * testing.T ) {
133
+ t .Parallel ()
134
+
135
+ client , server := NewTestHarness (t )
136
+ server .ResponseCode = http .StatusOK
137
+
138
+ expected := & Key {
139
+ ID : "test" ,
140
+ Key : "thisisatestclient" ,
141
+ Created : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
142
+ Expires : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
143
+ Description : "" ,
144
+ }
145
+
146
+ server .ResponseBody = expected
147
+
148
+ actual , err := client .Keys ().CreateOAuthClient (context .Background (), CreateOAuthClientRequest {
149
+ Scopes : []string {"all:read" },
150
+ Tags : []string {"tag:test" },
151
+ })
152
+ assert .NoError (t , err )
153
+ assert .EqualValues (t , expected , actual )
154
+ assert .Equal (t , http .MethodPost , server .Method )
155
+ assert .Equal (t , "/api/v2/tailnet/example.com/keys" , server .Path )
156
+
157
+ var actualReq createOAuthClientWithKeyTypeRequest
158
+ assert .NoError (t , json .Unmarshal (server .Body .Bytes (), & actualReq ))
159
+ assert .EqualValues (t , "oauthclient" , actualReq .KeyType )
160
+ assert .EqualValues (t , 1 , len (actualReq .Scopes ))
161
+ assert .EqualValues (t , "all:read" , actualReq .Scopes [0 ])
162
+ assert .EqualValues (t , 1 , len (actualReq .Tags ))
163
+ assert .EqualValues (t , "tag:test" , actualReq .Tags [0 ])
164
+ assert .EqualValues (t , "" , actualReq .Description )
165
+ }
166
+
132
167
func TestClient_GetKey (t * testing.T ) {
133
168
t .Parallel ()
134
169
0 commit comments