Skip to content

Commit

Permalink
travis ci investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
KissPeter committed Nov 17, 2019
1 parent 12a51d0 commit 1b939c4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[![Join the chat at https://gitter.im/API-Fuzzer/Lobby](https://badges.gitter.im/API-Fuzzer/Lobby.svg)](https://gitter.im/API-Fuzzer/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/eab6434d9bd742e3880d8f589a9cc0a6)](https://www.codacy.com/app/KissPeter/APIFuzzer?utm_source=github.com&utm_medium=referral&utm_content=KissPeter/APIFuzzer&utm_campaign=badger)
[![Maintainability](https://api.codeclimate.com/v1/badges/bfc9bda00deb5002b665/maintainability)](https://codeclimate.com/github/KissPeter/APIFuzzer/maintainability)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/KissPeter/APIFuzzer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/KissPeter/APIFuzzer/?branch=master)
[![Build Status](https://travis-ci.org/KissPeter/APIFuzzer.svg?branch=master)](https://travis-ci.org/KissPeter/APIFuzzer)
[![Maintainability](https://api.codeclimate.com/v1/badges/bfc9bda00deb5002b665/maintainability)](https://codeclimate.com/github/KissPeter/APIFuzzer/maintainability)
[![Documentation Status](https://readthedocs.org/projects/apifuzzer/badge/?version=latest)](https://apifuzzer.readthedocs.io/)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/16708/badge.svg)](https://scan.coverity.com/projects/kisspeter-apifuzzer)

# APIFuzzer — HTTP API Testing Framework

Expand Down Expand Up @@ -74,6 +73,23 @@ $ python3 fuzzer.py -s test/test_swagger_definition.json -u http://127.0.0.1:500
Check the reports:
$ ls -1 /tmp/reports/
Report example:
$ json_pp < /tmp/reports/79_1573993485.5391517.json
{
"response" : "Test application exception: invalid literal for int() with base 10: '0\\x00\\x10'",
"sub_reports" : [],
"parsed_status_code" : 500,
"state" : "COMPLETED",
"test_number" : 79,
"request_body" : null,
"reason" : "failed",
"name" : "target",
"request_url" : "http://127.0.0.1:5000/exception/0\u0000\u0010",
"request_method" : "GET",
"status" : "failed",
"request_headers" : "{\"User-Agent\": \"APIFuzzer\", \"Accept-Encoding\": \"gzip, deflate\", \"Accept\": \"*/*\", \"Connection\": \"keep-alive\"}"
}
```

[API Blueprint]: https://apiblueprint.org/
Expand Down
7 changes: 6 additions & 1 deletion apifuzzer/fuzzer_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def compile_headers(self, fuzz_header=None):
used at the reques
:type fuzz_header: list, dict, None
"""
_header = dict()
_header = requests.utils.default_headers()
_header.update(
{
'User-Agent': 'APIFuzzer',
}
)
if isinstance(fuzz_header, dict):
_header = fuzz_header
if isinstance(self.auth_headers, list):
Expand Down
14 changes: 6 additions & 8 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import json
import os
import tempfile
from subprocess import Popen

import pytest
import requests

from fuzzer import Fuzzer
from test.test_utils import get_test_server_pid
from test.test_utils import get_test_server_pid, stop_test_server


class TestClass(object):
Expand All @@ -21,8 +22,8 @@ def setup_class(cls):
cls.report_files = list()
cls.test_app_url = "http://127.0.0.1:5000/"
print('Setup_class with report dir: {}'.format(cls.report_dir))
if not get_test_server_pid():
os.system("python3 ./test_application.py 2>&1 | logger -t $0 &")
if len(get_test_server_pid("Setup")) < 1:
Popen(["python3", "./test_application.py", "2>&1", "|", "logger -t $0"])
with open('./test_swagger_definition.json', 'r') as f:
cls.swagger = json.loads(f.read())

Expand All @@ -33,17 +34,14 @@ def teardown_method(self, method):
"""
print('Removing {} report files...'.format(len(self.report_files)))
for f in self.report_files:
pass
# os.remove('{}/{}'.format(self.report_dir, f))
os.remove('{}/{}'.format(self.report_dir, f))

@classmethod
def teardown_class(cls):
"""
Stops the test application at the end of the test run
"""
pid = get_test_server_pid()
if pid:
os.kill(pid, 9)
stop_test_server()

def query_last_call(self):
"""
Expand Down
18 changes: 10 additions & 8 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import psutil


def get_test_server_pid():
_return = None
def get_test_server_pid(call=None):
_return = list()
for proc in psutil.net_connections('tcp4'):
if proc.laddr.port == 5000:
_return = proc.pid
print('Found process: {}'.format(proc))
break
print('No process found which listens on port 5000')
if proc.laddr.port == 5000 and proc.pid:
_return.append(proc.pid)
print('{} - found process: {}'.format(call, proc.pid))
if len(_return) < 1:
print('{} - no process found which listens on port 5000'.format(call))
return _return


def stop_test_server():
os.kill(get_test_server_pid(), 9)
for pid in get_test_server_pid("Stop"):
if pid:
os.kill(pid, 9)

0 comments on commit 1b939c4

Please sign in to comment.