Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

hasura-tests

БесплатноБез исполняемых скриптовНе проверен

Use when a Hasura GraphQL Engine needs tests, especially role-based row permissions: a docker-compose test instance, metadata API setup, x-hasura-role and…

testlandот testland★ 18 звёзд на GitHub

Об этом скилле

hasura-tests

Overview

Per hasura.io/docs/2.0/auth/authorization/quickstart/, Hasura permissions are configured per table, role, and operation (select / insert / update / delete), with row- filter expressions and column-level scopes.

The testable concerns are different from Apollo / Yoga:

  • Permission rules are declarative; tests verify the rule produces the expected filter SQL.
  • Roles + session variables drive everything; tests inject x-hasura-role + custom claims and assert the response shape.
  • Metadata is the source of truth; tests apply a fixture metadata then run queries.

When to use

  • Testing a Hasura-backed API where row-level isolation is the primary concern (composes with cross-tenant-data-leak-tests in the qa-multi-tenancy plugin).
  • Verifying a new role's permission rules.
  • PR review of hasura/metadata/ changes.
  • Regression-testing role transitions (user becomes admin, etc.).

How to use

  1. Bring up the ephemeral test stack (docker compose -f docker-compose.test.yml up -d) with introspection disabled and the console off.
  2. Apply the fixture metadata that declares the permission rules under test, via the /v1/metadata API or hasura metadata apply.
  3. Seed per-test rows so no test depends on another test's data.
  4. Send queries to /v1/graphql with the admin secret plus an x-hasura-role override (and x-hasura-user-id / custom claims) to act as any role.
  5. Assert the response shape: rows are row-filtered to the role, or the failure carries extensions.code = "permission-error" (or affected_rows: 0).
  6. Cover the full role x table x operation matrix from a checked-in fixture, and add one smoke test through the real JWT path.
  7. Tear the stack down with -v and reset metadata between suites.

Authoring

Test instance setup

# docker-compose.test.yml
services:
  postgres:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: ${PG_PASSWORD:?set PG_PASSWORD}

  hasura:
    image: hasura/graphql-engine:v2.42.0
    ports: ["8080:8080"]
    depends_on: [postgres]
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${PG_PASSWORD}@postgres:5432/postgres
      HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET:?set HASURA_GRAPHQL_ADMIN_SECRET}
      HASURA_GRAPHQL_DISABLE_INTROSPECTION_PUBLIC_API: "true"  # per graphql-complexity-limit-tester references/introspection.md
      HASURA_GRAPHQL_ENABLE_CONSOLE: "false"
docker compose -f docker-compose.test.yml up -d

Never write the admin secret or DB password into the compose file or a test. Per Compose interpolation, ${VAR} is read from the shell or a git-ignored .env, and ${VAR:?error} stops Compose when it is unset. Every command and test below reads HASURA_GRAPHQL_ADMIN_SECRET from the environment.

Apply metadata for test

Per Hasura docs, the metadata API at /v1/metadata:

curl -X POST http://localhost:8080/v1/metadata \
  -H "x-hasura-admin-secret: $HASURA_GRAPHQL_ADMIN_SECRET" \
  -H "Content-Type: application/json" \
  -d @hasura/metadata-fixture.json

metadata-fixture.json contains the declarative permission rules being tested.

Or via hasura CLI:

hasura migrate apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"
hasura metadata apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"

Role-based permission tests

Tests act as any role via admin secret + x-hasura-role override, and a full per-role x per-table x per-operation audit is generated from a checked-in fixture. Both patterns - the httpx by-role queries and the parametrized matrix - are in references/permission-matrix-tests.md.

Worked example

Scenario: a new user role must see only its own rows in the user table.

  1. In the fixture metadata, give user a select permission on user filtered by id = X-Hasura-User-Id; apply it with hasura metadata apply.
  2. POST { user { id name } } to /v1/graphql with headers x-hasura-admin-secret, x-hasura-role: user, x-hasura-user-id: 3.
  3. Assert status_code == 200 and every returned row has id == 3 - the row filter held.
  4. POST the same query with x-hasura-role: admin (no user-id) and assert len(rows) > 1 - admin is not restricted.

Result: one pair of requests proves the row-filter rule for the restricted role and confirms it does not leak into the admin role.

Running

docker compose -f docker-compose.test.yml up -d
hasura metadata apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"
pytest tests/hasura/
docker compose -f docker-compose.test.yml down -v

Parsing results

H

Полный SKILL.md на GitHub

Установить hasura-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

.tessl-plugin/plugin.jsonreferences/permission-matrix-tests.md

FAQ

Что делает скилл hasura-tests?

Use when a Hasura GraphQL Engine needs tests, especially role-based row permissions: a docker-compose test instance, metadata API setup, x-hasura-role and x-hasura-user-id headers, and a role by table by operation permission matrix against the v1/graphql endpoint.

Как установить скилл hasura-tests?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hasura-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить hasura-tests с