prowler-test-api
БесплатноЗапускает вложенные скриптыНе проверенTesting patterns for Prowler API: JSON:API, Celery tasks, RLS isolation, RBAC. Trigger: When writing tests for api/ (JSON:API requests/assertions…
от prowler-cloud★ 15 363 звезды на GitHubОб этом скилле
Critical Rules
- ALWAYS use
response.json()["data"]notresponse.data - ALWAYS send JSON:API bodies (
{"data": {...}}) withcontent_type=API_JSON_CONTENT_TYPE(fromconftest) for POST/PATCH/PUT authenticated_clientis Django's testClient, NOT DRF'sAPIClient:format=is silently ignored and the body is sent multipart. Existing tests that passformat="json"only work because they post flat dicts- ALWAYS mark DB tests with
@pytest.mark.django_db - ALWAYS test cross-tenant isolation - RLS returns 404, NOT 403
- NEVER skip RLS isolation tests when adding new endpoints
- NEVER use realistic-looking API keys in tests (TruffleHog will flag them)
- ALWAYS mock BOTH
.delay()ANDTask.objects.getfor views that return 202 with a task - ALWAYS patch the job function where
tasks.tasksimports it (e.g.tasks.tasks.check_provider_connection) when callingtask.apply(); never reach real cloud APIs - Valid provider UIDs only:
Provider.save()runsfull_clean()and thevalidate_<provider>_uid()checks
1. Fixture Dependency Chain
create_test_user (session) ─► tenants_fixture (function) ─► authenticated_client
│
└─► aws_provider ─► scans_fixture ─► findings_fixture
Key Fixtures
| Fixture | Description |
|---|---|
create_test_user |
Session user ([email protected]) |
tenants_fixture |
3 tenants: [0],[1] have membership ([1] as OWNER), [2] isolated |
authenticated_client |
Django test client with JWT for tenant[0] |
authenticated_client_for_tenant_factory |
Creates a Django test client with JWT for a specific user and tenant |
provider_factory |
Creates one validated provider with provider-specific defaults |
aws_provider |
1 AWS provider in tenant[0] |
aws_provider_pair |
2 AWS providers in tenant[0] |
all_provider_types_fixture |
1 provider for every supported provider type |
tasks_fixture |
2 Task rows in tenant[0] backed by TaskResult |
authenticated_api_client |
DRF APIClient with a serializer-issued JWT (use only for token tests) |
RBAC Fixtures
| Fixture | Permissions |
|---|---|
authenticated_client_rbac |
All permissions (admin) |
authenticated_client_rbac_noroles |
Membership but NO roles |
authenticated_client_no_permissions_rbac |
All permissions = False |
Use authenticated_client for normal view behavior tests. It uses a cheap JWT
and still runs the real request authentication path. Use serializer-generated
JWTs or API-key clients only when the test is specifically about token
obtain/refresh, invalid tokens, expired tokens, tenant switching by token, API
keys, or unauthenticated 401 behavior. Use
authenticated_client_for_tenant_factory when a test needs a cheap JWT client
for a different user or tenant.
2. JSON:API Requests
from conftest import API_JSON_CONTENT_TYPE # "application/vnd.api+json"
POST (Create)
response = authenticated_client.post(
reverse("scan-list"),
data={"data": {"type": "scans", "attributes": {...}, "relationships": {...}}},
content_type=API_JSON_CONTENT_TYPE,
)
PATCH (Update)
response = authenticated_client.patch(
reverse("provider-detail", kwargs={"pk": provider.id}),
data={"data": {"type": "providers", "id": str(provider.id), "attributes": {...}}},
content_type=API_JSON_CONTENT_TYPE,
)
Reading Responses
data = response.json()["data"]
attrs = data["attributes"]
errors = response.json()["errors"] # For 400 responses
3. RLS Isolation (Cross-Tenant)
RLS returns 404, NOT 403 - the resource is invisible, not forbidden.
def test_cross_tenant_access_denied(self, authenticated_client, tenants_fixture):
other_tenant = tenants_fixture[2] # Isolated tenant
foreign_provider = Provider.objects.create(tenant_id=other_tenant.id, ...)
response = authenticated_client.get(reverse("provider-detail", args=[foreign_provider.id]))
assert response.status_code == status.HTTP_404_NOT_FOUND # NOT 403!
4. Celery Task Testing
Testing Strategies
| Strategy | Use For |
|---|---|
Mock .delay() + Task.objects.get |
Testing views that trigger tasks |
Mock api.v1.views.enqueue_scan_execution_on_commit |
Testing scan creation (POST /scans) |
task.apply() |
Synchronous task logic testing |
Mock chain/group |
Testing Canvas orchestration |
Mock connection |
Testing @set_tenant decorator |
Mock apply_async |
Testing Beat scheduled tasks |
Why NOT task_always_eager
| Problem | Impact |
|---|---|
| No task serialization | Misses argument type errors |
| No broker interaction | Hides connection issues |
| Different execution context | self.request behaves differently |
Instead, use: task.apply() for sync execution, mocking for isolation.
**Full exampl
Установить prowler-test-api в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadEditWriteGlobGrepBashWebFetchWebSearchTaskВложенные файлы
FAQ
Что делает скилл prowler-test-api?
Testing patterns for Prowler API: JSON:API, Celery tasks, RLS isolation, RBAC. Trigger: When writing tests for api/ (JSON:API requests/assertions, cross-tenant isolation, RBAC, Celery tasks, viewsets/serializers).
Как установить скилл prowler-test-api?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл prowler-test-api запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic