Skip to content

Commit

Permalink
test: add e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Sestito <[email protected]>
  • Loading branch information
fabriziosestito committed Oct 26, 2023
1 parent ca5e6dd commit dbd7d28
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
115 changes: 115 additions & 0 deletions e2e-tests/07-raw-policies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Raw policies execution

testcases:
- name: fixtures
steps:
- type: readfile
path: ./test_data/raw_validation.json
assertions:
- result.err ShouldBeEmpty
vars:
raw_validation:
from: result.content
- type: readfile
path: ./test_data/raw_mutation.json
assertions:
- result.err ShouldBeEmpty
vars:
raw_mutation:
from: result.content

- name: Raw waPC validation policy works as expected
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-validation
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_validation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldNotContainKey patch
- result.bodyjson.response ShouldNotContainKey patchType

- name: Raw waPC mutation policy accepts without mutating
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-mutation
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_validation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldNotContainKey patch
- result.bodyjson.response ShouldNotContainKey patchType

- name: Raw waPC mutation policy mutates the request
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-mutation
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_mutation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldContainKey patch
- result.bodyjson.response ShouldContainKey patchType

- name: Raw OPA validation policy works as expected
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-validation-opa
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_validation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldNotContainKey patch
- result.bodyjson.response ShouldNotContainKey patchType

- name: Raw WASI validation policy works as expected
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-validation-wasi
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_validation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldNotContainKey patch
- result.bodyjson.response ShouldNotContainKey patchType

- name: Raw WASI mutation policy mutates the request
steps:
- name: Accept
type: http
method: POST
url: http://localhost:3000/validate_raw/raw-mutation-wasi
headers:
Content-Type: application/json
body: "{{ .fixtures.raw_mutation }}"
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.response.allowed ShouldEqual true
- result.bodyjson.response.status.code ShouldNotEqual 500
- result.bodyjson.response ShouldContainKey patch
- result.bodyjson.response ShouldContainKey patchType
43 changes: 43 additions & 0 deletions e2e-tests/test_data/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,46 @@ flux:
settings:
requiredAnnotations:
"fluxcd.io/cat": "felix"

raw-validation:
url: ghcr.io/kubewarden/tests/raw-validation-policy:v0.1.0
settings:
validUsers:
- "tonio"
- "wanda"
validActions:
- "eats"
- "likes"
validResources:
- "banana"
- "hay"

raw-mutation:
url: ghcr.io/kubewarden/tests/raw-mutation-policy:v0.1.0
allowedToMutate: true
settings: {}

raw-validation-opa:
url: ghcr.io/kubewarden/tests/raw-validation-opa-policy:v0.1.0
settings: {}

raw-validation-wasi:
url: ghcr.io/kubewarden/tests/raw-validation-wasi-policy:v0.1.0
settings:
validUsers:
- "tonio"
- "wanda"
validActions:
- "eats"
- "likes"
validResources:
- "banana"
- "hay"

raw-mutation-wasi:
url: ghcr.io/kubewarden/tests/raw-mutation-wasi-policy:v0.1.0
allowedToMutate: true
settings:
forbiddenResources:
- "banana"
- "carrot"
3 changes: 3 additions & 0 deletions e2e-tests/test_data/raw_mutation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"request": { "user": "tonio", "action": "eats", "resource": "banana" }
}
3 changes: 3 additions & 0 deletions e2e-tests/test_data/raw_validation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"request": { "user": "tonio", "action": "eats", "resource": "hay" }
}

0 comments on commit dbd7d28

Please sign in to comment.