@@ -13,7 +13,7 @@ import (
1313 "github.com/stretchr/testify/assert"
1414)
1515
16- func TestClient_CreateKey (t * testing.T ) {
16+ func TestClient_CreateAuthKey (t * testing.T ) {
1717 t .Parallel ()
1818
1919 client , server := NewTestHarness (t )
@@ -36,7 +36,7 @@ func TestClient_CreateKey(t *testing.T) {
3636
3737 server .ResponseBody = expected
3838
39- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
39+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
4040 Capabilities : capabilities ,
4141 })
4242 assert .NoError (t , err )
@@ -51,7 +51,7 @@ func TestClient_CreateKey(t *testing.T) {
5151 assert .EqualValues (t , "" , actualReq .Description )
5252}
5353
54- func TestClient_CreateKeyWithExpirySeconds (t * testing.T ) {
54+ func TestClient_CreateAuthKeyWithExpirySeconds (t * testing.T ) {
5555 t .Parallel ()
5656
5757 client , server := NewTestHarness (t )
@@ -74,7 +74,7 @@ func TestClient_CreateKeyWithExpirySeconds(t *testing.T) {
7474
7575 server .ResponseBody = expected
7676
77- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
77+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
7878 Capabilities : capabilities ,
7979 ExpirySeconds : 1440 ,
8080 })
@@ -90,7 +90,7 @@ func TestClient_CreateKeyWithExpirySeconds(t *testing.T) {
9090 assert .EqualValues (t , "" , actualReq .Description )
9191}
9292
93- func TestClient_CreateKeyWithDescription (t * testing.T ) {
93+ func TestClient_CreateAuthKeyWithDescription (t * testing.T ) {
9494 t .Parallel ()
9595
9696 client , server := NewTestHarness (t )
@@ -113,7 +113,7 @@ func TestClient_CreateKeyWithDescription(t *testing.T) {
113113
114114 server .ResponseBody = expected
115115
116- actual , err := client .Keys ().Create (context .Background (), CreateKeyRequest {
116+ actual , err := client .Keys ().CreateAuthKey (context .Background (), CreateKeyRequest {
117117 Capabilities : capabilities ,
118118 Description : "key description" ,
119119 })
@@ -129,6 +129,41 @@ func TestClient_CreateKeyWithDescription(t *testing.T) {
129129 assert .EqualValues (t , "key description" , actualReq .Description )
130130}
131131
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+
132167func TestClient_GetKey (t * testing.T ) {
133168 t .Parallel ()
134169
0 commit comments