-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow updates(first_name, last_name, disable, password) to built-in u…
…sers Signed-off-by: Yuva Shankar <[email protected]>
- Loading branch information
Showing
6 changed files
with
262 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package systemtests | ||
|
||
import ( | ||
"github.com/contiv/ccn_proxy/common/types" | ||
"github.com/contiv/ccn_proxy/proxy" | ||
. "gopkg.in/check.v1" | ||
) | ||
|
||
// TestLocalUserEndpoints tests ccn_proxy's local user endpoints | ||
func (s *systemtestSuite) TestLocalUserEndpoints(c *C) { | ||
|
||
runTest(func(p *proxy.Server, ms *MockServer) { | ||
token := adminToken(c) | ||
endpoint := "/api/v1/ccn_proxy/local_users" | ||
|
||
resp, body := proxyGet(c, token, endpoint) | ||
c.Assert(resp.StatusCode, Equals, 200) | ||
c.Assert(len(body), Not(Equals), 0) | ||
|
||
// add new local_user to the system | ||
data := `{"username":"testuser","password":"testpwd", "disable":false}` | ||
respBody := `{"username":"testuser","first_name":"","last_name":"","disable":false}` | ||
s.addLocalUser(c, data, respBody, token) | ||
|
||
// get `testuser` | ||
endpoint = "/api/v1/ccn_proxy/local_users/testuser" | ||
resp, body = proxyGet(c, token, endpoint) | ||
c.Assert(resp.StatusCode, Equals, 200) | ||
c.Assert(string(body), DeepEquals, respBody) | ||
|
||
// try login using `testuser` | ||
testuserToken := loginAs(c, "testuser", "testpwd") | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
|
||
// delete `testuser` | ||
resp, body = proxyDelete(c, token, endpoint) | ||
c.Assert(resp.StatusCode, Equals, 204) | ||
c.Assert(len(body), Equals, 0) | ||
|
||
// get `testuser` | ||
resp, body = proxyGet(c, token, endpoint) | ||
c.Assert(resp.StatusCode, Equals, 404) | ||
c.Assert(len(body), Equals, 0) | ||
|
||
}) | ||
} | ||
|
||
// TestLocalUserUpdateEndpoint tests ccn_proxy's local user update endpoint | ||
func (s *systemtestSuite) TestLocalUserUpdateEndpoint(c *C) { | ||
|
||
runTest(func(p *proxy.Server, ms *MockServer) { | ||
token := adminToken(c) | ||
|
||
// add new local_user to the system | ||
data := `{"username":"testuser","password":"testpwd", "disable":false}` | ||
respBody := `{"username":"testuser","first_name":"","last_name":"","disable":false}` | ||
s.addLocalUser(c, data, respBody, token) | ||
|
||
// try login using `testuser` | ||
testuserToken := loginAs(c, "testuser", "testpwd") | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
|
||
// update `testuser` details | ||
data = `{"first_name":"Temp", "last_name": "User"}` | ||
respBody = `{"username":"testuser","first_name":"Temp","last_name":"User","disable":false}` | ||
s.updateLocalUser(c, "testuser", data, respBody, token) | ||
|
||
// try login again using `testuser` | ||
testuserToken = loginAs(c, "testuser", "testpwd") | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
|
||
// update `testuser` password | ||
data = `{"password":"test"}` | ||
s.updateLocalUser(c, "testuser", data, respBody, token) | ||
|
||
// try login again using old password | ||
testuserToken, resp, err := login("testuser", "testpwd") | ||
c.Assert(err, IsNil) | ||
c.Assert(resp.StatusCode, Equals, 401) | ||
c.Assert(len(testuserToken), Equals, 0) | ||
|
||
// try login again using new password | ||
testuserToken = loginAs(c, "testuser", "test") | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
}) | ||
} | ||
|
||
// TestBuiltInUserUpdate tests built-in user update functionality | ||
func (s *systemtestSuite) TestBuiltInUserUpdate(c *C) { | ||
runTest(func(p *proxy.Server, ms *MockServer) { | ||
token := adminToken(c) | ||
|
||
for _, username := range []string{types.Admin.String(), types.Ops.String()} { | ||
// update user details | ||
data := `{"first_name":"Built-in", "last_name": "User", "disable":false}` | ||
respBody := `{"username":"` + username + `","first_name":"Built-in","last_name":"User","disable":false}` | ||
s.updateLocalUser(c, username, data, respBody, token) | ||
|
||
// login | ||
testuserToken := loginAs(c, username, username) | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
|
||
// update password | ||
data = `{"password":"test"}` | ||
s.updateLocalUser(c, username, data, respBody, token) | ||
|
||
// try login again using old password | ||
testuserToken, resp, err := login(username, username) | ||
c.Assert(err, IsNil) | ||
c.Assert(resp.StatusCode, Equals, 401) | ||
c.Assert(len(testuserToken), Equals, 0) | ||
|
||
// try login again using new password | ||
testuserToken = loginAs(c, username, "test") | ||
c.Assert(len(testuserToken), Not(Equals), 0) | ||
|
||
// revert password so that it wont block other tests | ||
data = `{"password":"` + username + `"}` | ||
s.updateLocalUser(c, username, data, respBody, token) | ||
} | ||
}) | ||
} | ||
|
||
// addLocalUser helper function for the tests | ||
func (s *systemtestSuite) addLocalUser(c *C, data, expectedRespBody, token string) { | ||
endpoint := "/api/v1/ccn_proxy/local_users" | ||
|
||
resp, body := proxyPost(c, token, endpoint, []byte(data)) | ||
c.Assert(resp.StatusCode, Equals, 201) | ||
c.Assert(string(body), DeepEquals, expectedRespBody) | ||
} | ||
|
||
// updateLocalUser helper function for the tests | ||
func (s *systemtestSuite) updateLocalUser(c *C, username, data, expectedRespBody, token string) { | ||
endpoint := "/api/v1/ccn_proxy/local_users/" + username | ||
|
||
resp, body := proxyPatch(c, token, endpoint, []byte(data)) | ||
c.Assert(resp.StatusCode, Equals, 200) | ||
c.Assert(string(body), DeepEquals, expectedRespBody) | ||
} |