Skip to content

Commit 7621ef2

Browse files
usersyrosh
authored andcommitted
test(quickscope): add integration test
1 parent 8c09518 commit 7621ef2

File tree

8 files changed

+238
-3
lines changed

8 files changed

+238
-3
lines changed

.github/workflows/pull-request.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
quickscope:
16+
name: quickscope
17+
runs-on: ubuntu-latest
18+
outputs:
19+
result: ${{ steps.test.outputs.result }}
20+
steps:
21+
- name: Checkout Repo
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
submodules: true
26+
27+
- name: Build quickscope
28+
working-directory: quickscope
29+
run: |
30+
docker pull eclipse-temurin:21-alpine
31+
docker build -t quickscope .
32+
33+
- name: Run integration test
34+
id: test
35+
working-directory: quickscope
36+
run: |
37+
result=$(./integration/integration.sh | tee /dev/stderr | tail -n1)
38+
echo "result=$result" >> $GITHUB_OUTPUT
39+
40+
- name: Upload new diff
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: quickscope-new
44+
path: ./quickscope/integration/new.diff
45+
46+
- name: Upload integration diff
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: quickscope-integration
50+
path: ./quickscope/integration/integration.diff
51+
52+
comment:
53+
name: Comment integration
54+
needs: quickscope
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout Repo
58+
uses: actions/checkout@v4
59+
60+
- name: Post comment
61+
env:
62+
PR_C_REPO: ${{ github.repository }}
63+
PR_C_NUMBER: ${{ github.event.pull_request.number }}
64+
PR_C_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
PR_QS_DIFF: ${{ needs.quickscope.outputs.result }}
66+
run: .internal/ci/comment-integration.sh

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
KEYS
22
env
33
.env
4-
*.swp
4+
*.swp
5+
new.diff
6+
integration.diff

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/pentext"]
2+
path = lib/pentext
3+
url = https://github.com/radicallyopensecurity/pentext.git
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
artifacts_root="https://github.com/$PR_C_REPO/actions/runs/$GITHUB_RUN_ID"
6+
7+
artifacts_url="https://api.github.com/repos/$PR_C_REPO/actions/runs/$GITHUB_RUN_ID/artifacts"
8+
artifacts_json=$(curl -s -H "Authorization: token $PR_C_TOKEN" "$artifacts_url")
9+
10+
new_url=$(echo "$artifacts_json" | jq -r '.artifacts[] | select(.name=="quickscope-new") | .archive_download_url')
11+
integration_url=$(echo "$artifacts_json" | jq -r '.artifacts[] | select(.name=="quickscope-integration") | .archive_download_url')
12+
13+
if [ "$PR_QS_DIFF" = "true" ]; then
14+
body="# Quickscope
15+
16+
Found diff. Please check the diffs:
17+
18+
- [current.diff](https://github.com/$PR_C_REPO/blob/${GITHUB_SHA}/quickscope/integration/current.diff)
19+
- [new.diff]($new_url)
20+
- [integration.diff]($integration_url)"
21+
else
22+
body="# Quickscope
23+
24+
No diff found."
25+
fi
26+
27+
curl -s -H "Authorization: token $PR_C_TOKEN" \
28+
-H "Content-Type: application/json" \
29+
-d "$(jq -nc --arg body "$body" '{body: $body}')" \
30+
"https://api.github.com/repos/$PR_C_REPO/issues/$PR_C_NUMBER/comments"

lib/pentext

Submodule pentext added at 937354f
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
diff -ruN /home/user/git/pentext-docker/quickscope/integration/tmp/source/test-remote.git/source/offerte.xml /home/user/git/pentext-docker/quickscope/integration/tmp/remote/test-remote.git/source/offerte.xml
2+
--- /home/user/git/pentext-docker/quickscope/integration/tmp/source/test-remote.git/source/offerte.xml 1970-01-01 01:00:00.000000000 +0100
3+
+++ /home/user/git/pentext-docker/quickscope/integration/tmp/remote/test-remote.git/source/offerte.xml 2025-09-25 00:48:52.129967308 +0200
4+
@@ -0,0 +1,57 @@
5+
+<?xml version="1.0" encoding="UTF-8"?>
6+
+<offerte xmlns:xi="http://www.w3.org/2001/XInclude"
7+
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
+ xsi:noNamespaceSchemaLocation="../dtd/offerte.xsd"
9+
+ xml:lang="en"><!--document meta information; to be filled in by the offerte writer-->
10+
+ <meta>
11+
+ <title>Quote</title>
12+
+ <offered_service_long>penetration testing services</offered_service_long>
13+
+ <!--if there is a shorter way of saying the same thing, you can type it here (it makes for more dynamic offerte text). If not, just repeat the long name.-->
14+
+ <offered_service_short>penetration test</offered_service_short>
15+
+ <xi:include href="snippets/company_info.xml"/>
16+
+ <targets><!--one target element per target-->
17+
+ <target/>
18+
+ <target/>
19+
+ </targets>
20+
+ <permission_parties>
21+
+ <xi:include href="client_info.xml"/>
22+
+ </permission_parties>
23+
+ <activityinfo>
24+
+ <persondays>0</persondays>
25+
+ <!--duration of pentest, in persondays-->
26+
+ <planning>
27+
+ <start>YYYY-MM-DD</start>
28+
+ <end>TBD</end>
29+
+ </planning>
30+
+ <!--start and end dates, in ISO format: 'YYYY-MM-DD' - or 'TBD'-->
31+
+ <report_due>TBD</report_due>
32+
+ <!--date or date range in text, e.g. May 18th until May 25th, 2024-->
33+
+ <nature>time-boxed</nature>
34+
+ <type>crystal-box</type>
35+
+ <!--please choose one of the following: black-box, grey-box, crystal-box-->
36+
+ <fee denomination="eur">0</fee>
37+
+ <!--(eur|usd|gbp)-->
38+
+ <xi:include href="servicebreakdown.xml"/>
39+
+ </activityinfo>
40+
+ <version_history><!--needed for date on frontpage and in signature boxes; it is possible to add a new <version> after each review; in that case, make sure to update the date/time-->
41+
+ <version number="auto" date="2025-09-24T10:00:00"><!--actual date-time here; you can leave the number attribute alone-->
42+
+ <v_author>ROS Writer</v_author>
43+
+ <!--name of the author here; for internal use only-->
44+
+ <v_description>Initial draft</v_description>
45+
+ <!--for internal use only-->
46+
+ </version>
47+
+ </version_history>
48+
+ </meta>
49+
+ <xi:include href="snippets/offerte/en/introandscope.xml"/>
50+
+ <xi:include href="snippets/offerte/en/projectoverview.xml"/>
51+
+ <xi:include href="snippets/offerte/en/prerequisites.xml"/>
52+
+ <xi:include href="snippets/offerte/en/disclaimer.xml"/>
53+
+ <xi:include href="snippets/offerte/en/methodology.xml"/>
54+
+ <xi:include href="snippets/offerte/en/additional-code-audit_methodology.xml"/>
55+
+ <xi:include href="snippets/offerte/en/teamandreporting.xml"/>
56+
+ <xi:include href="snippets/offerte/en/planningandpayment.xml"/>
57+
+ <xi:include href="snippets/offerte/en/aboutus.xml"/>
58+
+ <xi:include href="snippets/offerte/en/conditions.xml"/>
59+
+ <xi:include href="snippets/offerte/en/generaltermsandconditions.xml"/>
60+
+ <xi:include href="snippets/offerte/en/waiver.xml"/>
61+
+</offerte>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_USER=CI
5+
GIT_PASS=dummy
6+
REPO_NAME=test-remote.git
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
10+
TMPDIR="$SCRIPT_DIR/tmp"
11+
REMOTE="$TMPDIR/remote"
12+
SOURCE="$TMPDIR/source"
13+
14+
echo "* Preparing tmp dirs"
15+
rm -rf "$TMPDIR"
16+
mkdir -p "$REMOTE" "$SOURCE"
17+
18+
echo "* Cloning test repo into remote"
19+
git -C "$SCRIPT_DIR/../../lib/pentext" \
20+
clone . "$REMOTE/$REPO_NAME"
21+
22+
echo "* Starting git-http-backend container"
23+
docker rm -f git-http-backend 2>/dev/null || true
24+
docker run -d --name git-http-backend \
25+
-u $(id -u):$(id -g) \
26+
-v "$REMOTE":/var/gerrit/git \
27+
k8sgerrit/apache-git-http-backend:v0.1-791-gda829e467a-3.12.2-965-g6ae725f802
28+
29+
docker exec -u 0 git-http-backend mkdir -p /var/apache/credentials
30+
docker exec -u 0 git-http-backend htpasswd -b -B -c /var/apache/credentials/.htpasswd "$GIT_USER" "$GIT_PASS"
31+
32+
echo "* Running quickscope"
33+
docker run --rm --name quickscope \
34+
--link git-http-backend \
35+
-e GIT_SSL_NO_VERIFY=true \
36+
-e SERVER_PROTOCOL=http \
37+
-e CI_PROJECT_DIR=/usr/local/src/repo \
38+
-e CI_SERVER_HOST=git-http-backend:8080 \
39+
-e CI_PROJECT_PATH=$REPO_NAME \
40+
-e CI_DEFAULT_BRANCH=main \
41+
-e PROJECT_ACCESS_TOKEN=$GIT_PASS \
42+
-v "$REMOTE/$REPO_NAME":/usr/local/src/repo \
43+
--entrypoint ash \
44+
quickscope:latest \
45+
-c "git config --global --add safe.directory /usr/local/src/repo && exec /scripts/quickscope2off.sh"
46+
47+
echo "* Preparing for diff"
48+
git -C "$SCRIPT_DIR/../../lib/pentext" \
49+
clone . "$SOURCE/$REPO_NAME"
50+
docker exec -u 0 git-http-backend rm -rf "/var/gerrit/git/$REPO_NAME/.git"
51+
rm -rf "$SOURCE/$REPO_NAME/.git"
52+
53+
echo "* Creating new diff"
54+
diff -ruN "$SOURCE/$REPO_NAME" "$REMOTE/$REPO_NAME" > "$SCRIPT_DIR/new.diff" || true
55+
56+
echo "* Diffing with current"
57+
diff -u \
58+
<(sed -E 's/^(---|\+\+\+) ([^[:space:]]+).*/\1 \2/' "$SCRIPT_DIR/current.diff") \
59+
<(sed -E 's/^(---|\+\+\+) ([^[:space:]]+).*/\1 \2/' "$SCRIPT_DIR/new.diff") \
60+
> "$SCRIPT_DIR/integration.diff" || true
61+
62+
echo "* Cleaning up"
63+
docker rm -f git-http-backend || true
64+
rm -rf "$TMPDIR"
65+
66+
echo "* Found diff?"
67+
if [ -s "$SCRIPT_DIR/integration.diff" ]; then
68+
echo "true"
69+
else
70+
echo "false"
71+
fi

quickscope/scripts/quickscope2off.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
23
set -e
34
cd "$CI_PROJECT_DIR"
45

@@ -11,6 +12,6 @@ git commit -m "convert pentext quickscope to offerte"
1112
git remote -v
1213

1314
git remote rm origin
14-
git remote add origin "https://CI:${PROJECT_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}"
15+
git remote add origin "${SERVER_PROTOCOL:-https}://CI:${PROJECT_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}"
1516

1617
git push origin HEAD:${CI_DEFAULT_BRANCH}

0 commit comments

Comments
 (0)