test/automated-pytest-suite/testcases/rest/test_GET_adversarial.py
Yang Liu 33756ac899 Initial submission for starlingx pytest framework.
Include:
- util modules. such as table_parser, ssh/localhost clients, cli module,
exception, logger, etc. Util modules are mostly used by keywords.
- keywords modules. These are helper functions that are used directly by
test functions.
- platform (with platform or platform_sanity marker) and stx-openstack
(with sanity, sx_sanity, cpe_sanity, or storage_sanity marker) sanity
testcases
- pytest config conftest, and test fixture modules
- test config file template/example

Required packages:
- python3.4 or python3.5
- pytest >=3.10,<4.0
- pexpect
- requests
- pyyaml
- selenium (firefox, ffmpeg, pyvirtualdisplay, Xvfb or Xephyr or Xvnc)

Limitations:
- Anything that requires copying from Test File Server will not work until
a public share is configured to shared test files. Tests skipped for now.

Co-Authored-By: Maria Yousaf <maria.yousaf@windriver.com>
Co-Authored-By: Marvin Huang <marvin.huang@windriver.com>
Co-Authored-By: Yosief Gebremariam <yosief.gebremariam@windriver.com>
Co-Authored-By: Paul Warner <paul.warner@windriver.com>
Co-Authored-By: Xueguang Ma <Xueguang.Ma@windriver.com>
Co-Authored-By: Charles Chen <charles.chen@windriver.com>
Co-Authored-By: Daniel Graziano <Daniel.Graziano@windriver.com>
Co-Authored-By: Jordan Li <jordan.li@windriver.com>
Co-Authored-By: Nimalini Rasa <nimalini.rasa@windriver.com>
Co-Authored-By: Senthil Mukundakumar <senthil.mukundakumar@windriver.com>
Co-Authored-By: Anuejyan Manokeran <anujeyan.manokeran@windriver.com>
Co-Authored-By: Peng Peng <peng.peng@windriver.com>
Co-Authored-By: Chris Winnicki <chris.winnicki@windriver.com>
Co-Authored-By: Joe Vimar <Joe.Vimar@windriver.com>
Co-Authored-By: Alex Kozyrev <alex.kozyrev@windriver.com>
Co-Authored-By: Jack Ding <jack.ding@windriver.com>
Co-Authored-By: Ming Lei <ming.lei@windriver.com>
Co-Authored-By: Ankit Jain <ankit.jain@windriver.com>
Co-Authored-By: Eric Barrett <eric.barrett@windriver.com>
Co-Authored-By: William Jia <william.jia@windriver.com>
Co-Authored-By: Joseph Richard <Joseph.Richard@windriver.com>
Co-Authored-By: Aldo Mcfarlane <aldo.mcfarlane@windriver.com>

Story: 2005892
Task: 33750
Signed-off-by: Yang Liu <yang.liu@windriver.com>

Change-Id: I7a88a47e09733d39f024144530f5abb9aee8cad2
2019-07-15 15:30:00 -04:00

99 lines
3.1 KiB
Python
Executable File

#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import pytest
from utils.tis_log import LOG
from utils.rest import Rest
from keywords import system_helper
import string
@pytest.fixture(scope='module')
def sysinv_rest():
r = Rest('sysinv', platform=True)
return r
def test_GET_ihosts_host_id_shortUUID(sysinv_rest):
"""
Test GET of <resource> with valid authentication and upper
case UUID values.
RFC 4122 covers the need for uppercase UUID values
Args:
n/a
Prerequisites: system is running
Test Setups:
n/a
Test Steps:
- Using requests GET <resource> with proper authentication
- Determine if expected status_code of 200 is received
Test Teardown:
n/a
"""
path = "/ihosts/{}/addresses"
r = sysinv_rest
LOG.info(path)
LOG.info(system_helper.get_hosts())
for host in system_helper.get_hosts():
uuid = system_helper.get_host_values(host, 'uuid')[0]
LOG.info("host: {} uuid: {}".format(host, uuid))
message = "Using requests GET {} with proper authentication"
LOG.tc_step(message.format(path))
short_uuid = uuid[:-1]
status_code, text = r.get(resource=path.format(short_uuid),
auth=True)
message = "Retrieved: status_code: {} message: {}"
LOG.info(message.format(status_code, text))
LOG.tc_step("Determine if expected code of 400 is received")
message = "Expected code of 400 - received {} and message {}"
assert status_code == 400, message.format(status_code, text)
def test_GET_ihosts_host_id_invalidUUID(sysinv_rest):
"""
Test GET of <resource> with valid authentication and upper
case UUID values.
RFC 4122 covers the need for uppercase UUID values
Args:
n/a
Prerequisites: system is running
Test Setups:
n/a
Test Steps:
- Using requests GET <resource> with proper authentication
- Determine if expected status_code of 200 is received
Test Teardown:
n/a
"""
path = "/ihosts/{}/addresses"
r = sysinv_rest
LOG.info(path)
LOG.info(system_helper.get_hosts())
for host in system_helper.get_hosts():
uuid = system_helper.get_host_values(host, 'uuid')[0]
LOG.info("host: {} uuid: {}".format(host, uuid))
message = "Using requests GET {} with proper authentication"
LOG.tc_step(message.format(path))
# shift a->g, b->h, etc - all to generate invalid uuid
shifted_uuid = \
''.join(map(lambda x: chr((ord(x) - ord('a') + 6) % 26 + ord(
'a')) if x in string.ascii_lowercase else x, uuid.lower()))
status_code, text = r.get(resource=path.format(shifted_uuid),
auth=True)
message = "Retrieved: status_code: {} message: {}"
LOG.info(message.format(status_code, text))
LOG.tc_step("Determine if expected code of 400 is received")
message = "Expected code of 400 - received {} and message {}"
assert status_code == 400, message.format(status_code, text)