-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
behave: Add tests for osc-git commands, update test suite as needed
- Loading branch information
Showing
43 changed files
with
864 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
WORK_PATH = /var/lib/gitea | ||
|
||
[server] | ||
CERT_FILE = /etc/gitea/https/cert.pem | ||
KEY_FILE = /etc/gitea/https/key.pem | ||
STATIC_ROOT_PATH = /usr/share/gitea | ||
APP_DATA_PATH = /var/lib/gitea/data | ||
PPROF_DATA_PATH = /var/lib/gitea/data/tmp/pprof | ||
PROTOCOL = http | ||
HTTP_PORT = 3000 | ||
DISABLE_SSH = false | ||
START_SSH_SERVER = true | ||
SSH_PORT = 3022 | ||
LFS_START_SERVER = true | ||
|
||
[lfs] | ||
PATH = /var/lib/gitea/data/lfs | ||
|
||
[database] | ||
DB_TYPE = sqlite3 | ||
PATH = /var/lib/gitea/data/gitea.db | ||
|
||
[security] | ||
INSTALL_LOCK = true | ||
|
||
[oauth2] | ||
ENABLED = false | ||
|
||
[log] | ||
ROOT_PATH = /var/log/gitea | ||
MODE = console, file | ||
; Either "Trace", "Debug", "Info", "Warn", "Error" or "None", default is "Info" | ||
LEVEL = Debug | ||
|
||
[service] | ||
ENABLE_BASIC_AUTHENTICATION = true |
13 changes: 13 additions & 0 deletions
13
behave/container-files/etc/systemd/system/gitea-configure-from-env.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Configure /etc/gitea/conf/app.ini from environmental variables | ||
|
||
[Service] | ||
Type=oneshot | ||
User=root | ||
Group=root | ||
PassEnvironment=GITEA_SERVER_HTTP_PORT | ||
PassEnvironment=GITEA_SERVER_SSH_PORT | ||
ExecStart=bash -c /usr/bin/gitea-configure-from-env | ||
|
||
[Install] | ||
RequiredBy=gitea.service |
11 changes: 11 additions & 0 deletions
11
behave/container-files/etc/systemd/system/gitea-fix-var-lib-gitea-data.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Fix /var/lib/gitea/data by copying it back and forth to the same overlayfs layer | ||
|
||
[Service] | ||
Type=oneshot | ||
User=gitea | ||
Group=gitea | ||
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/' | ||
|
||
[Install] | ||
RequiredBy=gitea.service |
12 changes: 12 additions & 0 deletions
12
behave/container-files/etc/systemd/system/obs-configure-from-env.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Configure OBS from environmental variables | ||
|
||
[Service] | ||
Type=oneshot | ||
User=root | ||
Group=root | ||
PassEnvironment=OBS_PROXY_AUTH | ||
ExecStart=bash -c /usr/bin/obs-configure-from-env | ||
|
||
[Install] | ||
RequiredBy=apache2.service |
5 changes: 5 additions & 0 deletions
5
behave/container-files/opt/setup/fixtures/pac/test-GitPkgA.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<package name="test-GitPkgA" project="test:factory"> | ||
<title/> | ||
<description/> | ||
<scmsync>http://localhost:3000/pool/test-GitPkgA#factory</scmsync> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
set -x | ||
set -e | ||
|
||
|
||
TOPDIR=$(dirname $(readlink -f "$0")) | ||
source "$TOPDIR/common.sh" | ||
|
||
|
||
OSC="osc -A https://localhost" | ||
|
||
|
||
chown gitea:gitea /etc/gitea/conf/app.ini | ||
|
||
DB_PATH=/var/lib/gitea/data/gitea.db | ||
|
||
# create the database | ||
su - gitea -c 'gitea migrate' | ||
|
||
|
||
# to generate an access token for testing, use the following Python code: | ||
# from hashlib import pbkdf2_hmac | ||
# char = b"1" | ||
# print(pbkdf2_hmac(hash_name="sha256", password=40*char, salt=10*char, iterations=10000, dklen=50).hex()) | ||
|
||
|
||
# user #1: Admin, password=opensuse | ||
# gitea refuses to create user 'admin'; let's create 'admin1' and rename it in the database | ||
su - gitea -c 'gitea admin user create --username Admin1 --password opensuse --email [email protected] --must-change-password=false --admin' | ||
su - gitea -c "echo \"update user set lower_name='admin', name='Admin' where lower_name = 'admin1';\" | sqlite3 $DB_PATH" | ||
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" | ||
export TOKEN_ADMIN='1111111111111111111111111111111111111111' | ||
|
||
|
||
# user #2: Alice, password=opensuse | ||
su - gitea -c 'gitea admin user create --username Alice --password opensuse --email [email protected] --must-change-password=false' | ||
#su - gitea -c "echo \"update user set must_change_password=0 where lower_name = 'alice';\" | sqlite3 $DB_PATH" | ||
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" | ||
export TOKEN_ALICE='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' | ||
|
||
#sqlite> update access_token set scope='read:repository,write:repository,read:user' where id in (2,3); | ||
#read:issue | ||
|
||
# user #3 Bob, password=opensuse | ||
su - gitea -c 'gitea admin user create --username Bob --password opensuse --email [email protected] --must-change-password=false' | ||
#su - gitea -c "echo \"update user set must_change_password=0 where lower_name = 'bob';\" | sqlite3 $DB_PATH" | ||
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" | ||
export TOKEN_BOB='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' | ||
|
||
|
||
systemctl enable gitea | ||
systemctl enable gitea-configure-from-env | ||
systemctl enable gitea-fix-var-lib-gitea-data | ||
|
||
|
||
su - gitea -c 'gitea' 2>&1 >/dev/null & | ||
sleep 15 | ||
|
||
|
||
function create_org { | ||
org="$1" | ||
curl \ | ||
-X POST \ | ||
-H "Authorization: token $TOKEN_ADMIN" \ | ||
-H "Content-type: application/json" \ | ||
--data "{\"username\": \"$org\"}" \ | ||
"http://localhost:3000/api/v1/orgs" | ||
} | ||
|
||
|
||
function create_org_repo { | ||
org="$1" | ||
repo="$2" | ||
curl \ | ||
-X POST \ | ||
-H "Authorization: token $TOKEN_ADMIN" \ | ||
-H "Content-type: application/json" \ | ||
--data "{\"name\": \"$repo\", \"default_branch\": \"factory\"}" \ | ||
"http://localhost:3000/api/v1/orgs/$org/repos" | ||
} | ||
|
||
|
||
function add_ssh_key { | ||
user="$1" | ||
token="$2" | ||
ssh_key_path="$3" | ||
|
||
key="$(cat $ssh_key_path)" | ||
curl \ | ||
-X POST \ | ||
-H "Authorization: token $token" \ | ||
-H "Content-type: application/json" \ | ||
--data "{\"key\": \"$key\", \"title\": \"$(echo $key | cut -d ' ' -f 3-)\"}" \ | ||
"http://localhost:3000/api/v1/user/keys" | ||
} | ||
|
||
|
||
create_org pool | ||
create_org_repo pool test-GitPkgA | ||
add_ssh_key admin $TOKEN_ADMIN /root/.ssh/admin.pub | ||
add_ssh_key alice $TOKEN_ALICE /root/.ssh/alice.pub | ||
add_ssh_key bob $TOKEN_BOB /root/.ssh/bob.pub | ||
|
||
|
||
# create test-GitPkgA package based on test-PkgA | ||
# * change the package name | ||
# * use changelog dates as commit/commiter dates for reproducibility | ||
|
||
GITDIR="$(mktemp -d)" | ||
pushd "$GITDIR" | ||
|
||
git init --initial-branch factory | ||
# git commiter equals to the configured user | ||
git config user.name "Geeko Packager" | ||
git config user.email "[email protected]" | ||
|
||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-1.spec test-GitPkgA.spec | ||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-1.changes test-GitPkgA.changes | ||
sed 's@test-pkgA@test-GitPkgA@' -i * | ||
git add * | ||
DATE="2022-01-03 11:22:33 UTC" | ||
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Initial commit" --date "$DATE" | ||
|
||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-2.spec test-GitPkgA.spec | ||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-2.changes test-GitPkgA.changes | ||
sed 's@test-pkgA@test-GitPkgA@' -i * | ||
git add * | ||
DATE="2022-01-04 11:22:33 UTC" | ||
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Version 2" --date "$DATE" | ||
|
||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-3.spec test-GitPkgA.spec | ||
cp -a "$TOPDIR"/fixtures/pac/test-pkgA-3.changes test-GitPkgA.changes | ||
sed 's@test-pkgA@test-GitPkgA@' -i * | ||
git add * | ||
DATE="2022-01-05 11:22:33 UTC" | ||
GIT_COMMITTER_DATE="$DATE" git commit -a -m "Version 3" --date "$DATE" | ||
|
||
git remote add origin http://admin:opensuse@localhost:3000/pool/test-GitPkgA.git | ||
git push --set-upstream origin factory | ||
|
||
popd | ||
|
||
# create test-GitPkgA package in test:factory that has scmsync set to gitea | ||
$OSC api -X PUT '/source/test:factory/test-GitPkgA/_meta' --file "$TOPDIR"/fixtures/pac/test-GitPkgA.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACBqN71PEkPcdLHUG+oMKpAmnDAgdcuS4V3hEyRWaVf+iQAAAJh1HuOIdR7j | ||
iAAAAAtzc2gtZWQyNTUxOQAAACBqN71PEkPcdLHUG+oMKpAmnDAgdcuS4V3hEyRWaVf+iQ | ||
AAAEAqkTwb9syNHFuOFoy/UJgZGoHHX7zSMx7X10GmhgeIBGo3vU8SQ9x0sdQb6gwqkCac | ||
MCB1y5LhXeETJFZpV/6JAAAAEGFkbWluQGdpdGVhLXRlc3QBAgMEBQ== | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGo3vU8SQ9x0sdQb6gwqkCacMCB1y5LhXeETJFZpV/6J admin@gitea-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACBjDWj0eVxs8MzCGGrlEVekrafN+SaLymKSRHkeHefmFAAAAJhrDGRKawxk | ||
SgAAAAtzc2gtZWQyNTUxOQAAACBjDWj0eVxs8MzCGGrlEVekrafN+SaLymKSRHkeHefmFA | ||
AAAEDAwkWtXW0L35H8L4Can51HQh8JReoINka/SbeHflG2+mMNaPR5XGzwzMIYauURV6St | ||
p835JovKYpJEeR4d5+YUAAAAEGFsaWNlQGdpdGVhLXRlc3QBAgMEBQ== | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGMNaPR5XGzwzMIYauURV6Stp835JovKYpJEeR4d5+YU alice@gitea-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACCB3UPX7odgSnmMTKiD3SFI7U6DF7QU5RXoLAwDz0zPKAAAAJhCzJXDQsyV | ||
wwAAAAtzc2gtZWQyNTUxOQAAACCB3UPX7odgSnmMTKiD3SFI7U6DF7QU5RXoLAwDz0zPKA | ||
AAAECYDWlFAzIcdQsOV07CJXRYWoynJSNUsPzvGZDk4/tX+4HdQ9fuh2BKeYxMqIPdIUjt | ||
ToMXtBTlFegsDAPPTM8oAAAADmJvYkBnaXRlYS10ZXN0AQIDBAUGBw== | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIHdQ9fuh2BKeYxMqIPdIUjtToMXtBTlFegsDAPPTM8o bob@gitea-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
CONF='/etc/gitea/conf/app.ini' | ||
|
||
if [ -n "${GITEA_SERVER_HTTP_PORT}" ]; then | ||
sed -i "s@^HTTP_PORT =.*@HTTP_PORT = ${GITEA_SERVER_HTTP_PORT}@" "${CONF}" | ||
fi | ||
|
||
if [ -n "${GITEA_SERVER_SSH_PORT}" ]; then | ||
sed -i "s@^SSH_PORT =.*@SSH_PORT = ${GITEA_SERVER_SSH_PORT}@" "${CONF}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
CONF='/srv/www/obs/api/config/options.yml' | ||
|
||
if [ "${OBS_PROXY_AUTH}" -eq 1 ]; then | ||
# enable proxy auth in OBS if $OBS_PROXY_AUTH is set to 1 | ||
sed -i 's@^[ #]*proxy_auth_mode: .*@ proxy_auth_mode: :on@' "${CONF}" | ||
sed -i 's@^[ #]*proxy_auth_login_page: .*@ proxy_auth_login_page: https://my-idp.example.com/login@' "${CONF}" | ||
sed -i 's@^[ #]*proxy_auth_logout_page: .*@ proxy_auth_logout_page: https://my-idp.example.com/logout@' "${CONF}" | ||
|
||
# if this is not set, any changes to the tokens fail | ||
sed -i 's@^[ #]*proxy_auth_account_page: .*@ proxy_auth_account_page: https://my-idp.example.com/myaccount@' "${CONF}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.