Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/actions/tests/api-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
description: 'Markers to filter tests'
required: false
default: ${{ matrix.envfiles.apimarkers }}
db:
description: 'Database of the test environment, e.g. postgres15 or mongo7'
required: false
default: ${{ matrix.envfiles.db }}
runs:
using: "composite"
steps:
Expand All @@ -24,6 +28,7 @@
env:
USER_API_SECRET: ${{ inputs.user_api_secret }}
API_MARKERS: ${{ inputs.api_markers }}
DB: ${{ inputs.db }}
run: |
pip install --no-deps -r requirements.txt
cat >pytest.env <<-EOF
Expand All @@ -44,4 +49,9 @@
TYK_TEST_KEYCLOAK_URL=http://localhost:8180
TYK_TEST_KEYCLOAK_INTERNAL_URL=http://keycloak:8080
EOF
# MCP analytics tests read raw records from Postgres when given a DSN, otherwise from Mongo.

Check warning on line 52 in .github/actions/tests/api-tests/action.yaml

View check run for this annotation

probelabs / Visor: security

security Issue

A hardcoded PostgreSQL connection string (DSN) is present in the action. This string includes the username, host, port, database name, and sets `sslmode=disable`, forcing an unencrypted connection. While intended for a local test environment, hardcoding connection details is inflexible and establishes a poor security precedent. If the test database configuration changes (e.g., requires a password or SSL), this action will fail or connect insecurely.
Raw output
Avoid hardcoding the DSN. Instead, pass the full connection string as a dedicated input to the action. This allows the calling workflow to control the connection parameters, sourcing them from environment variables or secrets as needed, which is more secure and flexible.

Example implementation:

In `action.yaml`:
```yaml
inputs:
  # ...
  mcp-postgres-dsn:
    description: 'Postgres DSN for MCP analytics tests.'
    required: false

# ... inside the run step:
if [[ "${{ inputs.db }}" == postgres* && -n "${{ inputs.mcp-postgres-dsn }}" ]]; then
  echo "TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.mcp-postgres-dsn }}" >> pytest.env
fi
```
The calling workflow would then be responsible for providing the correct DSN.

Check warning on line 52 in .github/actions/tests/api-tests/action.yaml

View check run for this annotation

probelabs / Visor: quality

architecture Issue

The PostgreSQL connection string (DSN) is hardcoded. This couples the action to a specific test environment configuration (user `postgres`, host `localhost`, etc.). This reduces maintainability and reusability, as any changes to the test database setup will require modifying this action.
Raw output
To improve flexibility, make the DSN configurable by adding a new action input (e.g., `mcp-postgres-dsn`) with the current value as a default. This allows different environments to override the DSN without changing the action's code. Then, use the input in the script: `echo "TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.mcp-postgres-dsn }}" >> pytest.env`.
# URL form: the line below splits pytest.env on whitespace.

Check warning on line 53 in .github/actions/tests/api-tests/action.yaml

View check run for this annotation

probelabs / Visor: architecture

architecture Issue

The PostgreSQL DSN is hard-coded within the action's script. This couples the action to a specific test environment configuration (e.g., hostname, port, credentials) and makes it difficult to reuse the action in environments with different configurations. For a reusable action intended for production use, configuration should be exposed as inputs rather than being hidden in the implementation.
Raw output
To improve configurability and transparency, extract the DSN into a new action input, using the current hard-coded value as its default. This makes the configuration explicit, self-documenting, and allows for overrides when necessary.

1. Add a new input to the `inputs` section:
```yaml
  postgres_mcp_dsn:
    description: 'DSN for MCP analytics tests on Postgres. Used when `db` starts with `postgres`.'
    required: false
    default: 'postgresql://postgres@localhost:5432/tyk_analytics?sslmode=disable'
```

2. Use this new input in the run step:
```bash
          if [[ "$DB" == postgres* ]]; then
            echo "TYK_TEST_MCP_POSTGRES_DSN=${{ inputs.postgres_mcp_dsn }}" >> pytest.env
          fi
```
if [[ "$DB" == postgres* ]]; then
echo "TYK_TEST_MCP_POSTGRES_DSN=postgresql://postgres@localhost:5432/tyk_analytics?sslmode=disable" >> pytest.env
fi
env $(cat pytest.env | xargs) pytest -c pytest_ci.ini --ci --junitxml=${XUNIT_REPORT_PATH} -m "${{ inputs.api_markers }}"

Check failure on line 57 in .github/actions/tests/api-tests/action.yaml

View workflow job for this annotation

GitHub Actions / zizmor / scan

template-injection

action.yaml:57: code injection via template expansion: may expand into attacker-controllable code
Loading