-
This unit test will check authentication with user authorization:
GET
call to endpoint/api/index/
.- Setting Basic Auth that will set the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK and user has the authorization.
-
This unit test will check the user authorization with error password:
GET
call to endpoint/api/index/
.- Setting Basic Auth that will set the request's Authorization header to use HTTP Basic Authentication with the provided username and password {'xxx'}.
- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusUnauthorized (i.e 401),that means test is OK and authorization with error password is working fine.
-
This unit test will check the authentication without user authorization:
GET
call to endpoint/api/index/
.- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusUnauthorized (i.e 401),that means test is OK and authentication without authorization is working fine.