---
setup:
  - skip:
      features: headers
  - do:
      cluster.health:
        wait_for_status: yellow
  - do:
      security.put_user:
        username: "joe"
        body:  >
          {
            "password": "s3krit-password",
            "roles" : [ "token_admin" ]
          }
  - do:
      security.put_role:
        name: "token_admin"
        body:  >
          {
            "cluster": ["manage_token"],
            "indices": [
              {
                "names": "*",
                "privileges": ["all"]
              }
            ]
          }
  - do:
      security.activate_user_profile:
        body: >
          {
            "grant_type": "password",
            "username": "joe",
            "password" : "s3krit-password"
          }
  - do:
      headers:
        Authorization: "Basic am9lOnMza3JpdC1wYXNzd29yZA=="
      security.get_token:
        body:
          grant_type: "password"
          username: "joe"
          password: "s3krit-password"
---
teardown:
  - do:
      security.delete_user:
        username: "joe"
        ignore: 404
  - do:
      security.delete_role:
        name: "token_admin"
        ignore: 404

---
"Test update and get security settings API":
  - do:
      security.get_settings: {}

  - match: { "security.index.number_of_replicas": "0" }
  - match: { "security.index.auto_expand_replicas": "0-1" }
  - match: { "security-tokens.index.auto_expand_replicas": "0-1" }
  - match: { "security-tokens.index.number_of_replicas": "0" }
  - match: { "security-profile.index.auto_expand_replicas": "0-1" }
  - match: { "security-profile.index.number_of_replicas": "0" }

  - do:
      security.update_settings:
        body:
          security:
              index.auto_expand_replicas: "0-all"
          security-tokens:
              index.auto_expand_replicas: "0-all"
          security-profile:
              index.auto_expand_replicas: "0-all"

  - do:
      security.get_settings: { }

  - match: { "security.index.auto_expand_replicas": "0-all" }
  - match: { "security-tokens.index.auto_expand_replicas": "0-all" }
  - match: { "security-profile.index.auto_expand_replicas": "0-all" }

  - do:
      security.update_settings:
        body:
          security:
              index.auto_expand_replicas: null
              index.number_of_replicas: 1
          security-tokens:
              index.auto_expand_replicas: null
              index.number_of_replicas: 1
          security-profile:
              index.auto_expand_replicas: null
              index.number_of_replicas: 1

  - do:
      security.get_settings: { }

  - match: { "security.index.number_of_replicas": "1" }
  - match: { "security-tokens.index.number_of_replicas": "1" }
  - match: { "security-tokens.index.number_of_replicas": "1" }
