-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support online validation with Konnect (#1335)
* feat: support online validation with Konnect * tests: Added e2e tests for gateway validation with konnect. Also, this change adds a conditional that ensures that rbac flag used with konnect mode, gives an legible error to the user. * chore: lint fix * chore: removed workspace flag test as it is not supported with konnect * tests: added rbac-resources file * refactor: refactored tests and code to add all konnect validate usecases * chore: fixed workspace setting for Konnect check * chore: added mutually exclusive flags for konnect compatibility * chore: fixed logical error * chore: fixed descripancy in info due to preRun order in cobra * chore: added corrections based on PR review * removing unrelated code for vault validation --------- Co-authored-by: Prashansa Kulshrestha <[email protected]>
- Loading branch information
1 parent
b09aa3e
commit e09888d
Showing
8 changed files
with
307 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
_format_version: "3.0" | ||
_konnect: | ||
control_plane_name: default | ||
services: | ||
- connect_timeout: 60000 | ||
id: 58076db2-28b6-423b-ba39-a797193017f7 | ||
host: mockbin.org | ||
name: svc1 | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
routes: | ||
- name: r1 | ||
id: 87b6a97e-f3f7-4c47-857a-7464cb9e202b | ||
https_redirect_status_code: 301 | ||
paths: | ||
- /r1 |
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,18 @@ | ||
_format_version: "1.1" | ||
_konnect: | ||
control_plane_name: default | ||
services: | ||
- connect_timeout: 60000 | ||
id: 58076db2-28b6-423b-ba39-a797193017f7 | ||
host: mockbin.org | ||
name: svc1 | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
routes: | ||
- name: r1 | ||
id: 87b6a97e-f3f7-4c47-857a-7464cb9e202b | ||
https_redirect_status_code: 301 | ||
paths: | ||
- /r1 |
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,16 @@ | ||
_format_version: "3.0" | ||
services: | ||
- connect_timeout: 60000 | ||
id: 58076db2-28b6-423b-ba39-a797193017f7 | ||
host: mockbin.org | ||
name: svc1 | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
routes: | ||
- name: r1 | ||
id: 87b6a97e-f3f7-4c47-857a-7464cb9e202b | ||
https_redirect_status_code: 301 | ||
paths: | ||
- /r1 |
17 changes: 17 additions & 0 deletions
17
tests/integration/testdata/validate/konnect_no_version.yaml
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,17 @@ | ||
_konnect: | ||
control_plane_name: default | ||
services: | ||
- connect_timeout: 60000 | ||
id: 58076db2-28b6-423b-ba39-a797193017f7 | ||
host: mockbin.org | ||
name: svc1 | ||
port: 80 | ||
protocol: http | ||
read_timeout: 60000 | ||
retries: 5 | ||
routes: | ||
- name: r1 | ||
id: 87b6a97e-f3f7-4c47-857a-7464cb9e202b | ||
https_redirect_status_code: 301 | ||
paths: | ||
- /r1 |
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,93 @@ | ||
_format_version: "3.0" | ||
_konnect: | ||
control_plane_name: default | ||
rbac_roles: | ||
- comment: Full access to Dev Portal related endpoints in the workspace | ||
endpoint_permissions: | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /developers | ||
negative: false | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /developers/* | ||
negative: false | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /files | ||
negative: false | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /files/* | ||
negative: false | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /kong | ||
negative: false | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /rbac/* | ||
negative: true | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /rbac/*/* | ||
negative: true | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /rbac/*/*/* | ||
negative: true | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /rbac/*/*/*/* | ||
negative: true | ||
workspace: default | ||
- actions: | ||
- read | ||
- delete | ||
- create | ||
- update | ||
endpoint: /rbac/*/*/*/*/* | ||
negative: true | ||
workspace: default | ||
- actions: | ||
- read | ||
- update | ||
endpoint: /workspaces/default | ||
negative: false | ||
workspace: default | ||
name: workspace-portal-admin |
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,95 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
ONLINE = true | ||
OFFLINE = false | ||
) | ||
|
||
func Test_Validate_Konnect(t *testing.T) { | ||
setup(t) | ||
runWhen(t, "konnect", "") | ||
|
||
tests := []struct { | ||
name string | ||
stateFile string | ||
additionalArgs []string | ||
errorExpected bool | ||
errorString string | ||
}{ | ||
{ | ||
name: "validate with konnect", | ||
stateFile: "testdata/validate/konnect.yaml", | ||
additionalArgs: []string{}, | ||
errorExpected: false, | ||
}, | ||
{ | ||
name: "validate with --konnect-compatibility", | ||
stateFile: "testdata/validate/konnect.yaml", | ||
additionalArgs: []string{"--konnect-compatibility"}, | ||
errorExpected: false, | ||
}, | ||
{ | ||
name: "validate with 1.1 version file", | ||
stateFile: "testdata/validate/konnect_1_1.yaml", | ||
additionalArgs: []string{}, | ||
errorExpected: true, | ||
errorString: "[version] decK file version must be '3.0' or greater", | ||
}, | ||
{ | ||
name: "validate with no version in deck file", | ||
stateFile: "testdata/validate/konnect_no_version.yaml", | ||
additionalArgs: []string{}, | ||
errorExpected: true, | ||
errorString: "[version] unable to determine decK file version", | ||
}, | ||
{ | ||
name: "validate with --rbac-resources-only", | ||
stateFile: "testdata/validate/rbac-resources.yaml", | ||
additionalArgs: []string{"--rbac-resources-only"}, | ||
errorExpected: true, | ||
errorString: "[rbac] not yet supported by konnect", | ||
}, | ||
{ | ||
name: "validate with workspace set", | ||
stateFile: "testdata/validate/konnect.yaml", | ||
additionalArgs: []string{"--workspace=default"}, | ||
errorExpected: true, | ||
errorString: "[workspaces] not supported by Konnect - use control planes instead", | ||
}, | ||
{ | ||
name: "validate with no konnect config in file", | ||
stateFile: "testdata/validate/konnect_invalid.yaml", | ||
additionalArgs: []string{}, | ||
errorExpected: true, | ||
errorString: "[konnect] section not specified - ensure details are set via cli flags", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
validateOpts := append([]string{ | ||
tc.stateFile, | ||
}, tc.additionalArgs...) | ||
|
||
err := validate(ONLINE, validateOpts...) | ||
|
||
if tc.errorExpected { | ||
assert.Error(t, err) | ||
if tc.errorString != "" { | ||
assert.Contains(t, err.Error(), tc.errorString) | ||
} | ||
return | ||
} | ||
|
||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |