def test_test_http_unsupported_methods_pass2(self): add_response(self.sut, '/redfish/v1/', 'TRACE', requests.codes.NOT_IMPLEMENTED) proto.test_http_unsupported_methods(self.sut) result = get_result(self.sut, Assertion.PROTO_HTTP_UNSUPPORTED_METHODS, 'TRACE', '/redfish/v1/') self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_test_http_unsupported_methods_fail(self): add_response(self.sut, '/redfish/v1/', 'TRACE', requests.codes.BAD_REQUEST) proto.test_http_unsupported_methods(self.sut) result = get_result(self.sut, Assertion.PROTO_HTTP_UNSUPPORTED_METHODS, 'TRACE', '/redfish/v1/') self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn('TRACE method returned status', result['msg'])
def setUp(self): super(ProtocolDetails, self).setUp() self.sut = SystemUnderTest('http://127.0.0.1:8000', 'oper', 'xyzzy') sse_uri = '/redfish/v1/EventService/SSE' self.sut.set_server_sent_event_uri(sse_uri) self._add_get_responses(status=requests.codes.OK) add_response(self.sut, '/redfish/v1/AccountService/Accounts', 'POST', requests.codes.CREATED, json={'foo': 'bar'}, request_payload='{"UserName": "******"}')
def test_select_standard_role_fail(self, mock_logging_error): payload = {'Id': 'Guest'} add_response(self.sut, self.role_uri1, json=payload, res_type=ResourceType.ROLE) role = accounts.select_standard_role(self.sut, self.session) self.assertIsNone(role) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('Predefined role "ReadOnly" not found', args[0])
def test_add_account_collection_get_fail(self, mock_logging_error): add_response(self.sut, self.accounts_uri, json={}, status_code=requests.codes.NOT_FOUND) user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(user) self.assertIsNone(uri) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('Accounts collection could not be read', args[0])
def test_test_odata_service_value_prop_pass(self): uri = '/redfish/v1/odata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, json={'value': []}) resp.test_odata_service_value_prop(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_SERVICE_VALUE_PROP, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_test_odata_service_mime_type_pass(self): uri = '/redfish/v1/odata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, headers={'Content-Type': 'application/json'}) resp.test_odata_service_mime_type(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_SERVICE_MIME_TYPE, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_test_odata_service_context_pass(self): uri = '/redfish/v1/odata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, json={'@odata.context': '/redfish/v1/$metadata'}) resp.test_odata_service_context(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_SERVICE_CONTEXT, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_delete_account_allow_header_no_delete(self): payload = {'UserName': '******', 'Enabled': True} headers = {'Allow': 'GET, POST'} add_response(self.sut, self.account_uri1, json=payload, res_type=ResourceType.MANAGER_ACCOUNT, headers=headers) self.session.patch.return_value.status_code = requests.codes.OK accounts.delete_account(self.sut, self.session, 'Administrator', self.account_uri1) self.assertEqual(self.session.patch.call_count, 1)
def test_test_odata_metadata_mime_type_pass2(self): uri = '/redfish/v1/$metadata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, headers={'Content-Type': 'application/xml;charset=utf-8'}) resp.test_odata_metadata_mime_type(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_METADATA_MIME_TYPE, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_test_odata_service_mime_type_fail1(self): uri = '/redfish/v1/odata' add_response(self.sut, uri, 'GET', status_code=requests.codes.NOT_FOUND) resp.test_odata_service_mime_type(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_SERVICE_MIME_TYPE, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( '%s request to URI %s failed with status %s' % ('GET', uri, requests.codes.NOT_FOUND), result['msg'])
def test_test_x_auth_token_header_not_tested2(self): method = 'POST' uri = self.sut.sessions_uri add_response(self.sut, uri, method, status_code=requests.codes.CREATED, headers={'X-Auth-Token': 'YXN1cmUu'}) resp.test_x_auth_token_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_X_AUTH_TOKEN, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.NOT_TESTED, result['result']) self.assertIn('The security token is not a hexadecimal string', result['msg'])
def test_test_x_auth_token_header_pass(self): method = 'POST' uri = self.sut.sessions_uri add_response(self.sut, uri, method, status_code=requests.codes.CREATED, headers={'X-Auth-Token': 'C90FDAA22168C234C4C6628B8'}) resp.test_x_auth_token_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_X_AUTH_TOKEN, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result']) self.assertIn('Test passed for header %s' % 'X-Auth-Token', result['msg'])
def test_test_allow_header_get_or_head_pass(self): uri = '/redfish/v1/' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, headers={'Allow': 'GET, HEAD, PATCH'}) resp.test_allow_header_get_or_head(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_ALLOW_GET_OR_HEAD, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result']) self.assertIn( 'Test passed for header %s: %s' % ('Allow', 'GET, HEAD, PATCH'), result['msg'])
def test_test_etag_header_not_tested(self): uri = '/redfish/v1/AccountsService/Accounts/1' method = 'GET' add_response(self.sut, uri, method, status_code=requests.codes.NOT_FOUND, res_type=ResourceType.MANAGER_ACCOUNT) resp.test_etag_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_ETAG, method, '') self.assertIsNotNone(result) self.assertEqual(Result.NOT_TESTED, result['result']) self.assertIn( 'No successful response found for %s request to %s' % (method, 'ManagerAccount'), result['msg'])
def test_test_odata_service_value_prop_fail3(self): uri = '/redfish/v1/odata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, json={'value': {}}) resp.test_odata_service_value_prop(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_SERVICE_VALUE_PROP, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The value property for the OData service ' 'document is type %s; expected list' % 'dict', result['msg'])
def test_test_odata_metadata_entity_container_pass(self): uri = '/redfish/v1/$metadata' doc = ('<Edmx><DataServices><Schema><EntityContainer/>' '</Schema></DataServices></Edmx>') add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, text=doc) resp.test_odata_metadata_entity_container(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_METADATA_ENTITY_CONTAINER, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result'])
def test_add_account_via_patch_fail1(self, mock_logging_error): payload = {'UserName': '******', 'Enabled': True} add_response(self.sut, self.account_uri3, json=payload, res_type=ResourceType.MANAGER_ACCOUNT) self.session.post.return_value.status_code = ( requests.codes.METHOD_NOT_ALLOWED) self.session.patch.return_value.status_code = requests.codes.OK user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(user) self.assertIsNone(uri) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('No empty account slot found', args[0])
def test_test_odata_metadata_entity_container_fail1(self): uri = '/redfish/v1/$metadata' add_response(self.sut, uri, 'GET', status_code=requests.codes.NOT_FOUND) resp.test_odata_metadata_entity_container(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_METADATA_ENTITY_CONTAINER, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( '%s request to URI %s failed with status %s' % ('GET', uri, requests.codes.NOT_FOUND), result['msg'])
def test_test_odata_metadata_mime_type_fail1(self): uri = '/redfish/v1/$metadata' add_response(self.sut, uri, 'GET', status_code=requests.codes.OK, headers={'Content-Type': 'text/xml'}) resp.test_odata_metadata_mime_type(self.sut) result = get_result(self.sut, Assertion.RESP_ODATA_METADATA_MIME_TYPE, 'GET', uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The MIME type for the OData metadata document is %s' % 'text/xml', result['msg'])
def test_test_x_auth_token_header_warn(self): method = 'POST' uri = self.sut.sessions_uri add_response(self.sut, uri, method, status_code=requests.codes.CREATED, headers={'X-Auth-Token': '00002000'}) resp.test_x_auth_token_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_X_AUTH_TOKEN, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.WARN, result['result']) self.assertIn( 'The security token from the %s header may not be ' 'sufficiently random' % 'X-Auth-Token', result['msg'])
def test_test_cache_control_header_pass(self): uri = '/redfish/v1/' method = 'GET' add_response(self.sut, uri, method, status_code=requests.codes.OK, headers={'Cache-Control': 'no-cache'}) resp.test_cache_control_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_CACHE_CONTROL, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result']) self.assertIn( 'Test passed for header %s: %s' % ('Cache-Control', 'no-cache'), result['msg'])
def test_test_content_type_header_fail1(self): uri = '/redfish/v1/' method = 'GET' add_response(self.sut, uri, method, status_code=requests.codes.OK, headers={}) resp.test_content_type_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_CONTENT_TYPE, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The %s header was missing from the response to the %s ' 'request to URI %s' % ('Content-Type', method, uri), result['msg'])
def test_test_allow_header_method_not_allowed_fail(self): uri = '/redfish/v1/' add_response(self.sut, uri, 'POST', status_code=requests.codes.METHOD_NOT_ALLOWED, headers={}) resp.test_allow_header_method_not_allowed(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_ALLOW_METHOD_NOT_ALLOWED, 'POST', uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The Allow header was missing from response to %s ' 'request to %s' % ('POST', uri), result['msg'])
def test_test_content_type_header_pass(self): uri = '/redfish/v1/' method = 'GET' add_response(self.sut, uri, method, status_code=requests.codes.OK, headers={'Content-Type': 'application/json'}) resp.test_content_type_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_CONTENT_TYPE, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result']) self.assertIn( 'Test passed for header %s: %s' % ('Content-Type', 'application/json'), result['msg'])
def test_test_location_header_fail1(self): method = 'POST' uri = '/redfish/v1/Foo' add_response(self.sut, uri, method, status_code=requests.codes.CREATED, headers={}) resp.test_location_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_LOCATION, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The %s header was missing from the response to the ' '%s request to URI %s' % ('Location', method, uri), result['msg'])
def test_test_x_auth_token_header_fail(self): method = 'POST' uri = self.sut.sessions_uri add_response(self.sut, uri, method, status_code=requests.codes.CREATED, headers={}) resp.test_x_auth_token_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_X_AUTH_TOKEN, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The %s header was missing from the response to the ' 'POST request to the Sessions URI' % 'X-Auth-Token', result['msg'])
def test_test_link_header_not_tested(self): uri = '/redfish/v1/' method = 'GET' add_response(self.sut, uri, method, status_code=requests.codes.NOT_FOUND) resp.test_link_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_LINK_REL_DESCRIBED_BY, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.NOT_TESTED, result['result']) self.assertIn( 'No successful response found for %s request to %s' % (method, uri), result['msg'])
def test_test_allow_header_get_or_head_fail(self): uri = '/redfish/v1/' method = 'HEAD' add_response(self.sut, uri, method, status_code=requests.codes.OK, headers={}) resp.test_allow_header_get_or_head(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_ALLOW_GET_OR_HEAD, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.FAIL, result['result']) self.assertIn( 'The %s header was missing from the response to the %s ' 'request to URI %s' % ('Allow', method, uri), result['msg'])
def test_test_odata_version_header_pass(self): method = 'GET' uri = '/redfish/v1/' add_response(self.sut, uri, method, status_code=requests.codes.OK, headers={'OData-Version': '4.0'}) resp.test_odata_version_header(self.sut) result = get_result(self.sut, Assertion.RESP_HEADERS_ODATA_VERSION, method, uri) self.assertIsNotNone(result) self.assertEqual(Result.PASS, result['result']) self.assertIn( 'Test passed for header %s: %s' % ('OData-Version', '4.0'), result['msg'])