529 lines
14 KiB
YAML
529 lines
14 KiB
YAML
#
|
||
# Test the Archive Policy API to achieve coverage of just the
|
||
# ArchivePoliciesController.
|
||
#
|
||
|
||
fixtures:
|
||
- ConfigFixture
|
||
|
||
tests:
|
||
|
||
# Retrieve the empty list when there are no archive policies.
|
||
# NOTE(chdent): This demonstrates what used to be considered a
|
||
# security bug in JSON output:
|
||
# http://flask.pocoo.org/docs/0.10/security/#json-security
|
||
# The version described there is supposed to be fixed in most modern
|
||
# browsers but there is a new version of the problem which is only
|
||
# fixed in some:
|
||
# http://haacked.com/archive/2009/06/25/json-hijacking.aspx/
|
||
# The caveats point out that this is only an issue if your data is
|
||
# sensitive, which in this case...?
|
||
# However, the api-wg has made it recommendation that collections
|
||
# should be returned as an object with a named key with a value of
|
||
# a list as follows: {"archive_policies": [...]}
|
||
# This allows for extensibility such as future support for pagination.
|
||
# Do we care?
|
||
|
||
- name: empty archive policy list
|
||
url: /v1/archive_policy
|
||
response_headers:
|
||
content-type: /application/json/
|
||
response_strings:
|
||
- "[]"
|
||
|
||
- name: empty list text
|
||
url: /v1/archive_policy
|
||
request_headers:
|
||
accept: text/plain
|
||
status: 406
|
||
|
||
- name: empty list html
|
||
url: /v1/archive_policy
|
||
request_headers:
|
||
accept: text/html
|
||
status: 406
|
||
|
||
# Fail to create an archive policy for various reasons.
|
||
|
||
- name: wrong content type
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: text/plain
|
||
x-roles: admin
|
||
status: 415
|
||
response_strings:
|
||
- Unsupported Media Type
|
||
|
||
- name: wrong method
|
||
url: /v1/archive_policy
|
||
method: PUT
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
status: 405
|
||
|
||
- name: wrong authZ
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: clancy
|
||
data:
|
||
name: medium
|
||
definition:
|
||
- granularity: 1 second
|
||
status: 403
|
||
|
||
- name: missing authZ
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
data:
|
||
name: medium
|
||
definition:
|
||
- granularity: 1 second
|
||
status: 403
|
||
|
||
- name: bad request body
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
cowsay: moo
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: extra keys not allowed"
|
||
|
||
- name: missing definition
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: medium
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: required key not provided"
|
||
|
||
- name: empty definition
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: medium
|
||
definition: []
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: length of value must be at least 1"
|
||
|
||
- name: wrong value definition
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: somename
|
||
definition: foobar
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: expected a list"
|
||
|
||
- name: useless definition
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: medium
|
||
definition:
|
||
- cowsay: moo
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: extra keys not allowed"
|
||
|
||
# Create a valid archive policy.
|
||
|
||
- name: create archive policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: medium
|
||
definition:
|
||
- granularity: 1 second
|
||
points: 20
|
||
- granularity: 2 second
|
||
response_headers:
|
||
location: $SCHEME://$NETLOC/v1/archive_policy/medium
|
||
status: 201
|
||
|
||
# Retrieve it correctly and then poorly
|
||
|
||
- name: get archive policy
|
||
url: $LOCATION
|
||
response_headers:
|
||
content-type: /application/json/
|
||
response_json_paths:
|
||
$.name: medium
|
||
$.definition[0].granularity: "0:00:01"
|
||
$.definition[0].points: 20
|
||
$.definition[0].timespan: "0:00:20"
|
||
$.definition[1].granularity: "0:00:02"
|
||
$.definition[1].points: null
|
||
$.definition[1].timespan: null
|
||
|
||
- name: get wrong accept
|
||
url: /v1/archive_policy/medium
|
||
request_headers:
|
||
accept: text/plain
|
||
status: 406
|
||
|
||
# Unexpected methods
|
||
|
||
- name: post single archive
|
||
url: /v1/archive_policy/medium
|
||
method: POST
|
||
status: 405
|
||
|
||
- name: put single archive
|
||
url: /v1/archive_policy/medium
|
||
method: PUT
|
||
status: 405
|
||
|
||
# Create another one and then test duplication
|
||
|
||
- name: create second policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: large
|
||
definition:
|
||
- granularity: 1 hour
|
||
response_headers:
|
||
location: $SCHEME://$NETLOC/v1/archive_policy/large
|
||
status: 201
|
||
|
||
- name: create duplicate policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: large
|
||
definition:
|
||
- granularity: 1 hour
|
||
status: 409
|
||
response_strings:
|
||
- Archive policy large already exists
|
||
|
||
# Create a unicode named policy
|
||
|
||
- name: post unicode policy name
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: ✔éñ☃
|
||
definition:
|
||
- granularity: 1 minute
|
||
points: 20
|
||
status: 201
|
||
response_headers:
|
||
location: $SCHEME://$NETLOC/v1/archive_policy/%E2%9C%94%C3%A9%C3%B1%E2%98%83
|
||
response_json_paths:
|
||
name: ✔éñ☃
|
||
|
||
- name: retrieve unicode policy name
|
||
url: $LOCATION
|
||
response_json_paths:
|
||
name: ✔éñ☃
|
||
|
||
- name: post small unicode policy name
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: æ
|
||
definition:
|
||
- granularity: 1 minute
|
||
points: 20
|
||
status: 201
|
||
response_headers:
|
||
location: $SCHEME://$NETLOC/v1/archive_policy/%C3%A6
|
||
response_json_paths:
|
||
name: æ
|
||
|
||
- name: retrieve small unicode policy name
|
||
url: $LOCATION
|
||
response_json_paths:
|
||
name: æ
|
||
|
||
# List the collection
|
||
|
||
- name: get archive policy list
|
||
url: /v1/archive_policy
|
||
# TODO(chdent): We do not know the order, should we?
|
||
response_strings:
|
||
- '"name": "medium"'
|
||
- '"name": "large"'
|
||
|
||
# Delete one as non-admin
|
||
|
||
- name: delete single archive non admin
|
||
url: /v1/archive_policy/medium
|
||
method: DELETE
|
||
status: 403
|
||
|
||
# Delete one
|
||
|
||
- name: delete single archive
|
||
url: /v1/archive_policy/medium
|
||
method: DELETE
|
||
request_headers:
|
||
x-roles: admin
|
||
status: 204
|
||
|
||
# It really is gone
|
||
|
||
- name: confirm delete
|
||
url: /v1/archive_policy/medium
|
||
status: 404
|
||
|
||
# Fail to delete one that does not exist
|
||
|
||
- name: delete missing archive
|
||
url: /v1/archive_policy/grandiose
|
||
method: DELETE
|
||
request_headers:
|
||
x-roles: admin
|
||
status: 404
|
||
response_strings:
|
||
- Archive policy grandiose does not exist
|
||
|
||
- name: delete archive utf8
|
||
url: /v1/archive_policy/%E2%9C%94%C3%A9%C3%B1%E2%98%83
|
||
method: DELETE
|
||
request_headers:
|
||
x-roles: admin
|
||
status: 204
|
||
|
||
- name: delete missing archive utf8 again
|
||
url: /v1/archive_policy/%E2%9C%94%C3%A9%C3%B1%E2%98%83
|
||
method: DELETE
|
||
request_headers:
|
||
x-roles: admin
|
||
status: 404
|
||
response_strings:
|
||
- Archive policy ✔éñ☃ does not exist
|
||
|
||
# Add metric using the policy and then be unable to delete policy
|
||
|
||
- name: create metric
|
||
url: /v1/metric
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-user-id: 93180da9-7c15-40d3-a050-a374551e52ee
|
||
x-project-id: 99d13f22-3618-4288-82b8-6512ded77e4f
|
||
data:
|
||
archive_policy_name: large
|
||
status: 201
|
||
|
||
- name: delete in use policy
|
||
url: /v1/archive_policy/large
|
||
method: DELETE
|
||
request_headers:
|
||
x-roles: admin
|
||
status: 400
|
||
response_strings:
|
||
- Archive policy large is still in use
|
||
|
||
# Attempt to create illogical policies
|
||
|
||
- name: create illogical policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: complex
|
||
definition:
|
||
- granularity: 1 second
|
||
points: 60
|
||
timespan: "0:01:01"
|
||
status: 400
|
||
response_strings:
|
||
- timespan ≠ granularity × points
|
||
|
||
- name: create invalid points policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: complex
|
||
definition:
|
||
- granularity: 0
|
||
points: 60
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: not a valid value for dictionary value"
|
||
|
||
- name: create invalid granularity policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: complex
|
||
definition:
|
||
- granularity: 10
|
||
points: 0
|
||
status: 400
|
||
response_strings:
|
||
- "Invalid input: not a valid value for dictionary value"
|
||
|
||
- name: create identical granularities policy
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: complex
|
||
definition:
|
||
- granularity: 1 second
|
||
points: 60
|
||
- granularity: 1 second
|
||
points: 120
|
||
status: 400
|
||
response_strings:
|
||
- "More than one archive policy uses granularity `1.0'"
|
||
|
||
- name: policy invalid unit
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: 227d0e1f-4295-4e4b-8515-c296c47d71d3
|
||
definition:
|
||
- granularity: 1 second
|
||
timespan: "1 shenanigan"
|
||
status: 400
|
||
|
||
# Non admin user attempt
|
||
|
||
- name: fail to create policy non-admin
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-user-id: b45187c5-150b-4730-bcb2-b5e04e234220
|
||
x-project-id: 16764ee0-bffe-4843-aa36-04b002cdbc7c
|
||
data:
|
||
name: f1d150d9-02ad-4fe7-8872-c64b2bcaaa97
|
||
definition:
|
||
- granularity: 1 minute
|
||
points: 20
|
||
status: 403
|
||
response_strings:
|
||
- Access was denied to this resource
|
||
|
||
# Back windows
|
||
|
||
- name: policy with back window
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: 7720a99d-cd3b-4aa4-8a6f-935bf0d46ded
|
||
back_window: 1
|
||
definition:
|
||
- granularity: 10s
|
||
points: 20
|
||
status: 201
|
||
response_json_paths:
|
||
$.back_window: 1
|
||
$.definition[0].timespan: "0:03:20"
|
||
|
||
- name: policy no back window
|
||
desc: and default seconds on int granularity
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: 22f2b99f-e629-4170-adc4-09b65635e056
|
||
back_window: 0
|
||
definition:
|
||
- granularity: 10
|
||
points: 20
|
||
status: 201
|
||
response_json_paths:
|
||
$.back_window: 0
|
||
$.definition[0].points: 20
|
||
$.definition[0].timespan: "0:03:20"
|
||
|
||
# Timespan, points, granularity input tests
|
||
|
||
- name: policy float granularity
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: 595228db-ea29-4415-9d5b-ecb5366abb1b
|
||
definition:
|
||
- timespan: 1 hour
|
||
points: 1000
|
||
status: 201
|
||
response_json_paths:
|
||
$.definition[0].points: 1000
|
||
$.definition[0].granularity: "0:00:04"
|
||
$.definition[0].timespan: "1:06:40"
|
||
|
||
- name: policy float timespan
|
||
url: /v1/archive_policy
|
||
method: POST
|
||
request_headers:
|
||
content-type: application/json
|
||
x-roles: admin
|
||
data:
|
||
name: 6bc72791-a27e-4417-a589-afc6d2067a38
|
||
definition:
|
||
- timespan: 1 hour
|
||
granularity: 7s
|
||
status: 201
|
||
response_json_paths:
|
||
$.definition[0].points: 514
|
||
$.definition[0].granularity: "0:00:07"
|
||
$.definition[0].timespan: "0:59:58"
|