|
| 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 |
0 commit comments