@@ -63,7 +63,7 @@ func AddUser(accessKey string, secretKey string, groups []string, policies []str
6363 return response , err
6464}
6565
66- func DeleteUser (bucketName string ) (* http.Response , error ) {
66+ func DeleteUser (userName string ) (* http.Response , error ) {
6767 /*
6868 This is an atomic function to delete user and can be reused across
6969 different functions.
@@ -73,7 +73,7 @@ func DeleteUser(bucketName string) (*http.Response, error) {
7373 }
7474 fmt .Println ("...................................TestAddUser(): Remove user" )
7575 request , err := http .NewRequest (
76- "DELETE" , "http://localhost:9090/api/v1/user?name=" + bucketName , nil )
76+ "DELETE" , "http://localhost:9090/api/v1/user?name=" + userName , nil )
7777 if err != nil {
7878 log .Println (err )
7979 }
@@ -109,6 +109,27 @@ func ListUsers(offset string, limit string) (*http.Response, error) {
109109 return response , err
110110}
111111
112+ func GetUserInformation (userName string ) (* http.Response , error ) {
113+ /*
114+ Helper function to get user information via API:
115+ {{baseUrl}}/user?name=proident velit
116+ */
117+ client := & http.Client {
118+ Timeout : 3 * time .Second ,
119+ }
120+ request , err := http .NewRequest (
121+ "GET" ,
122+ "http://localhost:9090/api/v1/user?name=" + userName ,
123+ nil )
124+ if err != nil {
125+ log .Println (err )
126+ }
127+ request .Header .Add ("Cookie" , fmt .Sprintf ("token=%s" , token ))
128+ request .Header .Add ("Content-Type" , "application/json" )
129+ response , err := client .Do (request )
130+ return response , err
131+ }
132+
112133func TestAddUser (t * testing.T ) {
113134 /*
114135 This is an API Test to add a user via api/v1/users, the intention
@@ -238,3 +259,48 @@ func TestListUsers(t *testing.T) {
238259 }
239260 }
240261}
262+
263+ func TestGetUserInfo (t * testing.T ) {
264+ /*
265+ Test to get the user information via API.
266+ */
267+
268+ // 1. Create the user
269+ fmt .Println ("TestGetUserInfo(): 1. Create the user" )
270+ assert := assert .New (t )
271+ var groups = []string {}
272+ var policies = []string {}
273+ response , err := AddUser ("accessKey" , "secretKey" , groups , policies )
274+ if err != nil {
275+ log .Println (err )
276+ return
277+ }
278+ if response != nil {
279+ fmt .Println ("POST StatusCode:" , response .StatusCode )
280+ assert .Equal (201 , response .StatusCode , "Status Code is incorrect" )
281+ }
282+
283+ // 2. Get user information
284+ fmt .Println ("TestGetUserInfo(): 2. Get user information" )
285+ response , err = GetUserInformation ("accessKey" )
286+ if err != nil {
287+ log .Println (err )
288+ assert .Fail ("There was an error in the response" )
289+ return
290+ }
291+
292+ // 3. Verify user information
293+ fmt .Println ("TestGetUserInfo(): 3. Verify user information" )
294+ if response != nil {
295+ fmt .Println ("POST StatusCode:" , response .StatusCode )
296+ assert .Equal (200 , response .StatusCode , "Status Code is incorrect" )
297+ }
298+ b , err := io .ReadAll (response .Body )
299+ if err != nil {
300+ log .Fatalln (err )
301+ }
302+ fmt .Println (string (b ))
303+ expected := "{\" accessKey\" :\" accessKey\" ,\" memberOf\" :null,\" policy\" :[],\" status\" :\" enabled\" }\n "
304+ obtained := string (b )
305+ assert .Equal (expected , obtained , "User Information is wrong" )
306+ }
0 commit comments