Skip to content

Commit a901206

Browse files
committed
behave: Add tests for git-obs commands, update test suite as needed
1 parent ff30efa commit a901206

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+926
-90
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ jobs:
143143
- name: "Run tests"
144144
run: |
145145
cd behave
146-
behave -Dosc=../osc-wrapper.py -Dmax_podman_containers=2
146+
behave -Dosc=../osc-wrapper.py -Dpodman_max_containers=2

behave/Containerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
FROM opensuse/leap:15.6
22

3-
RUN zypper ar --repo http://download.opensuse.org/repositories/OBS:/Server:/Unstable/15.6/OBS:Server:Unstable.repo
4-
RUN zypper -n --gpg-auto-import-keys refresh
3+
RUN zypper -n modifyrepo --disable repo-openh264 || : \
4+
&& zypper ar --repo http://download.opensuse.org/repositories/OBS:/Server:/Unstable/15.6/OBS:Server:Unstable.repo \
5+
&& zypper ar --repo http://download.opensuse.org/repositories/devel:/tools:/scm/15.6/devel:tools:scm.repo \
6+
&& zypper -n --gpg-auto-import-keys refresh
7+
58
RUN zypper -n install \
69
bash \
710
bash-completion \
811
git \
12+
gitea \
913
less \
1014
obs-api \
15+
obs-gitea-bridge \
1116
obs-server \
1217
obs-signd \
1318
obs-worker \
@@ -16,6 +21,7 @@ RUN zypper -n install \
1621
openssl \
1722
perl-XML-SAX \
1823
rpm-build \
24+
sqlite3 \
1925
systemd \
2026
vim \
2127
&& rm -rf /var/cache/zypp/*
@@ -25,6 +31,7 @@ COPY container-files/ /
2531
RUN /bin/bash /opt/setup/setup.sh \
2632
&& /bin/bash /opt/setup/initial-data.sh \
2733
&& /bin/bash /opt/setup/prebuilt-rpms.sh \
34+
&& /bin/bash /opt/setup/gitea.sh \
2835
&& rm -rf /var/log/apache2/* \
2936
&& rm -rf /srv/obs/log/* \
3037
&& rm -rf /srv/obs/service/log/* \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
WORK_PATH = /var/lib/gitea
2+
3+
[server]
4+
CERT_FILE = /etc/gitea/https/cert.pem
5+
KEY_FILE = /etc/gitea/https/key.pem
6+
STATIC_ROOT_PATH = /usr/share/gitea
7+
APP_DATA_PATH = /var/lib/gitea/data
8+
PPROF_DATA_PATH = /var/lib/gitea/data/tmp/pprof
9+
PROTOCOL = http
10+
HTTP_PORT = 3000
11+
DISABLE_SSH = false
12+
START_SSH_SERVER = true
13+
SSH_PORT = 3022
14+
LFS_START_SERVER = true
15+
16+
[lfs]
17+
PATH = /var/lib/gitea/data/lfs
18+
19+
[database]
20+
DB_TYPE = sqlite3
21+
PATH = /var/lib/gitea/data/gitea.db
22+
23+
[security]
24+
INSTALL_LOCK = true
25+
26+
[oauth2]
27+
ENABLED = false
28+
29+
[log]
30+
ROOT_PATH = /var/log/gitea
31+
MODE = console, file
32+
; Either "Trace", "Debug", "Info", "Warn", "Error" or "None", default is "Info"
33+
LEVEL = Debug
34+
35+
[service]
36+
ENABLE_BASIC_AUTHENTICATION = true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Configure /etc/gitea/conf/app.ini from environmental variables
3+
4+
[Service]
5+
Type=oneshot
6+
User=root
7+
Group=root
8+
PassEnvironment=GITEA_SERVER_HTTP_PORT
9+
PassEnvironment=GITEA_SERVER_SSH_PORT
10+
ExecStart=bash -c /usr/bin/gitea-configure-from-env
11+
12+
[Install]
13+
RequiredBy=gitea.service
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=Fix /var/lib/gitea/data by copying it back and forth to the same overlayfs layer
3+
4+
[Service]
5+
Type=oneshot
6+
User=gitea
7+
Group=gitea
8+
ExecStart=/bin/bash -c 'mv /var/lib/gitea/data /var/lib/gitea/data.backup && mkdir -p /var/lib/gitea/data && cp -a /var/lib/gitea/data.backup/* /var/lib/gitea/data/'
9+
10+
[Install]
11+
RequiredBy=gitea.service
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Configure OBS from environmental variables
3+
4+
[Service]
5+
Type=oneshot
6+
User=root
7+
Group=root
8+
PassEnvironment=OBS_PROXY_AUTH
9+
ExecStart=bash -c /usr/bin/obs-configure-from-env
10+
11+
[Install]
12+
RequiredBy=apache2.service
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<package name="test-GitPkgA" project="test:factory">
2+
<title/>
3+
<description/>
4+
<scmsync>http://localhost:3000/pool/test-GitPkgA#factory</scmsync>
5+
</package>
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
set -x
2+
set -e
3+
4+
5+
TOPDIR=$(dirname $(readlink -f "$0"))
6+
source "$TOPDIR/common.sh"
7+
8+
9+
OSC="osc -A https://localhost"
10+
11+
12+
chown gitea:gitea /etc/gitea/conf/app.ini
13+
14+
DB_PATH=/var/lib/gitea/data/gitea.db
15+
16+
# create the database
17+
su - gitea -c 'gitea migrate'
18+
19+
20+
# to generate an access token for testing, use the following Python code:
21+
# from hashlib import pbkdf2_hmac
22+
# char = b"1"
23+
# print(pbkdf2_hmac(hash_name="sha256", password=40*char, salt=10*char, iterations=10000, dklen=50).hex())
24+
25+
26+
# user #1: Admin, password=opensuse
27+
# gitea refuses to create user 'admin'; let's create 'admin1' and rename it in the database
28+
su - gitea -c 'gitea admin user create --username Admin1 --password opensuse --email [email protected] --must-change-password=false --admin'
29+
su - gitea -c "echo \"update user set lower_name='admin', name='Admin' where lower_name = 'admin1';\" | sqlite3 $DB_PATH"
30+
su - gitea -c "echo \"INSERT INTO access_token (uid, name, token_hash, token_salt, token_last_eight, scope, created_unix, updated_unix) VALUES (1, 'admin', '2da98f9cae724ae30563e3ba9663afb24af91019d04736523f1762eed291c449aebbbb749571958e1811588b33e64ae86bd7', '1111111111', '11111111', 'all', 0, 0);\" | sqlite3 $DB_PATH"
31+
export TOKEN_ADMIN='1111111111111111111111111111111111111111'
32+
33+
34+
# user #2: Alice, password=opensuse
35+
su - gitea -c 'gitea admin user create --username Alice --password opensuse --email [email protected] --must-change-password=false'
36+
#su - gitea -c "echo \"update user set must_change_password=0 where lower_name = 'alice';\" | sqlite3 $DB_PATH"
37+
su - gitea -c "echo \"INSERT INTO access_token (uid, name, token_hash, token_salt, token_last_eight, scope, created_unix, updated_unix) VALUES (2, 'alice', '5aeaf57e2c156673a566815b5a5739f9aa25bc3ac0a3c9e942f31361230e1f26983f6b2abfd009358202fc2e02c8137693ee', 'aaaaaaaaaa', 'aaaaaaaa', 'all', 0, 0);\" | sqlite3 $DB_PATH"
38+
export TOKEN_ALICE='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
39+
40+
#sqlite> update access_token set scope='read:repository,write:repository,read:user' where id in (2,3);
41+
#read:issue
42+
43+
# user #3 Bob, password=opensuse
44+
su - gitea -c 'gitea admin user create --username Bob --password opensuse --email [email protected] --must-change-password=false'
45+
#su - gitea -c "echo \"update user set must_change_password=0 where lower_name = 'bob';\" | sqlite3 $DB_PATH"
46+
su - gitea -c "echo \"INSERT INTO access_token (uid, name, token_hash, token_salt, token_last_eight, scope, created_unix, updated_unix) VALUES (3, 'bob', 'b97a745cff7dabb6a767c4e993609ef41c54b8f722f9ff88b4232430e087751d54436fec1240f056585b270f432efb02d188', 'bbbbbbbbbb', 'bbbbbbbb', 'all', 0, 0);\" | sqlite3 $DB_PATH"
47+
export TOKEN_BOB='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
48+
49+
50+
systemctl enable gitea
51+
systemctl enable gitea-configure-from-env
52+
systemctl enable gitea-fix-var-lib-gitea-data
53+
54+
55+
su - gitea -c 'gitea' 2>&1 >/dev/null &
56+
sleep 15
57+
58+
59+
function create_org {
60+
org="$1"
61+
curl \
62+
-X POST \
63+
-H "Authorization: token $TOKEN_ADMIN" \
64+
-H "Content-type: application/json" \
65+
--data "{\"username\": \"$org\"}" \
66+
"http://localhost:3000/api/v1/orgs"
67+
}
68+
69+
70+
function create_org_repo {
71+
org="$1"
72+
repo="$2"
73+
curl \
74+
-X POST \
75+
-H "Authorization: token $TOKEN_ADMIN" \
76+
-H "Content-type: application/json" \
77+
--data "{\"name\": \"$repo\", \"default_branch\": \"factory\"}" \
78+
"http://localhost:3000/api/v1/orgs/$org/repos"
79+
}
80+
81+
82+
function add_ssh_key {
83+
user="$1"
84+
token="$2"
85+
ssh_key_path="$3"
86+
87+
key="$(cat $ssh_key_path)"
88+
curl \
89+
-X POST \
90+
-H "Authorization: token $token" \
91+
-H "Content-type: application/json" \
92+
--data "{\"key\": \"$key\", \"title\": \"$(echo $key | cut -d ' ' -f 3-)\"}" \
93+
"http://localhost:3000/api/v1/user/keys"
94+
}
95+
96+
97+
create_org pool
98+
create_org_repo pool test-GitPkgA
99+
add_ssh_key admin $TOKEN_ADMIN /root/.ssh/admin.pub
100+
add_ssh_key alice $TOKEN_ALICE /root/.ssh/alice.pub
101+
add_ssh_key bob $TOKEN_BOB /root/.ssh/bob.pub
102+
103+
104+
# create test-GitPkgA package based on test-PkgA
105+
# * change the package name
106+
# * use changelog dates as commit/commiter dates for reproducibility
107+
108+
GITDIR="$(mktemp -d)"
109+
pushd "$GITDIR"
110+
111+
git init --initial-branch factory
112+
# git commiter equals to the configured user
113+
git config user.name "Geeko Packager"
114+
git config user.email "[email protected]"
115+
116+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-1.spec test-GitPkgA.spec
117+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-1.changes test-GitPkgA.changes
118+
sed 's@test-pkgA@test-GitPkgA@' -i *
119+
git add *
120+
DATE="2022-01-03 11:22:33 UTC"
121+
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Initial commit" --date "$DATE"
122+
123+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-2.spec test-GitPkgA.spec
124+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-2.changes test-GitPkgA.changes
125+
sed 's@test-pkgA@test-GitPkgA@' -i *
126+
git add *
127+
DATE="2022-01-04 11:22:33 UTC"
128+
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Version 2" --date "$DATE"
129+
130+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-3.spec test-GitPkgA.spec
131+
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-3.changes test-GitPkgA.changes
132+
sed 's@test-pkgA@test-GitPkgA@' -i *
133+
git add *
134+
DATE="2022-01-05 11:22:33 UTC"
135+
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Version 3" --date "$DATE"
136+
137+
git remote add origin http://admin:opensuse@localhost:3000/pool/test-GitPkgA.git
138+
git push --set-upstream origin factory
139+
140+
popd
141+
142+
# create test-GitPkgA package in test:factory that has scmsync set to gitea
143+
$OSC api -X PUT '/source/test:factory/test-GitPkgA/_meta' --file "$TOPDIR"/fixtures/pac/test-GitPkgA.xml

behave/container-files/opt/setup/setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ sed -i 's!^<VirtualHost \*:82>!<VirtualHost *:82 *:1082>!' /etc/apache2/vhosts.d
3232
sed -i 's!^<VirtualHost \*:443>!<VirtualHost *:443 *:1443>!' /etc/apache2/vhosts.d/obs.conf
3333
sed -i 's!^Listen 82$!Listen 82\nListen 1082\nListen 1443!' /etc/apache2/vhosts.d/obs.conf
3434

35+
# forward X-Username HTTP header to HTTP_X_USERNAME variable that is needed for OBS proxy auth
36+
sed -i 's@^\(.*SSLEngine.*\)@ # the variable is used when OBS proxy auth is on\n SetEnvIf X-Username "(.*)" HTTP_X_USERNAME=$1\n\n\1@' /etc/apache2/vhosts.d/obs.conf
37+
3538

3639
# enable apache mods
3740
APACHE_MODS="passenger rewrite proxy proxy_http xforward headers ssl socache_shmcb"
@@ -144,3 +147,5 @@ sed -i '/^BindsTo *=.*/d; s/^WantedBy *=.*/WantedBy = default.target/' /usr/lib/
144147

145148
# OBS worker
146149
# systemctl enable obsworker
150+
151+
systemctl enable obs-configure-from-env
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-----BEGIN OPENSSH PRIVATE KEY-----
2+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
3+
QyNTUxOQAAACBqN71PEkPcdLHUG+oMKpAmnDAgdcuS4V3hEyRWaVf+iQAAAJh1HuOIdR7j
4+
iAAAAAtzc2gtZWQyNTUxOQAAACBqN71PEkPcdLHUG+oMKpAmnDAgdcuS4V3hEyRWaVf+iQ
5+
AAAEAqkTwb9syNHFuOFoy/UJgZGoHHX7zSMx7X10GmhgeIBGo3vU8SQ9x0sdQb6gwqkCac
6+
MCB1y5LhXeETJFZpV/6JAAAAEGFkbWluQGdpdGVhLXRlc3QBAgMEBQ==
7+
-----END OPENSSH PRIVATE KEY-----

0 commit comments

Comments
 (0)