name: Check RADIUS audit log
testcases:
- name: get_login_token
  steps:
  - type: get_login_token

- name: move_from_redis_to_db
  steps:
  - type: pfcron_flush_radius_audit_log

# auth_status equals Accept (to avoid Disconnect)
# mac equals {{.node01_ens7_mac_address}}"
# connection type of test suite connection profile
- name: get_id_of_radius_audit_log_entry
  steps:
  - type: http
    method: POST
    url: '{{.pfserver_webadmin_url}}/api/v1/radius_audit_logs/search'
    ignore_verify_ssl: true
    retry: 35
    retry_if:
      - result.statuscode ShouldNotEqual 404
    delay: 3
    assertions:
      - result.statuscode ShouldEqual 200
    body: >-
      {
        "cursor": 0,
        "fields": [
          "id"
        ],
        "sort": [
          "created_at DESC"
        ],        
        "limit": 1,
        "query": {
          "op": "and",
          "values": [
            {
              "op": "or",
              "values": [
                {
                  "field": "mac",
                  "op": "equals",
                  "value": "{{.wireless01_wlan1_mac_address}}"
                }
              ]
            },
            {
              "op": "or",
              "values": [
                {
                  "field": "auth_status",
                  "op": "equals",
                  "value": "Accept"
                }
              ]
            },
            {
              "op": "or",
              "values": [
                {
                  "field": "connection_type",
                  "op": "equals",
                  "value": "{{.wireless_mac_auth.profiles.wireless.filters.connection_type}}"
                }
              ]
            }
          ]
        }
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
      - result.bodyjson.items.items0 ShouldContainKey id
    vars:
      id:
        from: result.bodyjson.items.items0.id
      
- name: check_radius_reply
  steps:
  - type: http
    method: GET
    url: '{{.pfserver_webadmin_url}}/api/v1/radius_audit_log/{{.get_id_of_radius_audit_log_entry.id}}'
    ignore_verify_ssl: true
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
      - result.bodyjson.item.radius_reply ShouldContainSubstring 'Tunnel-Private-Group-Id = "{{.wireless_mac_auth.roles.headless_device.vlan_id}}"'
      - result.bodyjson.item.profile ShouldEqual "{{.wireless_mac_auth.profiles.wireless.id}}"

