Example 21

Negative test: an unnamed identity is denied

Permission tests prove the guardrails: an identity the profile does not name gets nothing.

Status
runnable in repo test
Industry
Security
Language
Python
Framework
pytest
CI
any
Fulfilment
LEASE_CERTIFIED_VERSION
Profile
orders-pr-regression

About this example

All data is synthetic. DataNivra provisions approved test data into a customer-controlled target; it does not run these tests. Credentials for the target are never returned by DataNivra — your runner holds its own.

Why test data matters

Permission tests prove the guardrails: an identity the profile does not name gets nothing.

What is requested

A lease by a CI workload identity that the profile's envelope does not list.

Policy gates

The envelope names the allowed workload identities.

What is provisioned

Nothing.

Expected output

403 TEST_DATA_REQUEST_DENIED, detail WORKLOAD_NOT_PERMITTED_BY_PROFILE; the identity cannot even list the profile.

Cleanup

Nothing to clean up.

Files

  • request.yaml
  • example.py

Run

  1. A tenant administrator defines and a second person approves the profile (datanivra test-data define ../../profiles/orders-pr-regression.yaml --submit, then datanivra policies approve).
  2. datanivra test-data validate request.yaml && datanivra test-data plan request.yaml
  3. Run the example with DATANIVRA_BASE_URL and a session or workload token.

Files

Exactly as they are in the examples repository. Every value is a synthetic placeholder; nothing here is a credential.

request.yaml

# yaml-language-server: $schema=../../../../packages/contracts/schemas/v1/manifests/test-data-request.schema.json
# DataNivra test-data-request manifest (apiVersion datanivra.io/v1alpha1). Validate: datanivra test-data validate <file>
apiVersion: datanivra.io/v1alpha1
kind: TestDataRequest
metadata:
  name: unauthorized-ci
spec:
  profile: { name: orders-pr-regression, version: 1 }

examples/test-data-api/scenarios/21-negative-permission-denied/request.yaml

example.py

"""Negative test: an unnamed identity is denied — provision approved test data through the Python SDK.

``provision`` only asks DataNivra for data from the approved ``orders-pr-regression`` profile; your own test
suite runs against the approved target with its own, separately managed database access.
"""

from __future__ import annotations

from pathlib import Path

from datanivra_contracts.testdata import TestDataRequest
from datanivra_sdk import DataNivraClient
from datanivra_sdk.testdata import TestDataClient

REQUEST = Path(__file__).with_name("request.yaml")


def provision(api: DataNivraClient, *, idempotency_key: str | None = None) -> TestDataRequest:
    """Create (or, for the same key, return) the request; DENIED raises ``DataNivraApiError``."""
    return TestDataClient(api).request(REQUEST, idempotency_key=idempotency_key)

examples/test-data-api/scenarios/21-negative-permission-denied/example.py

The profile it uses: orders-pr-regression

A tenant administrator defines this profile and a second person approves it; requests can only ask for what it allows. All profiles

orders-pr-regression.yaml

# yaml-language-server: $schema=../../../packages/contracts/schemas/v1/manifests/test-data-profile.schema.json
# DataNivra test-data-profile manifest (apiVersion datanivra.io/v1alpha1). Validate: datanivra test-data validate <file>
# Placeholder ids (00000000-0000-4000-8000-0000000000NN): replace with your ids.
# 01 = approved target environment, 11 = certified dataset, 21 = customer agent,
# 99 = workload identity trust (datanivra workload-identities list).
apiVersion: datanivra.io/v1alpha1
kind: TestDataProfile
metadata:
  name: orders-pr-regression
  description: Certified orders dataset leased into an isolated CI database per pull request
spec:
  fulfilment: LEASE_CERTIFIED_VERSION
  lease:
    dataset_id: 00000000-0000-4000-8000-000000000011
    agent_id: 00000000-0000-4000-8000-000000000021
    provider_kind: POSTGRESQL_CONTAINER
    default_ttl_seconds: 1800
    max_ttl_seconds: 7200
    target_pool:
      - env://DATANIVRA_CI_DB_1
      - env://DATANIVRA_CI_DB_2
      - env://DATANIVRA_CI_DB_3
      - env://DATANIVRA_CI_DB_4
  automation:
    workload_identity_ids: [00000000-0000-4000-8000-000000000099]
    max_ttl_seconds: 3600
    max_live_requests: 4
  audit_tags: [CI_PULL_REQUEST]

examples/test-data-api/profiles/orders-pr-regression.yaml