> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/platform/platform-services/partner-management/testing.md).

# Testing

Partner Management automated tests, a manual smoke test without Keycloak, and the UI build check.

## Automated tests

The API ships a pytest suite (`core/api/tests`) that runs against SQLite (no Postgres required) and is executed by the `test` GitHub workflow.

```bash
pip install -e core/api pytest aiosqlite greenlet
# plus the three openg2p-fastapi-common packages (see the workflow / Dockerfile)
pytest -q core/api/tests
```

Coverage:

* **Key service** — algorithm inference (RS256/ES256/EdDSA), kid defaulting to the fingerprint, and rejection of private keys, weak RSA, algorithm mismatch, and malformed input; JWKS rendering.
* **Lifecycle** — onboarding → `created` (keys not served) → approve → `active` (keys served); fetch by `kid`; JWKS; duplicate-onboarding rejection.
* **Rotation** — add a new key + revoke an old one; the revoked key is retained but no longer served.
* **Disable/enable** — disabled partners fail-closed on both fetch and JWKS.
* **Reject** — rejected onboarding is never served, and a decided request cannot be approved.
* **Policies** — onboarding with policies activates version 1 on approval (rejection marks them `rejected`); fetch by data controller, by use case and unfiltered; fail-closed `404` for unknown, non-active or policy-less partners; listing by use case; policy requests create new versions that supersede the old, can be rejected or revoke policies; one pending change per policy key (`PM-POLICY-409`); policy requests only for approved partners; audit events; field validation (scopes vs use cases, `name@major`, algorithms, fetch type, ISO-8601 durations) and one policy per key per request.
* **Validation** — `GET /metadata` lists the allowed values; unsupported or wrong-case algorithms, malformed `partner_id` / `kid`, non-http(s) `jwks_url`, unknown or already-revoked `revoke_kids`, and unknown status / request-type filters are rejected; `""` still means auto-detect; stored rows with values outside today's sets still load.

## Manual smoke test (no Keycloak)

Run the API with auth disabled to exercise the flow locally:

```bash
cd core/api
cp .env.example .env
# set: COMMON_AUTH_ENABLED=false
#      PARTNER_MANAGER_DB_DATASOURCE=sqlite+aiosqlite:///./pm.db
python -m openg2p_partner_management_api.main migrate
python -m openg2p_partner_management_api.main run
```

Then, against `http://localhost:8000`:

1. `POST /partners/requests/onboarding` with a PEM public key.
2. `GET /keys/<partner_id>` → `404` (not yet approved).
3. `POST /partners/requests/<id>/approve`.
4. `GET /keys/<partner_id>` → `200` with the key; `GET /keys/<partner_id>/jwks.json`.
5. `POST /partners/requests/policy` with a policy, approve it, then `GET /policies/<partner_id>` → `200` with the policy.
6. `POST /partners/<partner_id>/disable` → key and policy fetch return `404` again.

## UI

```bash
cd ui && npm install && npm run build   # type-checks and compiles all routes
npm run dev                             # requires IAM_URL + PARTNER_MANAGEMENT_API_URL
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/platform/platform-services/partner-management/testing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
