Skip to content

Commit 3ce6624

Browse files
committed
MAJOR: add support for userlists, users and groups
1 parent c89e36c commit 3ce6624

93 files changed

Lines changed: 16140 additions & 2338 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

configure_data_plane.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
366366
api.FrontendGetFrontendsHandler = &handlers.GetFrontendsHandlerImpl{Client: client}
367367
api.FrontendReplaceFrontendHandler = &handlers.ReplaceFrontendHandlerImpl{Client: client, ReloadAgent: ra}
368368

369+
// setup userlist handlers
370+
api.UserlistCreateUserlistHandler = &handlers.CreateUserListHandlerImpl{Client: client, ReloadAgent: ra}
371+
api.UserlistDeleteUserlistHandler = &handlers.DeleteUserListHandlerImpl{Client: client, ReloadAgent: ra}
372+
api.UserlistGetUserlistHandler = &handlers.GetUserListHandlerImpl{Client: client}
373+
api.UserlistGetUserlistsHandler = &handlers.GetUserListsHandlerImpl{Client: client}
374+
375+
// setup user handlers
376+
api.UserCreateUserHandler = &handlers.CreateUserHandlerImpl{Client: client, ReloadAgent: ra}
377+
api.UserDeleteUserHandler = &handlers.DeleteUserHandlerImpl{Client: client, ReloadAgent: ra}
378+
api.UserGetUserHandler = &handlers.GetUserHandlerImpl{Client: client}
379+
api.UserGetUsersHandler = &handlers.GetUsersHandlerImpl{Client: client}
380+
api.UserReplaceUserHandler = &handlers.ReplaceUserHandlerImpl{Client: client, ReloadAgent: ra}
381+
382+
// setup group handlers
383+
api.GroupCreateGroupHandler = &handlers.CreateGroupHandlerImpl{Client: client, ReloadAgent: ra}
384+
api.GroupDeleteGroupHandler = &handlers.DeleteGroupHandlerImpl{Client: client, ReloadAgent: ra}
385+
api.GroupGetGroupHandler = &handlers.GetGroupHandlerImpl{Client: client}
386+
api.GroupGetGroupsHandler = &handlers.GetGroupsHandlerImpl{Client: client}
387+
api.GroupReplaceGroupHandler = &handlers.ReplaceGroupHandlerImpl{Client: client, ReloadAgent: ra}
388+
369389
// setup server handlers
370390
api.ServerCreateServerHandler = &handlers.CreateServerHandlerImpl{Client: client, ReloadAgent: ra}
371391
api.ServerDeleteServerHandler = &handlers.DeleteServerHandlerImpl{Client: client, ReloadAgent: ra}

e2e/tests/groups/add.bats

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "groups: Add a group" {
27+
resource_post "$_GROUPS_BASE_PATH" "data/post.json" "userlist=first&=force_reload=true"
28+
assert_equal "$SC" 202
29+
}
30+
31+
@test "groups: Add a group to a non existing user list" {
32+
resource_post "$_GROUPS_BASE_PATH" "data/post.json" "userlist=fake&=force_reload=true"
33+
assert_equal "$SC" 400
34+
}
35+
36+
@test "groups: Add a malformed group" {
37+
resource_post "$_GROUPS_BASE_PATH" "data/empty.json" "userlist=first&force_reload=true"
38+
assert_equal "$SC" 422
39+
}

e2e/tests/groups/data/empty.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

e2e/tests/groups/data/haproxy.cfg

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
userlist first
11+
group G1 users tiger,scott
12+
group G2 users scott
13+
user tiger password $6$k6y3o.eP$JlKBx9za9667qe4xHSwRv6J.C0/D7cV91
14+
user scott insecure-password elgato
15+
16+
userlist second
17+
group one
18+
group two
19+
group three
20+
user neo password JlKBxxHSwRv6J.C0/D7cV91 groups one
21+
user thomas insecure-password white-rabbit groups one,two
22+
user anderson insecure-password hello groups two
23+
24+
userlist empty
25+
26+
userlist add_test
27+
group G3
28+
group G4
29+
30+
userlist replace_test
31+
group zion
32+
group io
33+
user trinity insecure-password the-one groups zion
34+
35+
userlist delete_test
36+
group antivirus
37+
group virus
38+
user smith insecure-password cloning groups virus

e2e/tests/groups/data/post.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"index": 0,
3+
"name": "new",
4+
"users": null
5+
}

e2e/tests/groups/data/replace.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"index": 0,
3+
"name": "enigma",
4+
"users": "trinity"
5+
}

e2e/tests/groups/delete.bats

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "groups: Delete a group" {
27+
resource_delete "$_GROUPS_BASE_PATH/antivirus" "userlist=delete_test"
28+
assert_equal "$SC" 202
29+
}
30+
31+
@test "groups: Delete a group and reload" {
32+
resource_delete "$_GROUPS_BASE_PATH/antivirus" "userlist=delete_test&force_reload=true"
33+
assert_equal "$SC" 204
34+
}
35+
36+
@test "groups: Delete a group that is assigned to an existing user" {
37+
# resource_delete "$_GROUPS_BASE_PATH/virus" "userlist=delete_test&force_reload=true"
38+
# assert_equal "$SC" 400
39+
}
40+
41+
@test "groups: Delete a non existing group" {
42+
resource_delete "$_GROUPS_BASE_PATH/fake" "userlist=delete_test&force_reload=true"
43+
assert_equal "$SC" 404
44+
}
45+
46+
@test "groups: Delete a non existing group in a non existing userlist" {
47+
resource_delete "$_GROUPS_BASE_PATH/fake" "userlist=fake&force_reload=true"
48+
assert_equal "$SC" 404
49+
}

e2e/tests/groups/get.bats

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "groups: Return group G1 from a userlist" {
27+
resource_get "$_GROUPS_BASE_PATH/G1" "userlist=first"
28+
assert_equal "$SC" 200
29+
assert_equal "$(get_json_path "$BODY" ".data.name")" "G1"
30+
assert_equal "$(get_json_path "$BODY" ".data.users")" "tiger,scott"
31+
}
32+
33+
@test "groups: Return group G2 from a userlist" {
34+
resource_get "$_GROUPS_BASE_PATH/G2" "userlist=first"
35+
assert_equal "$SC" 200
36+
assert_equal "$(get_json_path "$BODY" ".data.name")" "G2"
37+
assert_equal "$(get_json_path "$BODY" ".data.users")" "scott"
38+
}
39+
40+
@test "groups: Return a non existing group from a userlist" {
41+
resource_get "$_GROUPS_BASE_PATH/fake" "userlist=first"
42+
assert_equal "$SC" 404
43+
}
44+
45+
@test "groups: Return a non existing group from a non existing userlist" {
46+
resource_get "$_GROUPS_BASE_PATH/fake" "userlist=fake"
47+
assert_equal "$SC" 404
48+
}
49+
50+
@test "groups: Return group one from a userlist" {
51+
resource_get "$_GROUPS_BASE_PATH/one" "userlist=second"
52+
assert_equal "$SC" 200
53+
assert_equal "$(get_json_path "$BODY" ".data.name")" "one"
54+
assert_equal "$(get_json_path "$BODY" ".data.users")" null
55+
}
56+
57+
@test "groups: Return group two from a userlist" {
58+
resource_get "$_GROUPS_BASE_PATH/two" "userlist=second"
59+
assert_equal "$SC" 200
60+
assert_equal "$(get_json_path "$BODY" ".data.name")" "two"
61+
assert_equal "$(get_json_path "$BODY" ".data.users")" null
62+
}
63+
64+
@test "groups: Return group three from a userlist" {
65+
resource_get "$_GROUPS_BASE_PATH/three" "userlist=second"
66+
assert_equal "$SC" 200
67+
assert_equal "$(get_json_path "$BODY" ".data.name")" "three"
68+
assert_equal "$(get_json_path "$BODY" ".data.users")" null
69+
}

e2e/tests/groups/list.bats

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "groups: Return an array of groups from userlist first" {
27+
resource_get "$_GROUPS_BASE_PATH" "userlist=first"
28+
assert_equal "$SC" 200
29+
assert_equal "$(get_json_path "${BODY}" ".data | length")" 2
30+
31+
assert_equal "$(get_json_path "${BODY}" ".data[0].name" )" "G1"
32+
assert_equal "$(get_json_path "${BODY}" ".data[0].users" )" "tiger,scott"
33+
34+
assert_equal "$(get_json_path "${BODY}" ".data[1].name" )" "G2"
35+
assert_equal "$(get_json_path "${BODY}" ".data[1].users" )" "scott"
36+
}
37+
38+
@test "groups: Return an array of groups from userlist second" {
39+
resource_get "$_GROUPS_BASE_PATH" "userlist=second"
40+
assert_equal "$SC" 200
41+
assert_equal "$(get_json_path "${BODY}" ".data | length")" 3
42+
43+
assert_equal "$(get_json_path "${BODY}" ".data[0].name" )" "one"
44+
assert_equal "$(get_json_path "${BODY}" ".data[0].users" )" null
45+
46+
assert_equal "$(get_json_path "${BODY}" ".data[1].name" )" "two"
47+
assert_equal "$(get_json_path "${BODY}" ".data[1].users" )" null
48+
49+
assert_equal "$(get_json_path "${BODY}" ".data[2].name" )" "three"
50+
assert_equal "$(get_json_path "${BODY}" ".data[2].users" )" null
51+
}
52+
53+
@test "groups: Return an array of groups from userlist empty" {
54+
resource_get "$_GROUPS_BASE_PATH" "userlist=empty"
55+
assert_equal "$SC" 200
56+
assert_equal "$(get_json_path "${BODY}" ".data | length")" 0
57+
}
58+
59+
@test "groups: Return an array of groups from non existing userlist" {
60+
resource_get "$_GROUPS_BASE_PATH" "userlist=fake"
61+
assert_equal "$SC" 404
62+
}

e2e/tests/groups/replace.bats

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "groups: Replace a group" {
27+
resource_put "$_GROUPS_BASE_PATH/zion" "data/replace.json" "userlist=replace_test&force_reload=true"
28+
assert_equal "$SC" 200
29+
}
30+
31+
@test "groups: Replace a group with malformed data" {
32+
resource_put "$_GROUPS_BASE_PATH/io" "data/empty.json" "userlist=replace_test&force_reload=true"
33+
assert_equal "$SC" 422
34+
}
35+
36+
@test "groups: Replace a non existing group" {
37+
resource_put "$_GROUPS_BASE_PATH/fake" "data/replace.json" "userlist=replace_test&force_reload=true"
38+
assert_equal "$SC" 404
39+
}
40+
41+
@test "groups: Replace a non existing group in a non existing user list" {
42+
resource_put "$_GROUPS_BASE_PATH/1000" "data/replace.json" "userlist=fake&force_reload=true"
43+
assert_equal "$SC" 404
44+
}
45+

0 commit comments

Comments
 (0)