Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Add new CI for testing webapp API #1572

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/helper/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# Copyright 2024 Fuzz Introspector Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
import os
import requests
import subprocess

PROJECTS = [
'wrong-project-name', 'htslib', 'icu', 'tinyxml2', 'leveldb',
'eigen', 'immer', 'fluent-bit', 'json-java', 'java-diff-utils'
]
APIS = [
'/api/annotated-cfg', '/api/project-summary', '/api/branch-blockers',
'/api/all-functions', '/api/all-jvm-constructors',
'/api/easy-params-far-reach', '/api/far-reach-low-cov-fuzz-keyword',
'/api/project-repository', '/api/far-reach-but-low-coverage',
'/api/all-header-files'
]
BASE_URL = 'http://localhost:8080'
EXCEPTIONS = []


def _test_server_api(url):
"""Function for calling server API and check if the return code is 2XX or 3XX
The call is considered fail if the return code is 4XX or 5XX.
"""
response = requests.get(url)

if response.status_code >= 400 or response.status_code < 200:
print(f'{url} failed with return code: {response.status_code}')
EXCEPTIONS.append(f'{url} failed with return code: {response.status_code}')


if __name__ == "__main__":
ROOT_FI = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')

code = subprocess.call([os.path.join(ROOT_FI, '.github', 'helper', 'prepare_webapp')])
if code:
EXCEPTIONS.append('Failed to prepare the webapp for testing.')

# A list of curl test to the webapp api
for project in PROJECTS:
for api in APIS:
_test_server_api(f'{BASE_URL}{api}?project={project}')
DavidKorczynski marked this conversation as resolved.
Show resolved Hide resolved

# Shutdown started webserver
print("Shutting down started webserver")
try:
requests.get('http://localhost:8080/api/shutdown')
except:
pass

if EXCEPTIONS:
raise Exception(f'Test error. Details: {EXCEPTIONS}')
45 changes: 45 additions & 0 deletions .github/helper/prepare_webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash -eux
# Copyright 2024 Fuzz Introspector Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

ROOT_FI=`git rev-parse --show-toplevel`

# Create webserver DB
echo "[+] Creating the webapp DB"
cd $ROOT_FI/tools/web-fuzzing-introspection/app/static/assets/db/
./launch_minor_oss_fuzz.sh

# Start webserver DB
echo "Shutting down server in case it's running"
curl --silent http://localhost:8080/api/shutdown || true

echo "[+] Launching FI webapp"
cd $ROOT_FI/tools/web-fuzzing-introspection/app/
FUZZ_INTROSPECTOR_LOCAL_OSS_FUZZ=$ROOT_FI/oss_fuzz_integration/oss-fuzz \
python3 ./main.py >> /dev/null &

SECONDS=5
while true
do
# Checking if exists
MSG=$(curl -v --silent 127.0.0.1:8080 2>&1 | grep "Fuzzing" | wc -l)
if [[ $MSG > 0 ]]; then
echo "Found it"
break
fi
echo "- Waiting for webapp to load. Sleeping ${SECONDS} seconds."
sleep ${SECONDS}
done
29 changes: 29 additions & 0 deletions .github/workflows/webapp-api-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: webapp-api-test

on:
pull_request:
branches:
main
paths:
- 'tools/web-fuzzing-introspection/**'
- '.github/helper/**'
- '.github/workflows/webapp-api-test.yml'
permissions: read-all
jobs:
build:
runs-on: ubuntu-latest
name: webapp-api-test
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v2.4.0
- name: Set up Python 3.8
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v3.0.0
with:
python-version: 3.8
- name: Install venv
run: sudo apt-get install python3-venv
- name: Set up venv
run: python3 -m venv tools/web-fuzzing-introspection/.venv
- name: Active venv dependencies
run: source tools/web-fuzzing-introspection/.venv/bin/activate && pip install -r tools/web-fuzzing-introspection/requirements.txt
- name: Run test
Fixed Show fixed Hide fixed

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 2: pipCommand not pinned by hash
Click Remediation section below to solve this issue
run: source tools/web-fuzzing-introspection/.venv/bin/activate && python3 .github/helper/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
################################################################################

python ./web_db_creator_from_summary.py \
--since-date=20-04-2023 \
python3 ./web_db_creator_from_summary.py \
--since-date=01-05-2024 \
--output-dir=$PWD \
--input-dir=$PWD \
--includes=must_include_small.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ leveldb
eigen
immer
fluent-bit
json-java
java-diff-utils