Skip to content

Commit

Permalink
Merge pull request #2473 from CrowleyRajapakse/ai
Browse files Browse the repository at this point in the history
Adding cucumber test for backend api key
  • Loading branch information
CrowleyRajapakse authored Sep 19, 2024
2 parents 89b4cb9 + 5fd1146 commit 8bdf476
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/cucumber-tests/CRs/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,13 @@ spec:
protocol: TCP
selector:
app: graphql-faker
---
apiVersion: v1
kind: Secret
metadata:
name: mysecret
namespace: apk-integration-test
type: Opaque
data:
apiKey: c2FtcGF0aA==
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: "BackendAPIKeySecurity"
basePath: "/backend-api-key-security"
version: "3.14"
id: "backend-api-key-test"
type: "REST"
defaultVersion: true
endpointConfigurations:
production:
endpoint: "http://backend:80/anything"
endpointSecurity:
enabled: true
securityType:
secretName: "mysecret"
in: "Header"
apiKeyNameKey: "api-key"
apiKeyValueKey: "apiKey"
operations:
- target: "/employee"
verb: "GET"
secured: true
scopes: []
- target: "/get"
verb: "GET"
secured: true
scopes: []
- target: "/post"
verb: "POST"
secured: true
scopes: []
- target: "/employee"
verb: "POST"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "PUT"
secured: true
scopes: []
- target: "/employee/{employeeId}"
verb: "DELETE"
secured: true
scopes: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{
"openapi": "3.0.1",
"info": {
"title": "EmployeeServiceAPI",
"version": "3.14"
},
"servers": [
{
"url": "http://backend:80/anything",
"description": "Server URL",
"variables": {}
}
],
"paths": {
"/employee": {
"get": {
"tags": [
"employee-controller"
],
"operationId": "getEmployees",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
}
},

"post": {
"tags": [
"employee-controller"
],
"operationId": "addEmployee",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Employee"
}
}
}
},
"responses": {
"200": {
"description": "default response",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
}
},
"/get": {
"get": {
"tags": [
"employee-controller"
],
"operationId": "getEmployees",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
}
}
},
"/post": {
"post": {
"tags": [
"employee-controller"
],
"operationId": "getEmployees",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
}
}
},
"/employee/{employeeId}": {
"put": {
"tags": [
"employee-controller"
],
"operationId": "editEmployee",
"parameters": [
{
"name": "employeeId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
},
"delete": {
"tags": [
"employee-controller"
],
"operationId": "deleteEmployee",
"parameters": [
{
"name": "employeeId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Employee"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Employee": {
"type": "object",
"properties": {
"empId": {
"type": "string"
},
"name": {
"type": "string"
},
"designation": {
"type": "string"
},
"salary": {
"type": "number",
"format": "double"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Backend API Key auth
Scenario: Testing API level Endpoint backend api key auth header
Given The system is ready
And I have a valid subscription
When I use the APK Conf file "artifacts/apk-confs/backend_apikey_auth_conf.yaml"
And the definition file "artifacts/definitions/backend_apikey_auth_api.json"
And make the API deployment request
Then the response status code should be 200
Then I set headers
|Authorization|bearer ${accessToken}|
And I send "GET" request to "https://default.gw.wso2.com:9095/backend-api-key-security/3.14/employee/" with body ""
And I eventually receive 200 response code, not accepting
|429|
And the response body should contain "\"Api-Key\": \"sampath\""


Scenario Outline: Undeploy API
Given The system is ready
And I have a valid subscription
When I undeploy the API whose ID is "<apiID>"
Then the response status code should be <expectedStatusCode>

Examples:
| apiID | expectedStatusCode |
| backend-api-key-test | 202 |

Scenario: Testing undeployed API
Given The system is ready
And I have a valid subscription
Then I set headers
| Authorization | bearer ${accessToken} |
And I send "GET" request to "https://default.gw.wso2.com:9095/backend-api-key-security/3.14/employee/" with body ""
And I eventually receive 404 response code, not accepting
| 200 |

0 comments on commit 8bdf476

Please sign in to comment.