# yaml-language-server: $schema=https://api.cerbos.dev/latest/cerbos/policy/v1/TestSuite.schema.json
---
principals:
  user_with_create_ad_reports_role:
    id: "user_with_create_ad_reports_role_uuid"
    roles:
      - user
    attr:
      type: human
      tenants:
        "gto35228-00d8-93c6-b4op-286ef3e79319":
          tenant_uuid: "gto35228-00d8-93c6-b4op-286ef3e79319"
          tenant_type: "account"
          roles:
            fansifter_can_create_ad_reports:
              role: fansifter_can_create_ad_reports
  user_with_create_ad_reports_role_in_random_tenant:
    id: "user_with_create_ad_reports_role_in_random_tenant_uuid"
    roles:
      - user
    attr:
      type: human
      tenants:
        random_tenant:
          tenant_uuid: random_tenant_uuid
          tenant_type: "account"
          roles:
            fansifter_can_create_ad_reports:
              role: fansifter_can_create_ad_reports

resources:
  olivia_ad_report_shared_with_brian:
    id: "ad_report_create_with_multiple_tenants"
    kind: "ad_report"
    attr:
      identity_uuid: "3604ff98-f825-4ea1-9f48-a7f56f413ec4"
      shared_with_identities:
        - "08fc2c19-43fb-4804-9249-d0992554997f"
  brian_ad_report_shared_with_company_brand_1_tenant:
    id: "ad_report_create_with_multiple_tenants"
    kind: "ad_report"
    attr:
      identity_uuid: "08fc2c19-43fb-4804-9249-d0992554997f"
      shared_with_tenants:
        - tenant_uuid: "company_brand_1"
        - tenant_uuid: "columbia_tenant_uuid"

name: AdReportTestSuite
description: Tests for verifying the ad report resource policy
tests:
  - name: Managing an Ad Report
    input:
      principals:
        - olivia
        - brian
        - client_user_with_company_brand_1_tenant
        - random_role_user
        - user_with_create_ad_reports_role
        - user_with_create_ad_reports_role_in_random_tenant
      resources:
        - olivia_ad_report_shared_with_brian
        - brian_ad_report_shared_with_company_brand_1_tenant
      actions:
        - create
        - view
        - edit
        - share
        - delete
    expected:
      - principal: olivia
        resource: olivia_ad_report_shared_with_brian
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_ALLOW
          edit: EFFECT_ALLOW
          share: EFFECT_ALLOW
          delete: EFFECT_ALLOW
      - principal: brian
        resource: olivia_ad_report_shared_with_brian
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_ALLOW
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: client_user_with_company_brand_1_tenant
        resource: olivia_ad_report_shared_with_brian
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: brian
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_ALLOW
          edit: EFFECT_ALLOW
          share: EFFECT_ALLOW
          delete: EFFECT_ALLOW
      - principal: client_user_with_company_brand_1_tenant
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_ALLOW
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: olivia
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: random_role_user
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_DENY
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
# roles V2
      - principal: user_with_create_ad_reports_role
        resource: olivia_ad_report_shared_with_brian
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: user_with_create_ad_reports_role
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_ALLOW
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: user_with_create_ad_reports_role_in_random_tenant
        resource: olivia_ad_report_shared_with_brian
        actions:
          create: EFFECT_ALLOW  # user with role in any tenant ALLOWed to create Ad Report
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
      - principal: user_with_create_ad_reports_role_in_random_tenant
        resource: brian_ad_report_shared_with_company_brand_1_tenant
        actions:
          create: EFFECT_ALLOW  # user with role in any tenant ALLOWed to create Ad Report
          view: EFFECT_DENY
          edit: EFFECT_DENY
          share: EFFECT_DENY
          delete: EFFECT_DENY
