---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    cluster.health:
      wait_for_status: "yellow"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    security.put_user:
      username: "joe"
      body: "{\n  \"password\": \"s3krit-password\",\n  \"roles\" : [ \"admin_role\"\
        \ ]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    security.delete_user:
      username: "joe"
      ignore: 404
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test bulk put and delete roles api:
- do:
    security.bulk_put_role:
      body: "{\n    \"roles\": {\n        \"admin_role\": {\n            \"cluster\"\
        : [\n                \"all\"\n            ],\n            \"metadata\": {\n\
        \                \"key1\": \"val1\",\n                \"key2\": \"val2\"\n\
        \            },\n            \"indices\": [\n                {\n         \
        \           \"names\": \"*\",\n                    \"privileges\": [\n   \
        \                     \"all\"\n                    ]\n                }\n\
        \            ]\n        },\n        \"role_with_description\": {\n       \
        \     \"description\": \"Allows all security-related operations such as CRUD\
        \ operations on users and roles and cache clearing.\",\n            \"cluster\"\
        : [\n                \"manage_security\"\n            ]\n        }\n    }\n\
        }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    created:
    - "admin_role"
    - "role_with_description"
- do:
    headers:
      Authorization: "Basic am9lOnMza3JpdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    security.get_role:
      name: "admin_role"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    admin_role.cluster.0: "all"
- match:
    admin_role.metadata.key1: "val1"
- match:
    admin_role.metadata.key2: "val2"
- match:
    admin_role.indices.0.names.0: "*"
- match:
    admin_role.indices.0.privileges.0: "all"
- do:
    headers:
      Authorization: "Basic am9lOnMza3JpdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    security.get_role:
      name: "role_with_description"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    role_with_description.cluster.0: "manage_security"
- match:
    role_with_description.description: "Allows all security-related operations such\
      \ as CRUD operations on users and roles and cache clearing."
- do:
    headers:
      Authorization: "Basic am9lOnMza3JpdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    security.query_role:
      body: "{\n  \"query\": {\n    \"bool\": {\n      \"must_not\": {\n        \"\
        term\": {\n          \"metadata._reserved\": true\n        }\n      }\n  \
        \  }\n  },\n\"sort\": [\"name\"] }\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    total: 2
- match:
    count: 2
- match:
    roles.0.name: "admin_role"
- match:
    roles.1.name: "role_with_description"
- do:
    security.bulk_delete_role:
      body: "{\n   \"names\": [\"admin_role\", \"role_with_description\"]\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    deleted.0: "admin_role"
- match:
    deleted.1: "role_with_description"
