Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
[TT-6703] Added integration tests using Venom framework (#520)
Browse files Browse the repository at this point in the history
* Add test suit for json valiation

* Rewrite test

* Add readme

* Add executor for applying manifests

* Fix indentation

* commiting

* commiting

* Fix header transform tests

* reverting-original-changes-in-crds.yaml-file

* Fix circuit breaker tests

* Fix blacklist tests

* Fix request transform test

* Remove tests for cache plugins

* Add samples in venom-tests folder

* Remove readme file

* Update make file

* Remove venom tests from test-all target for now

* Try to run venom tests in GithubActions

* Fix check

* Do not run tests on PR

* Update changelog

* Delete duplicate tests

* Delete duplicate sample

* Remove comments from sample file

Co-authored-by: Pranshu Singh <pranshusingh@Pranshus-MacBook-Pro.local>
  • Loading branch information
komalsukhani and Pranshu Singh authored Nov 30, 2022
1 parent 4e839b0 commit c4b8507
Show file tree
Hide file tree
Showing 19 changed files with 586 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added support of API Ownership [#483](https://github.com/TykTechnologies/tyk-operator/pull/483)
- Added PoC tool that helps migration of existing ApiDefinition & SecurityPolicies
from Dashboard to Kubernetes environment. [#481](https://github.com/TykTechnologies/tyk-operator/pull/481)
- Added integration tests using venom framework

**Fixed**
- Fixed user email format used in integration tests since e2e tests were failing after Tyk v4.0.6 was released [#510](https://github.com/TykTechnologies/tyk-operator/pull/510)
Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ create-kind-cluster: ## Create kind cluster
clean: ## Delete kind cluster
kind delete cluster --name=${CLUSTER_NAME}

help:
@fgrep -h "##" Makefile | fgrep -v fgrep |sed -e 's/\\$$//' |sed -e 's/:/-:/'| sed -e 's/:.*##//'
.PHONY: install-venom
install-venom:
ifeq (, $(venom version))
@echo "Installing venom"
sudo curl https://github.com/ovh/venom/releases/download/v1.0.1/venom.linux-amd64 -L -o /usr/local/bin/venom && sudo chmod +x /usr/local/bin/venom
else
@echo "Venom is already installed"
endif

.PHONY: run-venom-tests
run-venom-tests: install-venom ## Run Venom integration tests
cd venom-tests && IS_TTY=true venom run

help:
@fgrep -h "##" Makefile | fgrep -v fgrep |sed -e 's/\\$$//' |sed -e 's/:/-:/'| sed -e 's/:.*##//'
58 changes: 58 additions & 0 deletions venom-tests/QA-949-api-Circuit-Breaker-Enforced-Timeouts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Test Availability Circuit Breaker and Enforced Timeouts
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_timeout.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with Enforced Timeouts Plugin
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/delay/3
assertions:
- result.statuscode ShouldEqual 504
- result.bodyjson.error ShouldContainSubstring Upstream service reached hard timeout

- name: Test with Circuit Breaker Plugin
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/status/500
assertions:
- result.statuscode ShouldEqual 500

- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/status/500
assertions:
- result.statuscode ShouldEqual 500

- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/status/500
assertions:
- result.statuscode ShouldEqual 500

- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/status/500
assertions:
- result.statuscode ShouldEqual 500

- type: http
method: GET
url: http://localhost:8080/httpbin-timeout-breaker/status/500
assertions:
- result.statuscode ShouldEqual 503
- result.bodyjson.error ShouldContainSubstring Service temporarily unavailable

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_timeout.yaml
assertions:
- result.code ShouldEqual 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test Header injection for response and resquest
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_global-headers.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with Request and Response Headers add and remove
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin-global-headers/get
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.headers ShouldNotBeEmpty
- result.bodyjson.headers.foo-req ShouldEqual my-foo
- result.bodyjson.headers.bar-req ShouldEqual my-bar
- result.headers.foo ShouldEqual Bar
- result.headers.Server ShouldBeEmpty

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_global-headers.yaml
assertions:
- result.code ShouldEqual 0
23 changes: 23 additions & 0 deletions venom-tests/QA-953-api-security-allowlist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Whitelist Endpoint Designer
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_whitelist.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with Security Allowlist
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin/get
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_whitelist.yaml
assertions:
- result.code ShouldEqual 0
32 changes: 32 additions & 0 deletions venom-tests/QA-954-api-security-blocklist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test Blacklist Endpoint Designer
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_blacklist.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with Security Blocklist
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin/get
assertions:
- result.statuscode ShouldEqual 403
- result.bodyjson.error ShouldContainSubstring Requested endpoint is forbidden

- name: Test request to non-block paths is successful
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin/anything
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_blacklist.yaml
assertions:
- result.code ShouldEqual 0
23 changes: 23 additions & 0 deletions venom-tests/QA-955-api-security-ignorelist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Ignore Endpoint Designer
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_ignored.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with Security Ignorelist
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin/get
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_ignored.yaml
assertions:
- result.code ShouldEqual 0
23 changes: 23 additions & 0 deletions venom-tests/QA-956-api-transform-method.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Method Transform Plugin
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_method_transform.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test Tyk can change method of a request using Method Transform Plugin
steps:
- type: http
method: POST
url: http://localhost:8080/transform/anything
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../bdd/custom_resources/transform/method.yaml
assertions:
- result.code ShouldEqual 0
35 changes: 35 additions & 0 deletions venom-tests/QA-958-api-transform-request-response-body.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Body Transform Plugin
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_transform.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test Tyk can change Body of a request using Body Transform Plugin
steps:
- type: http
method: POST
url: http://localhost:8080/httpbin-transform/anything
body: '{
"foo": "test"
}'
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.json.bar ShouldEqual test

- name: Test Tyk can change Body of a response using Body Transform Plugin
steps:
- type: http
method: GET
url: http://localhost:8080/httpbin-transform/xml
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_transform.yaml
assertions:
- result.code ShouldEqual 0
38 changes: 38 additions & 0 deletions venom-tests/QA-960-api-json-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test Json Validation Plugin
testcases:
- name: Create API
steps:
- type: applyManifests
filename: "samples/httpbin_json_schema_validation.yaml"
assertions:
- result.code ShouldEqual 0

- name: Test with invalid request
steps:
- type: http
url: http://localhost:8080/httpbin/get
body: '{
"userName": "b",
"age": 0
}'
assertions:
- result.statuscode ShouldEqual 422

- name: Test with valid request
steps:
- type: http
url: http://localhost:8080/httpbin/get
body: '{
"userName": "burak",
"age": 2
}'
assertions:
- result.statuscode ShouldEqual 200

- name: Delete API
steps:
- type: exec
script: kubectl delete -f ../config/samples/httpbin_json_schema_validation.yaml
assertions:
- result.code ShouldEqual 0

12 changes: 12 additions & 0 deletions venom-tests/lib/applyManifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
executor: applyManifests
input:
filename: {}
steps:
- type: exec
script: |
kubectl apply -f '{{.input.filename}}'
sleep 20
assertions:
- result.code ShouldEqual 0
output:
code: '{{.result.code}}'
34 changes: 34 additions & 0 deletions venom-tests/samples/httpbin_blacklist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: httpbin-blacklist
spec:
name: httpbin-blacklist
use_keyless: true
protocol: http
active: true
proxy:
target_url: http://httpbin.org/
listen_path: /httpbin
strip_listen_path: true
version_data:
default_version: Default
not_versioned: true
versions:
Default:
name: Default
use_extended_paths: true
paths:
black_list: []
ignored: []
white_list: []
extended_paths:
black_list:
- ignore_case: true
method_actions:
GET:
action: "no_action"
code: 200
data: ""
headers: {}
path: "/get"
36 changes: 36 additions & 0 deletions venom-tests/samples/httpbin_global-headers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
name: httpbin-global-headers
spec:
name: httpbin-global-headers
use_keyless: true
protocol: http
active: true
org_id: acme.com
proxy:
target_url: http://httpbin.org
listen_path: /httpbin-global-headers
strip_listen_path: true
response_processors:
- name: header_injector
version_data:
default_version: Default
not_versioned: true
versions:
Default:
name: Default
use_extended_paths: true
paths:
black_list: []
ignored: []
white_list: []
global_headers:
foo-req: my-foo
bar-req: my-bar
global_headers_remove:
- hello
global_response_headers:
Foo: Bar
global_response_headers_remove:
- Server
Loading

0 comments on commit c4b8507

Please sign in to comment.