name: Create and configure REALMS
testcases:
- name: get_login_token
  steps:
  - type: get_login_token

- name: get_ad_domain_id
  steps:
  - type: http
    method: GET
    url: '{{.pfserver_webadmin_url}}/api/v1/config/domains'
    ignore_verify_ssl: true
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
    vars:
      domain_id:
        from: result.bodyjson.items.items0.id

- name: create_realms
  steps:
  - type: http
    method: POST
    url: '{{.pfserver_webadmin_url}}/api/v1/config/realms'
    ignore_verify_ssl: true
    body: >-
      {
        "admin_strip_username": "enabled",
        "domain": "{{.get_ad_domain_id.domain_id}}",
        "eduroam_options": null,
        "eduroam_radius_acct": null,
        "eduroam_radius_acct_proxy_type": "load-balance",
        "eduroam_radius_auth": null,
        "eduroam_radius_auth_compute_in_pf": "enabled",
        "eduroam_radius_auth_proxy_type": "keyed-balance",
        "id": "{{.ad_domain_upper}}",
        "ldap_source": null,
        "options": null,
        "permit_custom_attributes": "disabled",
        "portal_strip_username": "enabled",
        "radius_acct": null,
        "radius_acct_proxy_type": "load-balance",
        "radius_auth": null,
        "radius_auth_compute_in_pf": "enabled",
        "radius_auth_proxy_type": "keyed-balance",
        "radius_strip_username": "enabled"
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 201

  - type: http
    method: POST
    url: '{{.pfserver_webadmin_url}}/api/v1/config/realms'
    ignore_verify_ssl: true
    body: >-
      {
        "admin_strip_username": "enabled",
        "domain": "{{.get_ad_domain_id.domain_id}}",
        "eduroam_options": null,
        "eduroam_radius_acct": null,
        "eduroam_radius_acct_proxy_type": "load-balance",
        "eduroam_radius_auth": null,
        "eduroam_radius_auth_compute_in_pf": "enabled",
        "eduroam_radius_auth_proxy_type": "keyed-balance",
        "id": "{{.ad_dns_domain}}",
        "ldap_source": null,
        "options": null,
        "permit_custom_attributes": "disabled",
        "portal_strip_username": "enabled",
        "radius_acct": null,
        "radius_acct_proxy_type": "load-balance",
        "radius_auth": null,
        "radius_auth_compute_in_pf": "enabled",
        "radius_auth_proxy_type": "keyed-balance",
        "radius_strip_username": "enabled"
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 201

- name: modify_builtin_realms
  steps:
  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/realm/DEFAULT'
    ignore_verify_ssl: true
    body: >-
      {
        "domain": "{{.get_ad_domain_id.domain_id}}"
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200

  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/realm/NULL'
    ignore_verify_ssl: true
    body: >-
      {
        "domain": "{{.get_ad_domain_id.domain_id}}"
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
