Skip to content

Commit ad8331e

Browse files
authored
Adjust tests to all editions and versions (#1995)
* Adjust tests to CB * Fixes #1996 * Add parameter format v1 or v2 to generate external issues report * Fix issue type (always vuln) * Adjust tests to 9.9 * Automatically detect 9.9 and set external issues format and scanner token param * Fix search by severity problem when severities are different between MQR and Std * Fix problem on filters on type of issues * Move env is separate file * unify scripts * rename scan.sh * Added env.sh * Remove useless file * Add determination of URL is 9.x * Make linters to run configurable * Fix python coverage and test paths that have to be relative * Use class to update web hooks * Quality pass * Add Web hook create delete test * Add one more test on refresh() after delete * Update with test data * Quality pass * Quality pass
1 parent d281bda commit ad8331e

27 files changed

+417
-579
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
"sonarlint.focusOnNewCode": true,
77
"pylint.args": [
88
"[\"--rcfile=conf/pylintrc\"]"
9-
]
9+
],
10+
"python.testing.pytestArgs": [
11+
"test"
12+
],
13+
"python.testing.unittestEnabled": false,
14+
"python.testing.pytestEnabled": true
1015
}

conf/build.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717
#
1818

19-
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
20-
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
21-
SONAR_TOOLS_RELEASE="${ROOTDIR}/sonar/version.py"
19+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
20+
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2221

2322
build_docs=0
2423
build_docker=0
2524

25+
. "${CONF_DIR}/env.sh"
26+
2627
while [[ $# -ne 0 ]]; do
2728
case "${1}" in
2829
docs|doc)
@@ -40,7 +41,7 @@ done
4041
echo "======= FORMATTING CODE ========="
4142
ruff format
4243
echo "======= BUILDING PACKAGE ========="
43-
rm -rf "${ROOTDIR}/build/lib/sonar" "${ROOTDIR}/build/lib/cli" "${ROOTDIR}"/build/scripts*/sonar-tools "${ROOTDIR}"/dist/sonar_tools*
44+
rm -rf "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}"/build/scripts*/sonar-tools "${ROOT_DIR}"/dist/sonar_tools*
4445
# python -m build
4546
poetry build
4647

@@ -52,6 +53,5 @@ fi
5253

5354
if [[ "${build_docker}" = "1" ]]; then
5455
echo "======= BUILDING DOCKER IMAGE WITH SNAPSHOT ========="
55-
version=$(grep PACKAGE_VERSION "${SONAR_TOOLS_RELEASE}" | cut -d "=" -f 2 | cut -d '"' -f 2)
56-
docker build -t "olivierkorach/sonar-tools:${version}-snapshot" -t olivierkorach/sonar-tools:latest -f "${CONFDIR}/snapshot.Dockerfile" "${ROOTDIR}" --load
56+
docker build -t "olivierkorach/sonar-tools:${VERSION}-snapshot" -t olivierkorach/sonar-tools:latest -f "${CONF_DIR}/snapshot.Dockerfile" "${ROOT_DIR}" --load
5757
fi

conf/build_tests.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
#
2121

22-
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
22+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
2323

24-
cd "${ROOTDIR}/test/unit" || exit 1
24+
cd "${ROOT_DIR}/test/unit" || exit 1
2525

2626
export GEN_LOC=test/gen
2727

@@ -31,22 +31,22 @@ echo "Generating edition / version specific tests"
3131
for target in lts latest cb 9 9-ce common
3232
do
3333
echo "Generating tests for ${target}"
34-
rm -rf "${ROOTDIR:?}/${GEN_LOC:?}/${target}"
35-
mkdir -p "${ROOTDIR:?}/${GEN_LOC:?}/${target}" 2>/dev/null
34+
rm -rf "${ROOT_DIR:?}/${GEN_LOC:?}/${target}"
35+
mkdir -p "${ROOT_DIR:?}/${GEN_LOC:?}/${target}" 2>/dev/null
3636
if [[ "${target}" = "common" ]]; then
3737
b=$(basename "${f}" .py)
38-
cp conftest.py utilities.py credentials.py "${ROOTDIR}/${GEN_LOC}/${target}"
39-
cp test_common*.py "${ROOTDIR}/${GEN_LOC}/${target}"
38+
cp conftest.py utilities.py credentials.py "${ROOT_DIR}/${GEN_LOC}/${target}"
39+
cp test_common*.py "${ROOT_DIR}/${GEN_LOC}/${target}"
4040
else
4141
for f in *.py
4242
do
4343
b=$(basename "${f}" .py)
44-
cp "${f}" "${ROOTDIR}/${GEN_LOC}/${target}/${b}_${target}.py"
44+
cp "${f}" "${ROOT_DIR}/${GEN_LOC}/${target}/${b}_${target}.py"
4545
done
46-
cp "credentials-${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/credentials.py"
47-
mv "${ROOTDIR}/${GEN_LOC}/${target}/conftest_${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/conftest.py"
48-
mv "${ROOTDIR}/${GEN_LOC}/${target}/utilities_${target}.py" "${ROOTDIR}/${GEN_LOC}/${target}/utilities.py"
49-
rm "${ROOTDIR}/${GEN_LOC}/${target}/"test_common*.py
46+
cp "credentials-${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/credentials.py"
47+
mv "${ROOT_DIR}/${GEN_LOC}/${target}/conftest_${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/conftest.py"
48+
mv "${ROOT_DIR}/${GEN_LOC}/${target}/utilities_${target}.py" "${ROOT_DIR}/${GEN_LOC}/${target}/utilities.py"
49+
rm "${ROOT_DIR}/${GEN_LOC}/${target}/"test_common*.py
5050
fi
5151
done
5252

conf/deploy.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
#
2121

22-
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
23-
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
23+
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2424

2525
deps=0
26-
"${CONFDIR}"/build.sh "$@"
26+
"${CONF_DIR}"/build.sh "$@"
2727

2828
while [[ $# -ne 0 ]]; do
2929
case "${1}" in
@@ -42,4 +42,4 @@ if [[ "${deps}" = "1" ]]; then
4242
else
4343
pipopts="--no-deps"
4444
fi
45-
pip install "${pipopts}" --force-reinstall "${ROOTDIR}"/dist/sonar_tools-*-py3-*.whl
45+
pip install "${pipopts}" --force-reinstall "${ROOT_DIR}"/dist/sonar_tools-*-py3-*.whl

conf/env.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
#
3+
# sonar-tools
4+
# Copyright (C) 2025 Olivier Korach
5+
# mailto:olivier.korach AT gmail DOT com
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 3 of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
22+
VERSION=$(grep PACKAGE_VERSION "${ROOT_DIR}/sonar/version.py" | cut -d "=" -f 2 | cut -d '"' -f 2)
23+
BUILD_DIR="${ROOT_DIR}/build"
24+
25+
PYLINT_REPORT="${BUILD_DIR}/pylint-report.out"
26+
# banditReport="${BUILD_DIR}/bandit-report.json"
27+
FLAKE8_REPORT="${BUILD_DIR}/flake8-report.out"
28+
SHELLCHECK_REPORT="${BUILD_DIR}/external-issues-shellcheck.json"
29+
TRIVY_REPORT="${BUILD_DIR}/external-issues-trivy.json"
30+
RUFF_REPORT="${BUILD_DIR}/external-issues-ruff.json"

conf/release.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU Lesser General Public
66
# License as published by the Free Software Foundation; either
7-
# version 3 of the License, or (at your option) any later version.
7+
# VERSION 3 of the License, or (at your option) any later VERSION.
88
#
99
# This program is distributed in the hope that it will be useful,
1010
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,40 +16,39 @@
1616
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717
#
1818

19-
ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
20-
CONFDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
19+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
20+
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2121

22-
"${CONFDIR}"/build.sh
22+
. "${CONF_DIR}"/env.sh
2323

24-
SONAR_TOOLS_RELEASE="${ROOTDIR}/sonar/version.py"
25-
DOCKERFILE_RELEASE="${CONFDIR}/release.Dockerfile"
24+
"${CONF_DIR}"/build.sh
2625

27-
version=$(grep PACKAGE_VERSION "${SONAR_TOOLS_RELEASE}" | cut -d "=" -f 2 | cut -d '"' -f 2)
26+
DOCKERFILE_RELEASE="${CONF_DIR}/release.Dockerfile"
2827

29-
docker_version=$(grep 'pip install sonar-tools==' "${DOCKERFILE_RELEASE}" | sed -E 's/.*sonar-tools==([0-9\.]+).*/\1/')
28+
docker_VERSION=$(grep 'pip install sonar-tools==' "${DOCKERFILE_RELEASE}" | sed -E 's/.*sonar-tools==([0-9\.]+).*/\1/')
3029

31-
if [[ "${version}" != "${docker_version}" ]]; then
32-
echo "Docker version and pypi version are different (${docker_version} vs ${version}), release aborted"
30+
if [[ "${VERSION}" != "${docker_VERSION}" ]]; then
31+
echo "Docker VERSION and pypi VERSION are different (${docker_VERSION} vs ${VERSION}), release aborted"
3332
exit 1
3433
fi
3534

3635
echo "Confirm release [y/n] ?"
3736
read -r confirm
3837
if [[ "${confirm}" = "y" ]]; then
39-
version=$(grep PACKAGE_VERSION "${ROOTDIR}"/sonar/version.py | cut -d "=" -f 2 | sed -e "s/[\'\" ]//g" -e "s/^ +//" -e "s/ +$//")
38+
VERSION=$(grep PACKAGE_VERSION "${ROOT_DIR}"/sonar/VERSION.py | cut -d "=" -f 2 | sed -e "s/[\'\" ]//g" -e "s/^ +//" -e "s/ +$//")
4039

4140
echo "Releasing on pypi.org"
42-
python3 -m twine upload "${ROOTDIR}/dist/sonar_tools-${version}-py3-none-any.whl"
41+
python3 -m twine upload "${ROOT_DIR}/dist/sonar_tools-${VERSION}-py3-none-any.whl"
4342
echo -n "Waiting pypi release to be effective"
44-
while [[ "$(get_pypi_latest_version sonar-tools)" != "${version}" ]]; do
43+
while [[ "$(get_pypi_latest_VERSION sonar-tools)" != "${VERSION}" ]]; do
4544
sleep 10
4645
echo -n "."
4746
done
4847
echo " done"
4948
echo "Releasing on dockerhub"
50-
docker buildx build --push --platform linux/amd64,linux/arm64 -t "olivierkorach/sonar-tools:${version}" -t olivierkorach/sonar-tools:latest -f "${CONFDIR}/release.Dockerfile" "${ROOTDIR}"
51-
cd "${ROOTDIR}" && docker pushrm olivierkorach/sonar-tools
49+
docker buildx build --push --platform linux/amd64,linux/arm64 -t "olivierkorach/sonar-tools:${VERSION}" -t olivierkorach/sonar-tools:latest -f "${CONF_DIR}/release.Dockerfile" "${ROOT_DIR}"
50+
cd "${ROOT_DIR}" && docker pushrm olivierkorach/sonar-tools
5251

5352
echo "Running scan"
54-
"${CONFDIR}/scan.sh" -test
53+
"${CONF_DIR}/scan.sh" -test
5554
fi

conf/ruff2sonar.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
def main() -> None:
3434
"""Main script entry point"""
35+
v1 = len(sys.argv) > 1 and sys.argv[1] == "v1"
3536
rules_dict = {}
3637
issue_list = []
3738
lines = sys.stdin.read().splitlines()
@@ -65,6 +66,10 @@ def main() -> None:
6566
"textRange": issue_range,
6667
},
6768
}
69+
if v1:
70+
sonar_issue["engineId"] = TOOLNAME
71+
sonar_issue["severity"] = "MAJOR"
72+
sonar_issue["type"] = "CODE_SMELL"
6873
rules_dict[f"{TOOLNAME}:{rule_id}"] = {
6974
"id": f"{TOOLNAME}:{rule_id}",
7075
"name": f"{TOOLNAME}:{rule_id}",
@@ -89,9 +94,12 @@ def main() -> None:
8994
end_line = int(m.group(1))
9095
i += 1
9196

92-
if len(issue_list) > 0:
93-
external_issues = {"rules": list(rules_dict.values()), "issues": issue_list}
94-
print(json.dumps(external_issues, indent=3, separators=(",", ": ")))
97+
if len(issue_list) == 0:
98+
return
99+
external_issues = {"rules": list(rules_dict.values()), "issues": issue_list}
100+
if v1:
101+
external_issues.pop("rules")
102+
print(json.dumps(external_issues, indent=3, separators=(",", ": ")))
95103

96104

97105
if __name__ == "__main__":

conf/run_all.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
#
3+
# sonar-tools
4+
# Copyright (C) 2019-2025 Olivier Korach
5+
# mailto:olivier.korach AT gmail DOT com
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 3 of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
22+
# ME="$( basename "${BASH_SOURCE[0]}" )"
23+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
24+
CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
25+
26+
. "${CONF_DIR}/env.sh"
27+
28+
dolint="true"
29+
dotest="false"
30+
scanOpts=()
31+
32+
while [[ $# -ne 0 ]]
33+
do
34+
case "${1}" in
35+
-nolint)
36+
dolint="false"
37+
;;
38+
-test)
39+
dotest="true"
40+
;;
41+
-9)
42+
external_format="v1"
43+
;;
44+
-local)
45+
localbuild="true"
46+
;;
47+
*)
48+
scanOpts=("${scanOpts[@]}" "${1}")
49+
;;
50+
esac
51+
shift
52+
done
53+
54+
if [[ "${dolint}" != "false" ]]; then
55+
"${CONF_DIR}"/run_linters.sh "${external_format}" "${localbuild}"
56+
fi
57+
58+
if [[ "${dotest}" = "true" ]]; then
59+
"${CONF_DIR}"/run_tests.sh
60+
fi
61+
62+
"${CONF_DIR}"/run_scanner.sh "${scanOpts[@]}"

0 commit comments

Comments
 (0)