name: SecurityEventAutoreg
testcases:
- name: get_login_token
  steps:
  - type: get_login_token

- name: sleep_some_time
  steps:
  - type: sleep
    time_to_sleep: 30

- name: get_unregdate_should_be_after
  steps:
  - type: exec
    script: 'cat /tmp/calculate_unregdate_should_be_after.txt'
    vars:
      datetime:
        from: result.systemout

- name: check_node_autoregistered
  steps:
  - type: http
    method: GET
    url: '{{.pfserver_webadmin_url}}/api/v1/node/{{.security_event_autoreg.node.mac_url_encoded}}'
    ignore_verify_ssl: true
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
    - result.statuscode ShouldEqual 200
    - result.bodyjson.item.dhcp_fingerprint ShouldEqual "{{.security_event_autoreg.node.dhcp_fingerprint}}"
    - result.bodyjson.item.status ShouldEqual "reg"
    vars:
      unregdate:
        from: result.bodyjson.item.unregdate  

- name: check_node_unregdate
  steps:
  - type: exec
    script: 'date +"%Y-%m-%dT%H:%M:%S+00:00" --date="{{.check_node_autoregistered.unregdate}}"'
    assertions:
      - result.systemout ShouldHappenAfter "{{.get_unregdate_should_be_after.datetime}}"

- name: check_host_internet_access
  steps:
  - type: check_internet_access_on_host 
