@@ -2,10 +2,40 @@ package dtrack
22
33import (
44 "context"
5- "github.com/stretchr/testify/require "
5+ "strings "
66 "testing"
7+
8+ "github.com/stretchr/testify/require"
79)
810
11+ func TestGenerateAPIKey_v4_12 (t * testing.T ) {
12+ client := setUpContainer (t , testContainerOptions {
13+ Version : "4.12.7" ,
14+ APIPermissions : []string {
15+ PermissionAccessManagement ,
16+ },
17+ })
18+
19+ team , err := client .Team .Create (context .Background (), Team {
20+ Name : "GenerateAPIKey_v4_12" ,
21+ })
22+ require .NoError (t , err )
23+
24+ key , err := client .Team .GenerateAPIKey (context .Background (), team .UUID )
25+ require .NoError (t , err )
26+
27+ keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
28+ require .NoError (t , err )
29+ require .Equal (t , len (keys ), 1 )
30+ require .Equal (t , keys [0 ].Key , key .Key )
31+ require .Equal (t , keys [0 ].MaskedKey , key .MaskedKey )
32+ require .Equal (t , keys [0 ].Comment , "" )
33+ require .Equal (t , key .Comment , "" )
34+ require .Equal (t , keys [0 ].Created , key .Created )
35+ require .Equal (t , len (key .Key ), 36 )
36+ require .Equal (t , len (key .MaskedKey ), 36 )
37+ }
38+
939func TestGenerateAPIKey (t * testing.T ) {
1040 client := setUpContainer (t , testContainerOptions {
1141 APIPermissions : []string {
@@ -24,7 +54,42 @@ func TestGenerateAPIKey(t *testing.T) {
2454 keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
2555 require .NoError (t , err )
2656 require .Equal (t , len (keys ), 1 )
27- require .Equal (t , keys [0 ].Key , key )
57+ require .Equal (t , keys [0 ].PublicId , key .PublicId )
58+ require .Equal (t , keys [0 ].Comment , key .Comment )
59+ require .Equal (t , keys [0 ].Created , key .Created )
60+ require .Equal (t , keys [0 ].MaskedKey , key .MaskedKey )
61+ require .Equal (t , keys [0 ].Key , "" )
62+ require .Equal (t , keys [0 ].Legacy , false )
63+ require .Equal (t , len (keys [0 ].PublicId ), 8 )
64+ require .Equal (t , keys [0 ].MaskedKey , "odt_" + key .PublicId + strings .Repeat ("*" , 32 ))
65+ }
66+
67+ func TestDeleteAPIKey_v4_12 (t * testing.T ) {
68+ client := setUpContainer (t , testContainerOptions {
69+ Version : "4.12.7" ,
70+ APIPermissions : []string {
71+ PermissionAccessManagement ,
72+ },
73+ })
74+
75+ team , err := client .Team .Create (context .Background (), Team {
76+ Name : "DeleteAPIKey_v4_12" ,
77+ })
78+ require .NoError (t , err )
79+
80+ key , err := client .Team .GenerateAPIKey (context .Background (), team .UUID )
81+ require .NoError (t , err )
82+
83+ keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
84+ require .NoError (t , err )
85+ require .Equal (t , len (keys ), 1 )
86+
87+ err = client .Team .DeleteAPIKey (context .Background (), key .Key )
88+ require .NoError (t , err )
89+
90+ keys , err = client .Team .GetAPIKeys (context .Background (), team .UUID )
91+ require .NoError (t , err )
92+ require .Empty (t , keys )
2893}
2994
3095func TestDeleteAPIKey (t * testing.T ) {
@@ -42,14 +107,46 @@ func TestDeleteAPIKey(t *testing.T) {
42107 key , err := client .Team .GenerateAPIKey (context .Background (), team .UUID )
43108 require .NoError (t , err )
44109
45- err = client .Team .DeleteAPIKey (context .Background (), key )
110+ keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
111+ require .NoError (t , err )
112+ require .Equal (t , len (keys ), 1 )
113+
114+ err = client .Team .DeleteAPIKey (context .Background (), key .PublicId )
46115 require .NoError (t , err )
47116
48- keys , err : = client .Team .GetAPIKeys (context .Background (), team .UUID )
117+ keys , err = client .Team .GetAPIKeys (context .Background (), team .UUID )
49118 require .NoError (t , err )
50119 require .Empty (t , keys )
51120}
52121
122+ func TestUpdateAPIKeyComment_v4_12 (t * testing.T ) {
123+ client := setUpContainer (t , testContainerOptions {
124+ Version : "4.12.7" ,
125+ APIPermissions : []string {
126+ PermissionAccessManagement ,
127+ },
128+ })
129+
130+ team , err := client .Team .Create (context .Background (), Team {
131+ Name : "UpdateAPIKeyComment_v4_12" ,
132+ })
133+ require .NoError (t , err )
134+
135+ key , err := client .Team .GenerateAPIKey (context .Background (), team .UUID )
136+ require .NoError (t , err )
137+ require .Equal (t , key .Comment , "" )
138+
139+ comment , err := client .Team .UpdateAPIKeyComment (context .Background (), key .Key , "test-comment" )
140+ require .NoError (t , err )
141+ require .Equal (t , comment , "test-comment" )
142+
143+ keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
144+ require .NoError (t , err )
145+ require .Equal (t , len (keys ), 1 )
146+ require .Equal (t , keys [0 ].Key , key .Key )
147+ require .Equal (t , keys [0 ].Comment , "test-comment" )
148+ }
149+
53150func TestUpdateAPIKeyComment (t * testing.T ) {
54151 client := setUpContainer (t , testContainerOptions {
55152 APIPermissions : []string {
@@ -64,14 +161,15 @@ func TestUpdateAPIKeyComment(t *testing.T) {
64161
65162 key , err := client .Team .GenerateAPIKey (context .Background (), team .UUID )
66163 require .NoError (t , err )
164+ require .Equal (t , key .Comment , "" )
67165
68- comment , err := client .Team .UpdateAPIKeyComment (context .Background (), key , "test-comment" )
166+ comment , err := client .Team .UpdateAPIKeyComment (context .Background (), key . PublicId , "test-comment" )
69167 require .NoError (t , err )
70168 require .Equal (t , comment , "test-comment" )
71169
72170 keys , err := client .Team .GetAPIKeys (context .Background (), team .UUID )
73171 require .NoError (t , err )
74172 require .Equal (t , len (keys ), 1 )
75- require .Equal (t , keys [0 ].Key , key )
173+ require .Equal (t , keys [0 ].PublicId , key . PublicId )
76174 require .Equal (t , keys [0 ].Comment , "test-comment" )
77175}
0 commit comments