cURL – handle cookie

I used to write RestAPI testing with Jersey test framework. Now I am going to write RestAPI testing against Spring Boot. They provided a Spring MockMVC test framework but, it is too much to me. I decided to use cURL to do that and wrap my owned cURL test framework with my favorite lang, probably Go lang.

Here are the commands to use cookie to  get authentation and then do further action.

Firstly have to know how the credential was submitted.

cURL-cookie.png

C:\Windows\system32>curl -i -X POST -d j_username=13400000000 -d j_password=”pnM
rnZDU2QGuCz8bDV8lzQ==” -c D:\cookie.txt http://xxx:8081/api/login
HTTP/1.1 200
Server: nginx/1.12.0
Date: Fri, 17 Nov 2017 09:19:54 GMT
Content-Length: 0
Connection: keep-alive
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: SESSION=18bfd40d-40fd-43ab-ad30-3e830da24dac;path=/;HttpOnly

 

C:\Windows\system32>curl -i –header “Accept:application/json” -X GET -b D:\cook
ie.txt http://xxxx:8081/runtime/tasks
HTTP/1.1 200
Server: nginx/1.12.0
Date: Fri, 17 Nov 2017 09:21:04 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: SAMEORIGIN

{“data”:[],”total”:0,”start”:0,”sort”:”id”,”order”:”asc”,”size”:0}
C:\Windows\system32>