Example #1
0
 def test_http_requests_http_scheme(self, mock_get):
     sut = SystemUnderTest('http://127.0.0.1:8000', 'oper', 'xyzzy')
     sut.set_sessions_uri('/redfish/v1/SessionService/Sessions')
     add_response(sut,
                  '/redfish/v1/',
                  'GET',
                  requests.codes.OK,
                  request_type=RequestType.NO_AUTH)
     add_response(sut,
                  sut.sessions_uri,
                  'GET',
                  requests.codes.OK,
                  request_type=RequestType.BASIC_AUTH)
     add_response(sut,
                  sut.sessions_uri,
                  'GET',
                  requests.codes.UNAUTHORIZED,
                  request_type=RequestType.NO_AUTH)
     mock_get.return_value.status_code = requests.codes.OK
     resources.http_requests(sut)
     responses = sut.get_responses_by_method(
         'GET', request_type=RequestType.HTTP_BASIC_AUTH)
     self.assertEqual(len(responses), 1)
     responses = sut.get_responses_by_method(
         'GET', request_type=RequestType.HTTP_NO_AUTH)
     self.assertEqual(len(responses), 2)
Example #2
0
 def test_http_requests_https_scheme_exception(self, mock_get, mock_warn):
     mock_get.side_effect = ConnectionError
     mock_sut = mock.MagicMock(spec=SystemUnderTest)
     mock_sut.scheme = 'https'
     mock_sut.avoid_http_redirect = False
     resources.http_requests(mock_sut)
     args = mock_warn.call_args[0]
     self.assertIn('Caught ConnectionError while trying to trigger',
                   args[0])
Example #3
0
 def test_http_requests_https_scheme(self, mock_get):
     headers = {'OData-Version': '4.0'}
     if self.sut.scheme == 'https':
         http_rhost = 'http' + self.sut.rhost[5:]
     else:
         http_rhost = self.sut.rhost
     request = mock.Mock(spec=requests.Request)
     request.method = 'GET'
     response = mock.Mock(spec=requests.Response)
     response.status_code = requests.codes.OK
     response.request = request
     mock_get.return_value = response
     resources.http_requests(self.sut)
     mock_get.assert_any_call(http_rhost + self.sut.sessions_uri,
                              headers=headers,
                              auth=(self.sut.username, self.sut.password),
                              verify=self.sut.verify)
     responses = self.sut.get_responses_by_method(
         'GET', request_type=RequestType.HTTP_BASIC_AUTH)
     self.assertEqual(len(responses), 1)
     responses = self.sut.get_responses_by_method(
         'GET', request_type=RequestType.HTTP_NO_AUTH)
     self.assertEqual(len(responses), 2)
Example #4
0
 def test_http_requests_other_scheme(self, mock_warning):
     sut = SystemUnderTest('ftp://127.0.0.1:8000', 'oper', 'xyzzy')
     resources.http_requests(sut)
     args = mock_warning.call_args[0]
     self.assertIn('Unexpected scheme (ftp)', args[0])
Example #5
0
def main():
    parser = argparse.ArgumentParser(
        description='Validate the protocol conformance of a Redfish service')
    parser.add_argument('--version',
                        action='version',
                        version='Redfish-Protocol-Validator %s' % tool_version)
    parser.add_argument('--user',
                        '-u',
                        type=str,
                        required=True,
                        help='the username for authentication')
    parser.add_argument('--password',
                        '-p',
                        type=str,
                        required=True,
                        help='the password for authentication')
    parser.add_argument('--rhost',
                        '-r',
                        type=str,
                        required=True,
                        help='address of the Redfish service (with scheme)')
    parser.add_argument('--log-level',
                        type=str,
                        default='WARNING',
                        help='the logging level (default: WARNING)')
    parser.add_argument('--report-dir',
                        type=str,
                        default='reports',
                        help='the directory for generated report files '
                        '(default: "reports")')
    parser.add_argument('--report-type',
                        choices=['html', 'tsv', 'both'],
                        help='the type of report to generate: html, tsv, or '
                        'both (default: both)',
                        default='both')
    parser.add_argument('--avoid-http-redirect',
                        action='store_true',
                        help='avoid attempts to generate HTTP redirects for '
                        'services that do not support HTTP')
    cert_g = parser.add_mutually_exclusive_group()
    cert_g.add_argument('--no-cert-check',
                        action='store_true',
                        help='disable verification of host SSL certificates')
    cert_g.add_argument('--ca-bundle',
                        type=str,
                        help='the file or directory containing trusted CAs')
    args = parser.parse_args()

    # set logging level
    log_level = getattr(logging, args.log_level.upper())
    logging.basicConfig(level=log_level)

    # set up cert verify option
    verify = args.ca_bundle if args.ca_bundle else not args.no_cert_check
    if args.no_cert_check:
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

    # create report directory if needed
    report_dir = Path(args.report_dir)
    if not report_dir.is_dir():
        report_dir.mkdir(parents=True)

    sut = SystemUnderTest(args.rhost, args.user, args.password, verify=verify)
    sut.set_avoid_http_redirect(args.avoid_http_redirect)
    sut.login()
    resources.read_target_resources(sut, func=resources.get_default_resources)
    no_auth_session = sessions.no_auth_session(sut)
    resources.read_uris_no_auth(sut, no_auth_session)
    resources.data_modification_requests(sut)
    resources.data_modification_requests_no_auth(sut, no_auth_session)
    resources.unsupported_requests(sut)
    resources.basic_auth_requests(sut)
    resources.http_requests(sut)
    resources.bad_auth_requests(sut)
    sessions.bad_login(sut)
    perform_tests(sut)
    sut.logout()
    utils.print_summary(sut)
    current_time = datetime.now()
    print('Report output:')
    report.json_results(sut, report_dir, current_time, tool_version)
    if args.report_type in ('tsv', 'both'):
        print(report.tsv_report(sut, report_dir, current_time))
    if args.report_type in ('html', 'both'):
        print(report.html_report(sut, report_dir, current_time, tool_version))
    # exit with status 1 if any assertions failed, 0 otherwise
    sys.exit(int(sut.summary_count(Result.FAIL) > 0))