@@ -184,6 +184,141 @@ func TestClient_CreateOAuthClient(t *testing.T) {
184184 assert .EqualValues (t , "" , actualReq .Description )
185185}
186186
187+ func TestClient_SetOAuthClient (t * testing.T ) {
188+ t .Parallel ()
189+
190+ client , server := NewTestHarness (t )
191+ server .ResponseCode = http .StatusOK
192+
193+ expected := & Key {
194+ ID : "test" ,
195+ KeyType : "client" ,
196+ Key : "thisisatestclient" ,
197+ ExpirySeconds : nil ,
198+ Created : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
199+ Expires : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
200+ Scopes : []string {"all:read" },
201+ Tags : []string {"tag:test" },
202+ Description : "" ,
203+ }
204+
205+ server .ResponseBody = expected
206+
207+ actual , err := client .Keys ().SetOAuthClient (context .Background (), "test" , SetOAuthClientRequest {
208+ Scopes : []string {"all:read" },
209+ Tags : []string {"tag:test" },
210+ })
211+ assert .NoError (t , err )
212+ assert .EqualValues (t , expected , actual )
213+ assert .Equal (t , http .MethodPut , server .Method )
214+ assert .Equal (t , "/api/v2/tailnet/example.com/keys/test" , server .Path )
215+
216+ var actualReq createOAuthClientWithKeyTypeRequest
217+ assert .NoError (t , json .Unmarshal (server .Body .Bytes (), & actualReq ))
218+ assert .EqualValues (t , "client" , actualReq .KeyType )
219+ assert .EqualValues (t , 1 , len (actualReq .Scopes ))
220+ assert .EqualValues (t , "all:read" , actualReq .Scopes [0 ])
221+ assert .EqualValues (t , 1 , len (actualReq .Tags ))
222+ assert .EqualValues (t , "tag:test" , actualReq .Tags [0 ])
223+ assert .EqualValues (t , "" , actualReq .Description )
224+ }
225+
226+ func TestClient_CreateFederatedIdentity (t * testing.T ) {
227+ t .Parallel ()
228+
229+ client , server := NewTestHarness (t )
230+ server .ResponseCode = http .StatusOK
231+
232+ expected := & Key {
233+ ID : "test" ,
234+ KeyType : "federated" ,
235+ Key : "thisisatestclient" ,
236+ ExpirySeconds : nil ,
237+ Created : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
238+ Expires : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
239+ Scopes : []string {"all:read" },
240+ Tags : []string {"tag:test" },
241+ Description : "" ,
242+ Audience : "exampleaud" ,
243+ Subject : "examplesubject" ,
244+ CustomClaimRules : map [string ]string {
245+ "foo" : "bar" ,
246+ },
247+ }
248+
249+ server .ResponseBody = expected
250+
251+ actual , err := client .Keys ().CreateFederatedIdentity (context .Background (), CreateFederatedIdentityRequest {
252+ Scopes : []string {"all:read" },
253+ Tags : []string {"tag:test" },
254+ Subject : "examplesubject" ,
255+ CustomClaimRules : map [string ]string {
256+ "foo" : "bar" ,
257+ },
258+ })
259+ assert .NoError (t , err )
260+ assert .EqualValues (t , expected , actual )
261+ assert .Equal (t , http .MethodPost , server .Method )
262+ assert .Equal (t , "/api/v2/tailnet/example.com/keys" , server .Path )
263+
264+ var actualReq createFederatedIdentityWithKeyTypeRequest
265+ assert .NoError (t , json .Unmarshal (server .Body .Bytes (), & actualReq ))
266+ assert .EqualValues (t , "federated" , actualReq .KeyType )
267+ assert .EqualValues (t , 1 , len (actualReq .Scopes ))
268+ assert .EqualValues (t , "all:read" , actualReq .Scopes [0 ])
269+ assert .EqualValues (t , 1 , len (actualReq .Tags ))
270+ assert .EqualValues (t , "tag:test" , actualReq .Tags [0 ])
271+ assert .EqualValues (t , "" , actualReq .Description )
272+ }
273+
274+ func TestClient_SetFederatedIdentity (t * testing.T ) {
275+ t .Parallel ()
276+
277+ client , server := NewTestHarness (t )
278+ server .ResponseCode = http .StatusOK
279+
280+ expected := & Key {
281+ ID : "test" ,
282+ KeyType : "federated" ,
283+ Key : "thisisatestclient" ,
284+ ExpirySeconds : nil ,
285+ Created : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
286+ Expires : time .Date (2021 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
287+ Scopes : []string {"all:read" },
288+ Tags : []string {"tag:test" },
289+ Description : "" ,
290+ Audience : "exampleaud" ,
291+ Subject : "examplesubject" ,
292+ CustomClaimRules : map [string ]string {
293+ "foo" : "bar" ,
294+ },
295+ }
296+
297+ server .ResponseBody = expected
298+
299+ actual , err := client .Keys ().SetFederatedIdentity (context .Background (), "test" , SetFederatedIdentityRequest {
300+ Scopes : []string {"all:read" },
301+ Tags : []string {"tag:test" },
302+ Subject : "examplesubject" ,
303+ CustomClaimRules : map [string ]string {
304+ "foo" : "bar" ,
305+ },
306+ })
307+ assert .NoError (t , err )
308+ assert .EqualValues (t , expected , actual )
309+ assert .Equal (t , http .MethodPut , server .Method )
310+ assert .Equal (t , "/api/v2/tailnet/example.com/keys/test" , server .Path )
311+
312+ var actualReq createFederatedIdentityWithKeyTypeRequest
313+ assert .NoError (t , json .Unmarshal (server .Body .Bytes (), & actualReq ))
314+ assert .EqualValues (t , "federated" , actualReq .KeyType )
315+ assert .EqualValues (t , 1 , len (actualReq .Scopes ))
316+ assert .EqualValues (t , "all:read" , actualReq .Scopes [0 ])
317+ assert .EqualValues (t , 1 , len (actualReq .Tags ))
318+ assert .EqualValues (t , "tag:test" , actualReq .Tags [0 ])
319+ assert .EqualValues (t , "" , actualReq .Description )
320+ }
321+
187322func TestClient_GetKey (t * testing.T ) {
188323 t .Parallel ()
189324
0 commit comments