diff --git a/backend/src/Squidex/Program.cs b/backend/src/Squidex/Program.cs index ebb6922a1..99886b670 100644 --- a/backend/src/Squidex/Program.cs +++ b/backend/src/Squidex/Program.cs @@ -71,6 +71,11 @@ namespace Squidex IPAddress.Any, 5001, listenOptions => listenOptions.UseHttps("../../../dev/squidex-dev.pfx", "password")); + + serverOptions.Listen( + IPAddress.IPv6Any, + 5001, + listenOptions => listenOptions.UseHttps("../../../dev/squidex-dev.pfx", "password")); } }); diff --git a/backend/tools/k6/docker-compose.yml b/backend/tools/k6/docker-compose.yml new file mode 100644 index 000000000..3e7d28660 --- /dev/null +++ b/backend/tools/k6/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.4' + +networks: + grafana: + +services: + influxdb: + image: influxdb:latest + networks: + - grafana + ports: + - "8086:8086" + environment: + - INFLUXDB_DB=k6 + + grafana: + image: grafana/grafana:latest + networks: + - grafana + ports: + - "4000:3000" + environment: + - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin + - GF_AUTH_ANONYMOUS_ENABLED=true + - GF_AUTH_BASIC_ENABLED=false diff --git a/backend/tools/k6/get-clients.js b/backend/tools/k6/get-clients.js new file mode 100644 index 000000000..ad67f6e2a --- /dev/null +++ b/backend/tools/k6/get-clients.js @@ -0,0 +1,35 @@ +import { check } from 'k6'; +import http from 'k6/http'; +import { variables, getBearerToken } from './shared.js'; + +export let options = { + stages: [ + { duration: "2m", target: 200 }, + { duration: "2m", target: 200 }, + { duration: "2m", target: 0 }, + ], + thresholds: { + 'http_req_duration': ['p(99)<1500'], // 99% of requests must complete below 1.5s + } +}; + + +export function setup() { + const token = getBearerToken(); + + return { token }; +} + +export default function (data) { + const url = `${variables.serverUrl}/api/apps/${variables.appName}/clients`; + + const response = http.get(url, { + headers: { + Authorization: `Bearer ${data.token}` + } + }); + + check(response, { + 'is status 200': (r) => r.status === 200, + }); +} \ No newline at end of file diff --git a/backend/tools/k6/shared.js b/backend/tools/k6/shared.js new file mode 100644 index 000000000..a8aef7935 --- /dev/null +++ b/backend/tools/k6/shared.js @@ -0,0 +1,35 @@ +import http from 'k6/http'; + +export const variables = { + appName: getValue('APP__NAME', 'integration-tests'), + clientId: getValue('CLIENT__ID', 'root'), + clientSecret: getValue('CLIENT__SECRET', 'xeLd6jFxqbXJrfmNLlO2j1apagGGGSyZJhFnIuHp4I0='), + serverUrl: getValue('SERVER__URL', 'https://localhost:5001') +}; + +let bearerToken = null; + +export function getBearerToken() { + if (!bearerToken) { + const url = `${variables.serverUrl}/identity-server/connect/token`; + + const response = http.post(url, { + grant_type: 'client_credentials', + client_id: variables.clientId, + client_secret: variables.clientSecret, + scope: 'squidex-api' + }); + + const json = JSON.parse(response.body); + + bearerToken = json.access_token; + } + + return bearerToken; +} + +function getValue(key, fallback) { + const result = __ENV[key] || fallback; + + return result; +} \ No newline at end of file