Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f48fe015e1 | ||
|
|
a72f543def | ||
|
|
2f9c2b4b9f | ||
|
|
5ea1da9aba | ||
|
|
42a7c5f334 | ||
|
|
f8cf3429de | ||
|
|
de766759da | ||
|
|
55173be919 | ||
|
|
ec0f5fd496 | ||
|
|
03e7194f91 |
No files matched your search
@@ -10,11 +10,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
|
||||
with:
|
||||
php-version: "8.4"
|
||||
extensions: curl, xml, mbstring, zip
|
||||
tools: composer
|
||||
- name: Install PHP 8.4
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ondrej/php
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y php8.4 php8.4-curl php8.4-xml php8.4-mbstring php8.4-zip php8.4-ldap php8.4-gd
|
||||
sudo update-alternatives --set php /usr/bin/php8.4
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
- name: PHP code style
|
||||
run: |
|
||||
make vendor-bin-codestyle
|
||||
@@ -113,7 +115,7 @@ jobs:
|
||||
- apiActivities
|
||||
# search
|
||||
- apiSearch1
|
||||
# - apiSearch2
|
||||
- apiSearch2
|
||||
- apiSearchContent # needs Tika
|
||||
# sharing
|
||||
- apiSharingNgShares
|
||||
@@ -130,7 +132,7 @@ jobs:
|
||||
# antivirus (needs ClamAV)
|
||||
- apiAntivirus
|
||||
# federation (needs email + federation ocis)
|
||||
# - apiOcm
|
||||
- apiOcm
|
||||
# collaboration (needs WOPI)
|
||||
- apiCollaboration
|
||||
steps:
|
||||
@@ -150,7 +152,8 @@ jobs:
|
||||
- name: Install libcurl 8.12.0 from source
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y libssl-dev libnghttp2-dev libpsl-dev libldap-dev libssh-dev zlib1g-dev libvips-dev
|
||||
# NEEDRESTART_MODE=a: auto-restart services silently; without this, needrestart can fail with exit code 6
|
||||
sudo NEEDRESTART_MODE=a apt-get install -y libssl-dev libnghttp2-dev libpsl-dev libldap-dev libssh-dev zlib1g-dev libvips-dev
|
||||
cd /tmp
|
||||
curl -sLO https://curl.se/download/curl-8.12.0.tar.gz
|
||||
tar xzf curl-8.12.0.tar.gz
|
||||
@@ -169,11 +172,15 @@ jobs:
|
||||
}
|
||||
'
|
||||
|
||||
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
|
||||
with:
|
||||
php-version: "8.4"
|
||||
extensions: curl, xml, mbstring, zip
|
||||
tools: composer
|
||||
- name: Install PHP 8.4
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ondrej/php
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y php8.4 php8.4-curl php8.4-xml php8.4-mbstring php8.4-zip php8.4-ldap php8.4-gd
|
||||
sudo update-alternatives --set php /usr/bin/php8.4
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
php -v
|
||||
composer --version
|
||||
|
||||
- name: Run ${{ matrix.suite }}
|
||||
run: BEHAT_SUITES=${{ matrix.suite }} python3 tests/acceptance/run-github.py
|
||||
@@ -201,11 +208,15 @@ jobs:
|
||||
- name: Enable pnpm
|
||||
run: corepack enable && corepack prepare pnpm@10.28.1 --activate
|
||||
|
||||
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
|
||||
with:
|
||||
php-version: "8.4"
|
||||
extensions: curl, xml, mbstring, zip
|
||||
tools: composer
|
||||
- name: Install PHP 8.4
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ondrej/php
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y php8.4 php8.4-curl php8.4-xml php8.4-mbstring php8.4-zip php8.4-ldap php8.4-gd
|
||||
sudo update-alternatives --set php /usr/bin/php8.4
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
php -v
|
||||
composer --version
|
||||
|
||||
- name: Run ${{ matrix.suite }}
|
||||
run: BEHAT_SUITES="${{ matrix.suite }}" python3 tests/acceptance/run-github.py
|
||||
@@ -218,10 +229,14 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
suite:
|
||||
- "coreApiAuth,coreApiCapabilities,coreApiFavorites,coreApiMain,coreApiVersions"
|
||||
- "coreApiShareManagementBasicToShares,coreApiShareManagementToShares"
|
||||
- "coreApiSharees,coreApiSharePublicLink2"
|
||||
- "coreApiShareOperationsToShares1,coreApiShareOperationsToShares2,coreApiSharePublicLink1,coreApiShareCreateSpecialToShares1,coreApiShareCreateSpecialToShares2,coreApiShareUpdateToShares"
|
||||
- "coreApiTrashbin,coreApiTrashbinRestore,coreApiWebdavEtagPropagation1,coreApiWebdavEtagPropagation2"
|
||||
- "coreApiWebdavDelete,coreApiWebdavOperations,coreApiWebdavMove2"
|
||||
- "coreApiWebdavProperties"
|
||||
- "coreApiWebdavMove1,coreApiWebdavPreviews,coreApiWebdavUpload,coreApiWebdavUploadTUS"
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
@@ -239,7 +254,8 @@ jobs:
|
||||
- name: Install libcurl 8.12.0 from source
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y libssl-dev libnghttp2-dev libpsl-dev libldap-dev libssh-dev zlib1g-dev libvips-dev
|
||||
# NEEDRESTART_MODE=a: auto-restart services silently; without this, needrestart can fail with exit code 6
|
||||
sudo NEEDRESTART_MODE=a apt-get install -y libssl-dev libnghttp2-dev libpsl-dev libldap-dev libssh-dev zlib1g-dev libvips-dev
|
||||
cd /tmp
|
||||
curl -sLO https://curl.se/download/curl-8.12.0.tar.gz
|
||||
tar xzf curl-8.12.0.tar.gz
|
||||
@@ -258,33 +274,138 @@ jobs:
|
||||
}
|
||||
'
|
||||
|
||||
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
|
||||
with:
|
||||
php-version: "8.4"
|
||||
extensions: curl, xml, mbstring, zip
|
||||
tools: composer
|
||||
- name: Install PHP 8.4
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:ondrej/php
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y php8.4 php8.4-curl php8.4-xml php8.4-mbstring php8.4-zip php8.4-ldap php8.4-gd
|
||||
sudo update-alternatives --set php /usr/bin/php8.4
|
||||
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
- name: Run ${{ matrix.suite }}
|
||||
run: >
|
||||
BEHAT_SUITES="${{ matrix.suite }}"
|
||||
ACCEPTANCE_TEST_TYPE=core-api
|
||||
EXPECTED_FAILURES_FILE=tests/acceptance/expected-failures-API-on-OCIS-storage.md
|
||||
WITH_REMOTE_PHP=true
|
||||
python3 tests/acceptance/run-github.py
|
||||
|
||||
- name: Upload test logs
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
e2e-tests:
|
||||
name: e2e-${{ matrix.suite }}
|
||||
needs: [build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- suite: part-1
|
||||
args: "--total-parts 4 --xsuites search,app-provider,ocm,keycloak --run-part 1"
|
||||
- suite: part-2
|
||||
args: "--total-parts 4 --xsuites search,app-provider,ocm,keycloak --run-part 2"
|
||||
- suite: part-3
|
||||
args: "--total-parts 4 --xsuites search,app-provider,ocm,keycloak --run-part 3"
|
||||
- suite: part-4
|
||||
args: "--total-parts 4 --xsuites search,app-provider,ocm,keycloak --run-part 4"
|
||||
- suite: search
|
||||
args: "--suites search"
|
||||
tika: true
|
||||
- suite: keycloak
|
||||
args: "--suites journeys,keycloak"
|
||||
keycloak: true
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
name: test-logs-${{ matrix.suite }}
|
||||
path: tests/acceptance/output/
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||
with:
|
||||
node-version: "24"
|
||||
- name: Enable pnpm
|
||||
run: corepack enable && corepack prepare pnpm@10.28.1 --activate
|
||||
- name: Generate code
|
||||
run: |
|
||||
pnpm config set store-dir ./.pnpm-store
|
||||
make ci-node-generate
|
||||
env:
|
||||
CHROMEDRIVER_SKIP_DOWNLOAD: "true"
|
||||
|
||||
- name: Cache Playwright Chromium
|
||||
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
|
||||
with:
|
||||
path: ~/.cache/ms-playwright
|
||||
key: playwright-chromium-${{ hashFiles('.drone.env') }}
|
||||
|
||||
# --- Tika (search suite only) ---
|
||||
- name: Start Tika
|
||||
if: matrix.tika == true
|
||||
run: |
|
||||
docker run -d --name tika --network host apache/tika:3.2.2.0-full
|
||||
timeout 120 bash -c 'until curl -sf http://localhost:9998; do sleep 2; done'
|
||||
echo "tika ready."
|
||||
|
||||
# --- Keycloak (keycloak suite only) ---
|
||||
- name: Generate Keycloak certs
|
||||
if: matrix.keycloak == true
|
||||
run: |
|
||||
mkdir -p keycloak-certs
|
||||
openssl req -x509 -newkey rsa:2048 \
|
||||
-keyout keycloak-certs/keycloakkey.pem \
|
||||
-out keycloak-certs/keycloakcrt.pem \
|
||||
-nodes -days 365 -subj '/CN=keycloak'
|
||||
chmod -R 777 keycloak-certs
|
||||
|
||||
- name: Start Postgres
|
||||
if: matrix.keycloak == true
|
||||
run: |
|
||||
docker run -d --name postgres --network host \
|
||||
-e POSTGRES_DB=keycloak \
|
||||
-e POSTGRES_USER=keycloak \
|
||||
-e POSTGRES_PASSWORD=keycloak \
|
||||
postgres:alpine3.18
|
||||
timeout 30 bash -c 'until docker exec postgres pg_isready -U keycloak; do sleep 1; done'
|
||||
|
||||
- name: Start Keycloak
|
||||
if: matrix.keycloak == true
|
||||
run: |
|
||||
# Patch realm: replace Drone Docker hostname with localhost IP
|
||||
sed 's|https://ocis-server:9200|https://127.0.0.1:9200|g' \
|
||||
tests/config/drone/ocis-ci-realm.dist.json > /tmp/ocis-realm.json
|
||||
docker run -d --name keycloak --network host \
|
||||
-e OCIS_DOMAIN=https://127.0.0.1:9200 \
|
||||
-e KC_HOSTNAME=localhost \
|
||||
-e KC_PORT=8443 \
|
||||
-e KC_DB=postgres \
|
||||
-e "KC_DB_URL=jdbc:postgresql://localhost:5432/keycloak" \
|
||||
-e KC_DB_USERNAME=keycloak \
|
||||
-e KC_DB_PASSWORD=keycloak \
|
||||
-e KC_FEATURES=impersonation \
|
||||
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
|
||||
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
|
||||
-e KC_HTTPS_CERTIFICATE_FILE=/keycloak-certs/keycloakcrt.pem \
|
||||
-e KC_HTTPS_CERTIFICATE_KEY_FILE=/keycloak-certs/keycloakkey.pem \
|
||||
-v "$(pwd)/keycloak-certs:/keycloak-certs:ro" \
|
||||
-v "/tmp/ocis-realm.json:/opt/keycloak/data/import/oCIS-realm.json:ro" \
|
||||
quay.io/keycloak/keycloak:26.2.5 \
|
||||
start-dev --proxy-headers xforwarded \
|
||||
--spi-connections-http-client-default-disable-trust-manager=true \
|
||||
--import-realm --health-enabled=true
|
||||
timeout 300 bash -c 'until curl -skf https://localhost:9000/health/ready; do sleep 3; done' \
|
||||
|| (echo "=== keycloak logs ===" && docker logs keycloak --tail 80 && exit 1)
|
||||
echo "keycloak ready."
|
||||
|
||||
- name: Run e2e-${{ matrix.suite }}
|
||||
run: E2E_ARGS="${{ matrix.args }}" python3 tests/acceptance/run-e2e.py
|
||||
env:
|
||||
TIKA_NEEDED: ${{ matrix.tika == true && 'true' || 'false' }}
|
||||
KEYCLOAK_NEEDED: ${{ matrix.keycloak == true && 'true' || 'false' }}
|
||||
|
||||
litmus:
|
||||
name: litmus
|
||||
needs: [build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
@@ -296,8 +417,8 @@ jobs:
|
||||
needs: [build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
@@ -309,8 +430,8 @@ jobs:
|
||||
needs: [build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
@@ -322,8 +443,8 @@ jobs:
|
||||
needs: [build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
@@ -331,7 +452,7 @@ jobs:
|
||||
run: python3 tests/acceptance/run-wopi.py --type cs3
|
||||
|
||||
all-acceptance-tests:
|
||||
needs: [local-api-tests, cli-tests, core-api-tests, litmus, cs3api, wopi-builtin, wopi-cs3]
|
||||
needs: [local-api-tests, cli-tests, core-api-tests, litmus, cs3api, wopi-builtin, wopi-cs3, e2e-tests]
|
||||
runs-on: ubuntu-latest
|
||||
if: always()
|
||||
steps:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The following grep will filter out every line containing an `env` annotation.
|
||||
# It will ignore every line that already has a valid `introductionVersion` annotation.
|
||||
# the following grep will filter out every line containing an `env` annotation
|
||||
# and prints all entries found that are invalid. this is required to see where CI might fail
|
||||
|
||||
RED=$(echo -e "\033[0;31m")
|
||||
GREEN=$(echo -e "\033[0;32m")
|
||||
@@ -14,48 +14,64 @@ print_introduction_version_examples() {
|
||||
${GREEN}Valid examples:${NORM}
|
||||
|
||||
introductionVersion:"pre5.0"
|
||||
introductionVersion:"5.0"
|
||||
introductionVersion:"5.0" deprecationVersion:"7.0.0"
|
||||
introductionVersion:"4.9.3-rc5"
|
||||
introductionVersion:"5.0.1-cheesecake"
|
||||
introductionVersion:"5.10.100.15"
|
||||
introductionVersion:"0.0"
|
||||
introductionVersion:"releaseX" # acceptable alphabetical version
|
||||
introductionVersion:"Addams" # another alphabetical example such as a release name
|
||||
introductionVersion:"release" deprecationVersion:"7.0.0"
|
||||
introductionVersion:"releaseX" deprecationVersion:"7.0.0"
|
||||
introductionVersion:"Addams" deprecationVersion:"7.0.0"
|
||||
|
||||
${RED}Invalid examples:${NORM}
|
||||
|
||||
introductionVersion:"5.0cheesecake"
|
||||
introductionVersion:"5"
|
||||
introductionVersion:"5blueberry"
|
||||
introductionVersion:""
|
||||
introductionVersion:" "
|
||||
introductionVersion:"-"
|
||||
introductionVersion:"--"
|
||||
introductionVersion:"51.0cheesecake" deprecationVersion:"7.0.0"
|
||||
introductionVersion:"50..0.1-cheesecake"
|
||||
introductionVersion:"15"
|
||||
introductionVersion:"54blueberry"
|
||||
introductionVersion:"5-lasagna"
|
||||
introductionVersion:"4.9.3rc5"
|
||||
introductionVersion:"5.lasagna-rc1"
|
||||
introductionVersion:"4.9.3rc-5" deprecationVersion:"7.0.0"
|
||||
introductionVersion:"5B-rc1" deprecationVersion:"7.0.0"
|
||||
|
||||
See the dev docs for more details: https://owncloud.dev/services/general-info/envvars/envvar-naming-scopes/
|
||||
See the envvar life cycle in the dev docs for more details:
|
||||
https://owncloud.dev/services/general-info/envvars/envvar-naming-scopes/
|
||||
EOL
|
||||
}
|
||||
|
||||
ERROR=0
|
||||
|
||||
SEMVER_REGEX="([0-9]|[1-9][0-9]*)(\.([0-9]|[1-9][0-9]*)){1,2}(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?"
|
||||
ALPHA_REGEX="[A-Za-z]+[A-Za-z0-9-]*"
|
||||
# note that our semver is not fully compliant because we do not have a patch version for new envvars
|
||||
# if you want to test, use the examples above and take the blocks separated by `|` (or)
|
||||
SEMVER_REGEX='(?:introductionVersion:\")(?:(?:[^\dA-Za-z]*?)\"|(?:\d+[A-z]+).*?\"|(?:\d*?\")|(?:\d*?[-\.]+\D.*?\")|(?:\d*?[\.]{2,}.*?\")|(?:\d+\.\d+[A-z]+\")|(?:(?:\d+\.)+\d+[A-z]+.*?\"))'
|
||||
|
||||
QI=$(git grep -n "env:" -- '*.go' |grep -v -P "introductionVersion:\"($SEMVER_REGEX|(pre5\\.0)|($ALPHA_REGEX))\""|grep -v "_test.go"|grep -v "vendor/")
|
||||
# filter out the the following paths
|
||||
EXCLUDE_PATHS='_test.go|vendor/'
|
||||
|
||||
# query the code
|
||||
QI=$(git grep -n "env:" -- '*.go' | grep -v -E "${EXCLUDE_PATHS}" | grep --color=always -P "${SEMVER_REGEX}")
|
||||
|
||||
# count the results found
|
||||
RESULTS_INTRO=$(echo "${QI}"|wc -l)
|
||||
|
||||
# add a new line after each hit, eol identified via "´ which only appears at the end of each envvar string definition
|
||||
QUERY_INTRO=$(echo "${QI}" | sed "s#\"\`#\"\`\n#g")
|
||||
|
||||
RESULTS_INTRO=$(echo "${QUERY_INTRO}"|wc -l)
|
||||
|
||||
echo "Checking introductionVersion annotations"
|
||||
|
||||
if [ "${QUERY_INTRO}" != "" ] && [ "${RESULTS_INTRO}" -gt 0 ]; then
|
||||
echo
|
||||
echo "==============================================================================================="
|
||||
echo ${RED}"The following ${RESULTS_INTRO} items contain invalid or missing introductionVersion annotation(s):"${NORM}
|
||||
echo ${RED}"The following item(s) contain invalid or missing introductionVersion annotation(s):"${NORM}
|
||||
echo "==============================================================================================="
|
||||
echo
|
||||
echo "$QUERY_INTRO"
|
||||
echo
|
||||
echo ${GREEN}"${RESULTS_INTRO} items found"${NORM}
|
||||
echo
|
||||
print_introduction_version_examples
|
||||
echo
|
||||
ERROR=1
|
||||
@@ -64,11 +80,13 @@ else
|
||||
echo
|
||||
fi
|
||||
|
||||
# The following grep will filter out every line containing an `env` annotation
|
||||
# it will ignore every line that has allready a valid `desc` annotation
|
||||
# the following grep will filter out every line containing an `env` annotation and
|
||||
# will print each line that has an invalid `desc` annotation.
|
||||
|
||||
QUERY_DESC=$(git grep -n "env:" -- '*.go' |grep -v -P "desc:\".{10,}\""|grep -v "_test.go"|grep -v "vendor/")
|
||||
# query the code
|
||||
QUERY_DESC=$(git grep -n "env:" -- '*.go' | grep -v -E "${EXCLUDE_PATHS}" | grep -v --color=always -P "desc:\".{10,}\"")
|
||||
|
||||
# count the results found
|
||||
RESULTS_DESC=$(echo "${QUERY_DESC}"|wc -l)
|
||||
|
||||
echo "Checking description annotations"
|
||||
@@ -76,9 +94,11 @@ echo "Checking description annotations"
|
||||
if [ "${QUERY_DESC}" != "" ] && [ "${RESULTS_DESC}" -gt 0 ]; then
|
||||
echo
|
||||
echo "==============================================================================================="
|
||||
echo ${RED}"The following ${RESULTS_DESC} items contain invalid or missing description annotation:"${NORM}
|
||||
echo ${RED}"The following item(s) contain invalid or missing description annotation:"${NORM}
|
||||
echo "==============================================================================================="
|
||||
echo "$QUERY_DESC"
|
||||
echo
|
||||
echo ${GREEN}"${RESULTS_DESC} items found"${NORM}
|
||||
ERROR=1
|
||||
else
|
||||
echo "All description annotations are valid"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Bugfix: Avoid superfluous GetPublicShare call when deleting space permissions
|
||||
|
||||
We fixed `DeletePermission` to recognise space permission IDs (prefixed with
|
||||
`u:` or `g:`) by their format before making any gateway calls. Previously,
|
||||
deleting a space member always triggered a `GetPublicShare` lookup that was
|
||||
guaranteed to fail, producing a confusing error log.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12122
|
||||
https://github.com/owncloud/ocis/issues/12012
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# this script can run from everywhere in the ocis repo because it uses git grep
|
||||
|
||||
# The following grep will filter out every line containing an `env` annotation AND
|
||||
# containing a non semver `introductionVersion` annotation that is used as placeholder.
|
||||
# note that invalid `introductionVersion` annotations are already covered via:
|
||||
# /.make/check-env-var-annotations.sh as part of the CI
|
||||
|
||||
RED=$(echo -e "\033[0;31m")
|
||||
GREEN=$(echo -e "\033[0;32m")
|
||||
NORM=$(echo -e "\033[0m")
|
||||
|
||||
|
||||
# build the correct regex
|
||||
IV_REGEX='(?:introductionVersion:\")(?!pre5\.0)(?:[^\d].*?\")'
|
||||
IV_NAME=introductionVersion
|
||||
|
||||
RV_REGEX='(?:removalVersion:\")(?!pre5\.0)(?:[^\d].*?\")'
|
||||
RV_NAME=removalVersion
|
||||
|
||||
EXCLUDE_PATHS='_test.go|vendor/'
|
||||
|
||||
# create a here doc function to be printed when the option is selected
|
||||
# note that tabs are used intentionally. they are removed by cat but are required to make the code readable.
|
||||
print_version_examples() {
|
||||
cat <<-EOL
|
||||
${GREEN}Valid $1 examples:${NORM}
|
||||
|
||||
$1:"releaseX" # acceptable alphabetical version
|
||||
$1:"Addams" # another alphabetical example such as a release name
|
||||
$1:"Addams.8" # another alphabetical example such as a release name plus a version
|
||||
$1:"%%NEXT%%" # a dummy placeholder as release name
|
||||
|
||||
See the dev docs for more details: https://owncloud.dev/services/general-info/envvars/envvar-naming-scopes/
|
||||
EOL
|
||||
}
|
||||
|
||||
# ask what the script should search for
|
||||
echo "Select one of the following keys to search for:"
|
||||
echo
|
||||
echo " 1) introductionVersion"
|
||||
echo " 2) removalVersion"
|
||||
echo " 3) Print valid matching search pattern examples"
|
||||
echo
|
||||
read -s -n 1 n
|
||||
case $n in
|
||||
1) USEREGEX="${IV_REGEX}"
|
||||
NAME="${IV_NAME}"
|
||||
;;
|
||||
2) USEREGEX="${RV_REGEX}"
|
||||
NAME="${RV_NAME}"
|
||||
;;
|
||||
3) echo
|
||||
print_version_examples "${IV_NAME}"
|
||||
echo
|
||||
print_version_examples "${RV_NAME}"
|
||||
echo
|
||||
exit
|
||||
;;
|
||||
*) echo "Invalid option"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
|
||||
# query the code
|
||||
QS=$(git grep -n "env:" -- '*.go' | grep -v -E "${EXCLUDE_PATHS}" | grep --color=always -P "${USEREGEX}")
|
||||
|
||||
# count the results found
|
||||
RESULTS_COUNT=$(echo "${QS}"|wc -l)
|
||||
|
||||
# add a new line after each hit, eol identified via "´ which only appears at the end of each envvar string definition
|
||||
QUERY_RESULT=$(echo "${QS}" | sed "s#\"\`#\"\`\n#g")
|
||||
|
||||
echo "Checking ${NAME} annotations"
|
||||
|
||||
if [ "${QUERY_RESULT}" != "" ] && [ "${RESULTS_COUNT}" -gt 0 ]; then
|
||||
echo
|
||||
echo "==============================================================================================="
|
||||
echo ${GREEN}"The following items contain placeholder ${NAME} annotation(s):"${NORM}
|
||||
echo "==============================================================================================="
|
||||
echo
|
||||
echo "$QUERY_RESULT"
|
||||
echo
|
||||
echo ${GREEN}"${RESULTS_COUNT} items found"${NORM}
|
||||
echo
|
||||
else
|
||||
echo ${GREEN}"No matching placeholders for ${NAME} annotations found."${NORM}
|
||||
echo
|
||||
fi
|
||||
@@ -549,7 +549,7 @@ From the `Run and Debug` panel of VSCode, select `Fed oCIS Server` and start the
|
||||
source tests/config/local/.env-federation && ocis/bin/ocis init
|
||||
|
||||
# run oCIS
|
||||
ocis/bin/ocis server
|
||||
source tests/config/local/.env-federation && ocis/bin/ocis server
|
||||
```
|
||||
|
||||
The second oCIS instance should be available at: <https://localhost:10200/>
|
||||
@@ -567,7 +567,7 @@ Run the acceptance test with the following command:
|
||||
```bash
|
||||
TEST_SERVER_URL="https://localhost:9200" \
|
||||
TEST_SERVER_FED_URL="https://localhost:10200" \
|
||||
BEHAT_FEATURE="tests/acceptance/features/apiOcm/ocm.feature" \
|
||||
BEHAT_SUITE=apiOcm \
|
||||
make test-acceptance-api
|
||||
```
|
||||
|
||||
|
||||
@@ -52,24 +52,25 @@ The envvar struct tag contains at maximum the following key/value pairs to docum
|
||||
|
||||
### Introduce new Envvars
|
||||
|
||||
If a new envvar is introduced, the complete struct needs to be added, but only the `introductionVersion` requires data.
|
||||
* If a **new** envvar is introduced, the entire structure must be added, including the `introductionVersion` field. Note that 'introduced' means, that the new envvar was not present in any of the services.
|
||||
|
||||
{{< hint info >}}
|
||||
* During development, set `introductionVersion` to a short, **alphabetic code name** that represents the upcoming release (e.g. `releaseX`).
|
||||
* This identifier stays constant until the release receives its final production semantic-version number.
|
||||
{{< /hint >}}
|
||||
{{< hint info >}}
|
||||
* During development, set the `introductionVersion` to a short, **alphabetic code name** that represents the upcoming release such as `releaseX` or the project name for that release such as `Daledda`.
|
||||
* This identifier stays constant until the release receives its final production semantic-version number.
|
||||
* Although the pipeline checks the semver string when a PR is created, you can perform this check upfront manually by entering the following command from the ocis root:
|
||||
|
||||
The docs helper scripts render these alphabetic identifiers verbatim. They appear in the next (master) branch of the admin docs as rendered here.
|
||||
```bash
|
||||
.make/check-env-var-annotations.sh
|
||||
```
|
||||
{{< /hint >}}
|
||||
|
||||
Once the release is cut, before tagging, replace them with the actual semantic version (e.g. `releaseX` → `7.2.0`).
|
||||
The doc helper scripts render these alphabetic identifiers verbatim. They appear in the next (master) branch of the admin documentation exactly as they are entered.
|
||||
|
||||
{{< hint info >}}
|
||||
A new production version **MUST NOT** contain any alphabetic identifyers but the semantic version only.
|
||||
{{< /hint >}}
|
||||
* See the [Set the Correct IntroductionVersion]({{< ref "./new-release-process/" >}}) documentation before starting a new release candidate.
|
||||
|
||||
### Adding Envvars to Existing Ones
|
||||
|
||||
If an envvar has been introduced with a particular version, the `introductionVersion` gets a value accordingly. If an additional envvar like a global one is added to this existing envvar later on, the introduction version will *not* be changed.
|
||||
If an envvar has been introduced with a particular release, the `introductionVersion` got a semver value accordingly. If an additional envvar is added to this existing one such as a global envvar, the introduction version **must not** be changed.
|
||||
|
||||
### Deprecate Existing Envvars
|
||||
|
||||
|
||||
@@ -23,13 +23,26 @@ Ask the developers if envvars of this type have been changed (added or removed).
|
||||
* From the ocis root run:\
|
||||
`sudo make docs-clean`\
|
||||
`make docs-generate`\
|
||||
Drop any changes in `env_vars.yaml`!
|
||||
Discard any changes in `env_vars.yaml`!
|
||||
* Check if there is a change in the `extended-envars.yaml` output.\
|
||||
If so, process [Extended Envvars - Fixing Changed Item]({{< ref "./special-envvars.md#fixing-changed-items" >}}).
|
||||
If so, process [Extended Envvars - Fixing Changed Items]({{< ref "./special-envvars.md#fixing-changed-items" >}}).
|
||||
* When done, re-run `make docs-generate` and check if the output matches the expectations in `./docs/services/_includes/adoc/extended_configvars.adoc`.
|
||||
|
||||
## Ordinary Envvars
|
||||
|
||||
### Set the Correct IntroductionVersion
|
||||
|
||||
* Once the release is cut, **before** creating the first release candidate, replace them with the actual semantic version (e.g. `releaseX` → `8.1.0`). To find these placeholders in `introductionVersion` keys, you can run a helper script by issuing the following command:
|
||||
```bash
|
||||
docs/ocis/helpers/identify_envvar_placeholder_names.sh
|
||||
```
|
||||
|
||||
{{< hint info >}}
|
||||
A new production version **MUST NOT** contain any alphabetic identifyers but the semantic version only, using **major, minor and a patch version, which is always 0!**.
|
||||
{{< /hint >}}
|
||||
|
||||
* Create a PR and merge it **before** taking the next step maintaining the `env_vars.yaml` file! Do not forget to rebase your local git repo.
|
||||
|
||||
### Maintain the 'env_vars.yaml' File
|
||||
|
||||
This is **mandatory for a new release** !
|
||||
@@ -38,17 +51,13 @@ This is **mandatory for a new release** !
|
||||
`sudo make docs-clean`\
|
||||
`make docs-generate`\
|
||||
Any changes in `env_vars.yaml` are now considered.
|
||||
* This file will most likely show changes and merging them is **essential** as base for **added/removed or deprecated envvars**. Note that this file will get additions/updates only, but items never get deleted automatically !!\
|
||||
* This file will most likely show changes and merging them is **essential** as base for **added/removed or deprecated envvars** (envvar deltas). Note that this file will get additions/updates only, but items never get deleted automatically !!\
|
||||
{{< hint info >}}
|
||||
Note that due to how the code is currently designed, **things may get shifted** around though no real changes have been introduced.
|
||||
{{< /hint >}}
|
||||
* First, check if any **alphabetic code names** are present in the changes. See [Introduce new Envvars]({{< ref "./envvar-naming-scopes.md/#introduce-new-envvars" >}}).
|
||||
* If so, create a new branch and replace them in the **service containing the source** with the actual semantic version (e.g. `releaseX` → `7.2.0`) first. Note that ALL of major, minor and patch numbers must be present, including patch versions == `0`.
|
||||
* If all changes are applied, rerun `make docs-generate` and check if all changes are incorporated in the yaml file.
|
||||
* Create a PR and merge these changes, dont forget to do a local pull of master afterwards...
|
||||
* With a new branch, remove all envvars from the `env_vars.yaml` file manually that have formerly been deprecated and removed from the code.
|
||||
* With a new branch, remove all envvars from the `env_vars.yaml` file manually that have formerly been deprecated **and removed** from the code.
|
||||
* Commit the changes and merge it.\
|
||||
Now `env_vars.yaml` is up to date on the repo in master, next steps are based on this state!
|
||||
Now, `env_vars.yaml` is up to date in the repo in master. Next steps depend on this updated file!
|
||||
|
||||
### Create Envvar Delta Files
|
||||
|
||||
|
||||
@@ -183,8 +183,8 @@ require (
|
||||
github.com/go-acme/lego/v4 v4.25.2 // indirect
|
||||
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.6.2 // indirect
|
||||
github.com/go-git/go-git/v5 v5.16.5 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.8.0 // indirect
|
||||
github.com/go-git/go-git/v5 v5.17.1 // indirect
|
||||
github.com/go-ini/ini v1.67.0 // indirect
|
||||
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
|
||||
|
||||
@@ -292,12 +292,12 @@ github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
|
||||
github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM=
|
||||
github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU=
|
||||
github.com/go-git/go-billy/v5 v5.8.0 h1:I8hjc3LbBlXTtVuFNJuwYuMiHvQJDq1AT6u4DwDzZG0=
|
||||
github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5SqfmrrheCY=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
|
||||
github.com/go-git/go-git/v5 v5.16.5 h1:mdkuqblwr57kVfXri5TTH+nMFLNUxIj9Z7F5ykFbw5s=
|
||||
github.com/go-git/go-git/v5 v5.16.5/go.mod h1:QOMLpNf1qxuSY4StA/ArOdfFR2TrKEjJiye2kel2m+M=
|
||||
github.com/go-git/go-git/v5 v5.17.1 h1:WnljyxIzSj9BRRUlnmAU35ohDsjRK0EKmL0evDqi5Jk=
|
||||
github.com/go-git/go-git/v5 v5.17.1/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
|
||||
@@ -556,40 +556,13 @@ func (s DriveItemPermissionsService) DeletePermission(ctx context.Context, itemI
|
||||
ctx, span := s.tp.Tracer("graph").Start(ctx, "DeletePermission")
|
||||
defer span.End()
|
||||
|
||||
var permissionType permissionType
|
||||
|
||||
sharedResourceID, err := s.getLinkPermissionResourceID(ctx, permissionID)
|
||||
switch {
|
||||
// Check if the ID is referring to a public share
|
||||
case err == nil:
|
||||
permissionType = Public
|
||||
// If the item id is referring to a space root and this is not a public share
|
||||
// we have to deal with space permissions
|
||||
case IsSpaceRoot(itemID):
|
||||
permissionType = Space
|
||||
sharedResourceID = itemID
|
||||
err = nil
|
||||
// If this is neither a public share nor a space permission, check if this is a
|
||||
// user share
|
||||
default:
|
||||
sharedResourceID, err = s.getUserPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
permissionType = User
|
||||
}
|
||||
}
|
||||
|
||||
if sharedResourceID == nil && s.config.IncludeOCMSharees {
|
||||
sharedResourceID, err = s.getOCMPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
permissionType = OCM
|
||||
}
|
||||
}
|
||||
permType, sharedResourceID, err := s.resolveDeletePermission(ctx, itemID, permissionID)
|
||||
|
||||
switch {
|
||||
case err != nil:
|
||||
s.logger.Error().Err(err).Msg("permission error")
|
||||
return err
|
||||
case permissionType == Unknown:
|
||||
case permType == Unknown:
|
||||
s.logger.Error().Err(err).Msg("permission not found")
|
||||
return errorcode.New(errorcode.ItemNotFound, "permission not found")
|
||||
case sharedResourceID == nil:
|
||||
@@ -605,7 +578,7 @@ func (s DriveItemPermissionsService) DeletePermission(ctx context.Context, itemI
|
||||
return err
|
||||
}
|
||||
|
||||
switch permissionType {
|
||||
switch permType {
|
||||
case User:
|
||||
return s.removeUserShare(ctx, permissionID)
|
||||
case Public:
|
||||
@@ -622,6 +595,54 @@ func (s DriveItemPermissionsService) DeletePermission(ctx context.Context, itemI
|
||||
}
|
||||
}
|
||||
|
||||
// resolveDeletePermission determines the type and shared resource ID for a permission
|
||||
// that is about to be deleted.
|
||||
func (s DriveItemPermissionsService) resolveDeletePermission(ctx context.Context, itemID *storageprovider.ResourceId, permissionID string) (permissionType, *storageprovider.ResourceId, error) {
|
||||
if IsSpaceRoot(itemID) {
|
||||
return s.resolveSpaceRootPermission(ctx, itemID, permissionID)
|
||||
}
|
||||
return s.resolveItemPermission(ctx, permissionID)
|
||||
}
|
||||
|
||||
// resolveSpaceRootPermission resolves permissions on a space root. Space roots
|
||||
// carry space permissions (member/group grants with "u:"/"g:" prefixed IDs) and
|
||||
// public links. Space permissions are recognised by their ID format to avoid a
|
||||
// superfluous gateway call to GetPublicShare.
|
||||
func (s DriveItemPermissionsService) resolveSpaceRootPermission(ctx context.Context, itemID *storageprovider.ResourceId, permissionID string) (permissionType, *storageprovider.ResourceId, error) {
|
||||
if _, parseErr := spacePermissionIdToCS3Grantee(permissionID); parseErr == nil {
|
||||
return Space, itemID, nil
|
||||
}
|
||||
|
||||
sharedResourceID, err := s.getLinkPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
return Public, sharedResourceID, nil
|
||||
}
|
||||
return Unknown, nil, err
|
||||
}
|
||||
|
||||
// resolveItemPermission resolves permissions on a non-space-root item by trying
|
||||
// public link, user share, then OCM share lookups in order.
|
||||
func (s DriveItemPermissionsService) resolveItemPermission(ctx context.Context, permissionID string) (permissionType, *storageprovider.ResourceId, error) {
|
||||
sharedResourceID, err := s.getLinkPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
return Public, sharedResourceID, nil
|
||||
}
|
||||
|
||||
sharedResourceID, err = s.getUserPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
return User, sharedResourceID, nil
|
||||
}
|
||||
|
||||
if s.config.IncludeOCMSharees {
|
||||
sharedResourceID, err = s.getOCMPermissionResourceID(ctx, permissionID)
|
||||
if err == nil {
|
||||
return OCM, sharedResourceID, nil
|
||||
}
|
||||
}
|
||||
|
||||
return Unknown, nil, err
|
||||
}
|
||||
|
||||
// DeleteSpaceRootPermission deletes a permission on the root item of a project space
|
||||
func (s DriveItemPermissionsService) DeleteSpaceRootPermission(ctx context.Context, driveID *storageprovider.ResourceId, permissionID string) error {
|
||||
|
||||
|
||||
@@ -822,9 +822,8 @@ var _ = Describe("DriveItemPermissionsService", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
It("deletes a space permission as expected", func() {
|
||||
getPublicShareResponse.Status = status.NewNotFound(context.Background(), "")
|
||||
gatewayClient.On("GetPublicShare", mock.Anything, mock.Anything).Return(&getPublicShareResponse, nil)
|
||||
|
||||
// No GetPublicShare mock needed — space permissions (u:/g: prefixed IDs)
|
||||
// are recognised by their format and skip the public share lookup.
|
||||
gatewayClient.On("RemoveShare",
|
||||
mock.Anything,
|
||||
mock.Anything,
|
||||
|
||||
@@ -38,6 +38,46 @@ require_once 'bootstrap.php';
|
||||
class SearchContext implements Context {
|
||||
private FeatureContext $featureContext;
|
||||
|
||||
/**
|
||||
* Retry search until results are non-empty or timeout is reached.
|
||||
* Indexing of newly uploaded files in ocis is async, so a single
|
||||
* fixed sleep is not reliable — poll instead.
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $pattern
|
||||
* @param string|null $limit
|
||||
* @param string|null $scopeType
|
||||
* @param string|null $scope
|
||||
* @param string|null $spaceName
|
||||
* @param TableNode|null $properties
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
private function searchWithRetry(
|
||||
string $user,
|
||||
string $pattern,
|
||||
?string $limit = null,
|
||||
?string $scopeType = null,
|
||||
?string $scope = null,
|
||||
?string $spaceName = null,
|
||||
?TableNode $properties = null,
|
||||
): ResponseInterface {
|
||||
// Indexing is async — poll until results appear.
|
||||
// Initial wait 3s, then retry every 2s, up to ~13s total.
|
||||
$maxAttempts = STANDARD_RETRY_COUNT;
|
||||
$response = null;
|
||||
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
|
||||
\sleep($attempt === 0 ? 3 : 2);
|
||||
$response = $this->searchFiles($user, $pattern, $limit, $scopeType, $scope, $spaceName, $properties);
|
||||
$parsed = HttpRequestHelper::parseResponseAsXml($response);
|
||||
if (\is_array($parsed) && isset($parsed["value"]) && !empty($parsed["value"])) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
// return last response even if empty — let the assertion step produce the failure message
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $pattern
|
||||
@@ -146,10 +186,7 @@ class SearchContext implements Context {
|
||||
?string $limit = null,
|
||||
?TableNode $properties = null,
|
||||
): void {
|
||||
// NOTE: because indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously
|
||||
// short wait is necessary before searching
|
||||
sleep(5);
|
||||
$response = $this->searchFiles($user, $pattern, $limit, null, null, null, $properties);
|
||||
$response = $this->searchWithRetry($user, $pattern, $limit, null, null, null, $properties);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
@@ -269,10 +306,7 @@ class SearchContext implements Context {
|
||||
string $scope,
|
||||
?string $spaceName = null,
|
||||
): void {
|
||||
// NOTE: since indexing of newly uploaded files or directories with ocis is decoupled and occurs asynchronously,
|
||||
// a short wait is necessary before searching
|
||||
sleep(5);
|
||||
$response = $this-> searchFiles($user, $pattern, null, $scopeType, $scope, $spaceName);
|
||||
$response = $this->searchWithRetry($user, $pattern, null, $scopeType, $scope, $spaceName);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
}
|
||||
@@ -4063,10 +4063,46 @@ trait WebDav {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContentFor(string $filename): void {
|
||||
$expectedPreview = \file_get_contents(__DIR__ . "/../fixtures/" . $filename);
|
||||
$fixturePath = __DIR__ . "/../fixtures/" . $filename;
|
||||
$fixtureImg = \imagecreatefromstring(\file_get_contents($fixturePath));
|
||||
Assert::assertNotFalse($fixtureImg, "Could not decode fixture image $filename");
|
||||
|
||||
$this->getResponse()->getBody()->rewind();
|
||||
$responseBodyContent = $this->getResponse()->getBody()->getContents();
|
||||
Assert::assertEquals($expectedPreview, $responseBodyContent);
|
||||
$responseImg = \imagecreatefromstring($responseBodyContent);
|
||||
Assert::assertNotFalse($responseImg, "Downloaded preview is not a valid image");
|
||||
|
||||
$w = \imagesx($fixtureImg);
|
||||
$h = \imagesy($fixtureImg);
|
||||
Assert::assertEquals($w, \imagesx($responseImg), "Image width mismatch for fixture $filename");
|
||||
Assert::assertEquals($h, \imagesy($responseImg), "Image height mismatch for fixture $filename");
|
||||
|
||||
$tolerance = 12; // per-channel tolerance for libvips version differences
|
||||
$maxDiff = 0;
|
||||
for ($x = 0; $x < $w; $x++) {
|
||||
for ($y = 0; $y < $h; $y++) {
|
||||
$fc = \imagecolorat($fixtureImg, $x, $y);
|
||||
$rc = \imagecolorat($responseImg, $x, $y);
|
||||
$maxDiff = \max(
|
||||
$maxDiff,
|
||||
\abs(($fc >> 16 & 0xFF) - ($rc >> 16 & 0xFF)),
|
||||
\abs(($fc >> 8 & 0xFF) - ($rc >> 8 & 0xFF)),
|
||||
\abs(($fc & 0xFF) - ($rc & 0xFF)),
|
||||
);
|
||||
}
|
||||
}
|
||||
$rw = \imagesx($responseImg);
|
||||
$rh = \imagesy($responseImg);
|
||||
echo " [preview-fixture] $filename: fixture={$w}x{$h} response={$rw}x{$rh} maxPixelDiff=$maxDiff\n";
|
||||
|
||||
Assert::assertLessThanOrEqual(
|
||||
$tolerance,
|
||||
$maxDiff,
|
||||
"Preview pixel values differ by more than $tolerance from fixture $filename (max diff: $maxDiff)",
|
||||
);
|
||||
|
||||
\imagedestroy($fixtureImg);
|
||||
\imagedestroy($responseImg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Executable
+287
@@ -0,0 +1,287 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Run Playwright e2e tests against a local OCIS instance.
|
||||
|
||||
Usage: E2E_ARGS='--run-part 1' python3 tests/acceptance/run-e2e.py
|
||||
Optional: TIKA_NEEDED=true, KEYCLOAK_NEEDED=true
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import shlex
|
||||
import subprocess
|
||||
import signal
|
||||
import time
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
WEB_REPO = "https://github.com/owncloud/web.git"
|
||||
|
||||
|
||||
def wait_for(condition_fn, timeout: int, label: str) -> None:
|
||||
deadline = time.time() + timeout
|
||||
while not condition_fn():
|
||||
if time.time() > deadline:
|
||||
print(f"Timeout waiting for {label}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def ocis_healthy(ocis_url: str, use_basic_auth: bool = True) -> bool:
|
||||
if use_basic_auth:
|
||||
cmd = ["curl", "-sk", "-uadmin:admin",
|
||||
f"{ocis_url}/graph/v1.0/users/admin",
|
||||
"-w", "%{http_code}", "-o", "/dev/null"]
|
||||
else:
|
||||
# Keycloak mode: no local admin user, check unauthenticated endpoint
|
||||
cmd = ["curl", "-sk",
|
||||
f"{ocis_url}/.well-known/openid-configuration",
|
||||
"-w", "%{http_code}", "-o", "/dev/null"]
|
||||
r = subprocess.run(cmd, capture_output=True, text=True)
|
||||
return r.stdout.strip() == "200"
|
||||
|
||||
|
||||
def run(cmd: list, env: dict = None, check: bool = True, cwd=None):
|
||||
e = {**os.environ, **(env or {})}
|
||||
return subprocess.run(cmd, env=e, check=check, cwd=cwd)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
e2e_args = os.environ.get("E2E_ARGS", "").strip()
|
||||
if not e2e_args:
|
||||
print("E2E_ARGS is required, e.g. E2E_ARGS='--run-part 1' python3 run-e2e.py",
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
tika_needed = os.environ.get("TIKA_NEEDED", "").lower() == "true"
|
||||
keycloak_needed = os.environ.get("KEYCLOAK_NEEDED", "").lower() == "true"
|
||||
|
||||
repo_root = Path(__file__).resolve().parents[2]
|
||||
ocis_bin = repo_root / "ocis/bin/ocis"
|
||||
wrapper_bin = repo_root / "tests/ociswrapper/bin/ociswrapper"
|
||||
ocis_url = "https://127.0.0.1:9200"
|
||||
ocis_config_dir = Path.home() / ".ocis/config"
|
||||
web_dir = repo_root / "webTestRunner"
|
||||
|
||||
# build ocis + ociswrapper only if not already provided (e.g. via artifact)
|
||||
if not ocis_bin.exists():
|
||||
run(["make", "-C", str(repo_root / "ocis"), "build"])
|
||||
if not wrapper_bin.exists():
|
||||
run(["make", "-C", str(repo_root / "tests/ociswrapper"), "build"],
|
||||
env={"GOWORK": "off"})
|
||||
|
||||
# clone + install web only if not already provided (e.g. via artifact)
|
||||
if not web_dir.exists():
|
||||
drone_env = {}
|
||||
drone_env_file = repo_root / ".drone.env"
|
||||
if drone_env_file.exists():
|
||||
for line in drone_env_file.read_text().splitlines():
|
||||
if "=" in line and not line.startswith("#"):
|
||||
k, v = line.split("=", 1)
|
||||
drone_env[k.strip()] = v.strip()
|
||||
web_branch = drone_env.get("WEB_BRANCH", "master")
|
||||
web_commitid = drone_env.get("WEB_COMMITID", "")
|
||||
run(["git", "clone", "-b", web_branch, "--single-branch", "--no-tags",
|
||||
WEB_REPO, str(web_dir)])
|
||||
if web_commitid:
|
||||
subprocess.run(["git", "checkout", web_commitid], cwd=web_dir, check=True)
|
||||
|
||||
if not (web_dir / "node_modules").exists():
|
||||
pkg_manager = json.loads((web_dir / "package.json").read_text()).get("packageManager", "pnpm")
|
||||
run(["npm", "install", "--silent", "--global", "--force", pkg_manager])
|
||||
subprocess.run(["pnpm", "config", "set", "store-dir", "./.pnpm-store"],
|
||||
cwd=web_dir, check=True)
|
||||
subprocess.run(["pnpm", "install"], cwd=web_dir, check=True)
|
||||
subprocess.run(["pnpm", "exec", "playwright", "install", "--with-deps", "chromium"],
|
||||
cwd=web_dir, check=True)
|
||||
|
||||
# init ocis
|
||||
run([str(ocis_bin), "init", "--insecure", "true"])
|
||||
shutil.copy(
|
||||
repo_root / "tests/config/drone/app-registry.yaml",
|
||||
ocis_config_dir / "app-registry.yaml",
|
||||
)
|
||||
|
||||
# Trust the self-signed cert system-wide so Chromium and node-fetch
|
||||
# don't produce TLS handshake errors that load the server
|
||||
ocis_cert = Path.home() / ".ocis/proxy/server.crt"
|
||||
if ocis_cert.exists():
|
||||
subprocess.run(
|
||||
["sudo", "cp", str(ocis_cert), "/usr/local/share/ca-certificates/ocis.crt"],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(["sudo", "update-ca-certificates"], check=True)
|
||||
|
||||
# Patch web UI config: replace Drone Docker service name with our URL
|
||||
drone_web_cfg = json.loads(
|
||||
(repo_root / "tests/config/drone/ocis-config.json").read_text()
|
||||
)
|
||||
|
||||
def _patch_urls(obj, old, new):
|
||||
if isinstance(obj, dict):
|
||||
return {k: _patch_urls(v, old, new) for k, v in obj.items()}
|
||||
if isinstance(obj, list):
|
||||
return [_patch_urls(v, old, new) for v in obj]
|
||||
if isinstance(obj, str):
|
||||
return obj.replace(old, new)
|
||||
return obj
|
||||
|
||||
gha_web_cfg = _patch_urls(drone_web_cfg, "https://ocis-server:9200", ocis_url)
|
||||
gha_web_cfg_path = ocis_config_dir / "web-ui-config.json"
|
||||
gha_web_cfg_path.write_text(json.dumps(gha_web_cfg, indent=2))
|
||||
|
||||
server_env = {
|
||||
**os.environ,
|
||||
# core — matches drone ocisServer()
|
||||
"OCIS_URL": ocis_url,
|
||||
"OCIS_CONFIG_DIR": str(ocis_config_dir),
|
||||
"STORAGE_USERS_DRIVER": "ocis",
|
||||
"PROXY_ENABLE_BASIC_AUTH": "true",
|
||||
|
||||
"OCIS_LOG_LEVEL": "error",
|
||||
"IDM_CREATE_DEMO_USERS": "true",
|
||||
"IDM_ADMIN_PASSWORD": "admin",
|
||||
"FRONTEND_SEARCH_MIN_LENGTH": "2",
|
||||
"OCIS_ASYNC_UPLOADS": "true",
|
||||
"OCIS_EVENTS_ENABLE_TLS": "false",
|
||||
"NATS_NATS_HOST": "0.0.0.0",
|
||||
"NATS_NATS_PORT": "9233",
|
||||
"OCIS_JWT_SECRET": "some-ocis-jwt-secret",
|
||||
"EVENTHISTORY_STORE": "memory",
|
||||
"OCIS_TRANSLATION_PATH": str(repo_root / "tests/config/translations"),
|
||||
"WEB_UI_CONFIG_FILE": str(gha_web_cfg_path),
|
||||
"THUMBNAILS_TXT_FONTMAP_FILE": str(repo_root / "tests/config/drone/fontsMap.json"),
|
||||
# extra_server_environment — matches drone e2eTestPipeline()
|
||||
"OCIS_PASSWORD_POLICY_BANNED_PASSWORDS_LIST": str(repo_root / "tests/config/drone/banned-password-list.txt"),
|
||||
"GRAPH_AVAILABLE_ROLES": "b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5,a8d5fe5e-96e3-418d-825b-534dbdf22b99,fb6c3e19-e378-47e5-b277-9732f9de6e21,58c63c02-1d89-4572-916a-870abc5a1b7d,2d00ce52-1fc2-4dbc-8b95-a73b73395f5a,1c996275-f1c9-4e71-abdf-a42f6495e960,312c0871-5ef7-4b3a-85b6-0e4074c64049,aa97fe03-7980-45ac-9e50-b325749fd7e6,63e64e19-8d43-42ec-a738-2b6af2610efa",
|
||||
"FRONTEND_CONFIGURABLE_NOTIFICATIONS": "true",
|
||||
# debug addresses
|
||||
"ACTIVITYLOG_DEBUG_ADDR": "0.0.0.0:9197",
|
||||
"APP_PROVIDER_DEBUG_ADDR": "0.0.0.0:9165",
|
||||
"APP_REGISTRY_DEBUG_ADDR": "0.0.0.0:9243",
|
||||
"AUTH_BASIC_DEBUG_ADDR": "0.0.0.0:9147",
|
||||
"AUTH_MACHINE_DEBUG_ADDR": "0.0.0.0:9167",
|
||||
"AUTH_SERVICE_DEBUG_ADDR": "0.0.0.0:9198",
|
||||
"CLIENTLOG_DEBUG_ADDR": "0.0.0.0:9260",
|
||||
"EVENTHISTORY_DEBUG_ADDR": "0.0.0.0:9270",
|
||||
"FRONTEND_DEBUG_ADDR": "0.0.0.0:9141",
|
||||
"GATEWAY_DEBUG_ADDR": "0.0.0.0:9143",
|
||||
"GRAPH_DEBUG_ADDR": "0.0.0.0:9124",
|
||||
"GROUPS_DEBUG_ADDR": "0.0.0.0:9161",
|
||||
"IDM_DEBUG_ADDR": "0.0.0.0:9239",
|
||||
"IDP_DEBUG_ADDR": "0.0.0.0:9134",
|
||||
"INVITATIONS_DEBUG_ADDR": "0.0.0.0:9269",
|
||||
"NATS_DEBUG_ADDR": "0.0.0.0:9234",
|
||||
"OCDAV_DEBUG_ADDR": "0.0.0.0:9163",
|
||||
"OCM_DEBUG_ADDR": "0.0.0.0:9281",
|
||||
"OCS_DEBUG_ADDR": "0.0.0.0:9114",
|
||||
"POSTPROCESSING_DEBUG_ADDR": "0.0.0.0:9255",
|
||||
"PROXY_DEBUG_ADDR": "0.0.0.0:9205",
|
||||
"SEARCH_DEBUG_ADDR": "0.0.0.0:9224",
|
||||
"SETTINGS_DEBUG_ADDR": "0.0.0.0:9194",
|
||||
"SHARING_DEBUG_ADDR": "0.0.0.0:9151",
|
||||
"SSE_DEBUG_ADDR": "0.0.0.0:9139",
|
||||
"STORAGE_PUBLICLINK_DEBUG_ADDR": "0.0.0.0:9179",
|
||||
"STORAGE_SHARES_DEBUG_ADDR": "0.0.0.0:9156",
|
||||
"STORAGE_SYSTEM_DEBUG_ADDR": "0.0.0.0:9217",
|
||||
"STORAGE_USERS_DEBUG_ADDR": "0.0.0.0:9159",
|
||||
"THUMBNAILS_DEBUG_ADDR": "0.0.0.0:9189",
|
||||
"USERLOG_DEBUG_ADDR": "0.0.0.0:9214",
|
||||
"USERS_DEBUG_ADDR": "0.0.0.0:9145",
|
||||
"WEB_DEBUG_ADDR": "0.0.0.0:9104",
|
||||
"WEBDAV_DEBUG_ADDR": "0.0.0.0:9119",
|
||||
"WEBFINGER_DEBUG_ADDR": "0.0.0.0:9279",
|
||||
}
|
||||
|
||||
if tika_needed:
|
||||
server_env.update({
|
||||
"FRONTEND_FULL_TEXT_SEARCH_ENABLED": "true",
|
||||
"SEARCH_EXTRACTOR_TYPE": "tika",
|
||||
"SEARCH_EXTRACTOR_TIKA_TIKA_URL": "http://localhost:9998",
|
||||
"SEARCH_EXTRACTOR_CS3SOURCE_INSECURE": "true",
|
||||
})
|
||||
|
||||
if keycloak_needed:
|
||||
server_env.update({
|
||||
"OCIS_EXCLUDE_RUN_SERVICES": "idp",
|
||||
"PROXY_AUTOPROVISION_ACCOUNTS": "true",
|
||||
"PROXY_ROLE_ASSIGNMENT_DRIVER": "oidc",
|
||||
"OCIS_OIDC_ISSUER": "https://localhost:8443/realms/oCIS",
|
||||
"PROXY_OIDC_REWRITE_WELLKNOWN": "true",
|
||||
"WEB_OIDC_CLIENT_ID": "web",
|
||||
"PROXY_USER_OIDC_CLAIM": "preferred_username",
|
||||
"PROXY_USER_CS3_CLAIM": "username",
|
||||
"OCIS_ADMIN_USER_ID": "",
|
||||
"GRAPH_ASSIGN_DEFAULT_USER_ROLE": "false",
|
||||
"GRAPH_USERNAME_MATCH": "none",
|
||||
"PROXY_CSP_CONFIG_FILE_LOCATION": str(repo_root / "tests/config/drone/csp.yaml"),
|
||||
"KEYCLOAK_DOMAIN": "localhost:8443",
|
||||
"IDM_CREATE_DEMO_USERS": "false",
|
||||
})
|
||||
|
||||
procs = []
|
||||
|
||||
print("Starting ocis...")
|
||||
if keycloak_needed:
|
||||
# external IdP: run ocis server directly (no ociswrapper)
|
||||
ocis_proc = subprocess.Popen(
|
||||
[str(ocis_bin), "server"],
|
||||
env=server_env,
|
||||
)
|
||||
else:
|
||||
ocis_proc = subprocess.Popen(
|
||||
[str(wrapper_bin), "serve",
|
||||
"--bin", str(ocis_bin),
|
||||
"--url", ocis_url,
|
||||
"--admin-username", "admin",
|
||||
"--admin-password", "admin"],
|
||||
env=server_env,
|
||||
)
|
||||
procs.append(ocis_proc)
|
||||
|
||||
def cleanup(*_):
|
||||
for p in procs:
|
||||
try:
|
||||
p.terminate()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
signal.signal(signal.SIGTERM, cleanup)
|
||||
signal.signal(signal.SIGINT, cleanup)
|
||||
|
||||
try:
|
||||
wait_for(lambda: ocis_healthy(ocis_url, use_basic_auth=not keycloak_needed), 300, "ocis")
|
||||
print("ocis ready.")
|
||||
|
||||
playwright_env = {
|
||||
**os.environ,
|
||||
"BASE_URL_OCIS": ocis_url,
|
||||
"HEADLESS": "true",
|
||||
"RETRY": "3",
|
||||
"SKIP_A11Y_TESTS": "true",
|
||||
"REPORT_TRACING": "true",
|
||||
"NODE_EXTRA_CA_CERTS": str(ocis_cert),
|
||||
"BROWSER": "chromium",
|
||||
}
|
||||
|
||||
if keycloak_needed:
|
||||
playwright_env.update({
|
||||
"KEYCLOAK": "true",
|
||||
"KEYCLOAK_HOST": "localhost:8443",
|
||||
})
|
||||
|
||||
print(f"Running e2e: {e2e_args}")
|
||||
result = subprocess.run(
|
||||
["bash", "run-e2e.sh"] + shlex.split(e2e_args),
|
||||
cwd=web_dir / "tests/e2e",
|
||||
env=playwright_env,
|
||||
)
|
||||
return result.returncode
|
||||
|
||||
finally:
|
||||
cleanup()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -119,6 +119,7 @@ LOCAL_API_TESTS = {
|
||||
"NOTIFICATIONS_SMTP_PORT": EMAIL_SMTP_PORT,
|
||||
"NOTIFICATIONS_SMTP_INSECURE": "true",
|
||||
"NOTIFICATIONS_SMTP_SENDER": EMAIL_SMTP_SENDER,
|
||||
"NOTIFICATIONS_DEBUG_ADDR": "0.0.0.0:9174",
|
||||
},
|
||||
},
|
||||
"authApp": {
|
||||
@@ -211,6 +212,7 @@ def base_server_env(repo_root: Path, ocis_url: str, ocis_config_dir: str) -> dic
|
||||
"OCIS_EVENTS_ENABLE_TLS": "false",
|
||||
"NATS_NATS_HOST": "0.0.0.0",
|
||||
"NATS_NATS_PORT": "9233",
|
||||
"MICRO_REGISTRY_ADDRESS": "127.0.0.1:9233",
|
||||
"OCIS_JWT_SECRET": "some-ocis-jwt-secret",
|
||||
"EVENTHISTORY_STORE": "memory",
|
||||
"OCIS_TRANSLATION_PATH": str(repo_root / "tests/config/translations"),
|
||||
@@ -325,6 +327,20 @@ def clamav_healthy() -> bool:
|
||||
|
||||
|
||||
|
||||
def load_env_file(path: Path) -> dict:
|
||||
"""Parse a bash-style env file (export KEY=value) into a dict."""
|
||||
env = {}
|
||||
for line in path.read_text().splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#") or line.startswith("!"):
|
||||
continue
|
||||
line = line.removeprefix("export ").strip()
|
||||
if "=" in line:
|
||||
k, v = line.split("=", 1)
|
||||
env[k.strip()] = v.strip()
|
||||
return env
|
||||
|
||||
|
||||
def run(cmd: list, env: dict = None, check: bool = True):
|
||||
e = {**os.environ, **(env or {})}
|
||||
return subprocess.run(cmd, env=e, check=check)
|
||||
@@ -355,6 +371,8 @@ def main() -> int:
|
||||
|
||||
# generate IDP web assets (required for IDP service to start; matches drone ci-node-generate)
|
||||
run(["make", "-C", str(repo_root / "services/idp"), "ci-node-generate"])
|
||||
# download web UI assets (required for robots.txt and other static assets; no pnpm needed)
|
||||
run(["make", "-C", str(repo_root / "services/web"), "ci-node-generate"])
|
||||
|
||||
# build (ENABLE_VIPS=true when libvips-dev is installed, matching drone)
|
||||
build_env = {}
|
||||
@@ -458,14 +476,15 @@ def main() -> int:
|
||||
fed_env = {**os.environ}
|
||||
fed_env.update(base_server_env(repo_root, ocis_fed_url, str(fed_config_dir)))
|
||||
fed_env.update(cfg["extraServerEnvironment"])
|
||||
# load federation port mappings from canonical env file (single source of truth)
|
||||
fed_env.update(load_env_file(repo_root / "tests/config/local/.env-federation"))
|
||||
# CI-specific overrides
|
||||
fed_env.update({
|
||||
"OCIS_URL": ocis_fed_url,
|
||||
"PROXY_HTTP_ADDR": "0.0.0.0:10200",
|
||||
"OCIS_BASE_DATA_PATH": str(fed_data_dir),
|
||||
# use different ports to avoid conflicts with primary
|
||||
"GATEWAY_GRPC_ADDR": "0.0.0.0:10142",
|
||||
"NATS_NATS_PORT": "10233",
|
||||
"NATS_NATS_HOST": "0.0.0.0",
|
||||
"OCIS_CONFIG_DIR": str(fed_config_dir),
|
||||
"OCIS_RUNTIME_PORT": "10250",
|
||||
"MICRO_REGISTRY_ADDRESS": "127.0.0.1:10233",
|
||||
})
|
||||
|
||||
# init federation ocis with separate config
|
||||
@@ -646,13 +665,15 @@ def main() -> int:
|
||||
p = Path(ef_override)
|
||||
base_failures = p if p.is_absolute() else repo_root / p
|
||||
|
||||
# merge expected-failures-without-remotephp.md (drone does this)
|
||||
# merge expected-failures-without-remotephp.md only when not using remote.php
|
||||
# (mirrors drone.star: "" if run_with_remote_php else "cat ...without-remotephp.md >> ...")
|
||||
tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False)
|
||||
tmp.write(base_failures.read_text())
|
||||
without_rphp = repo_root / "tests/acceptance/expected-failures-without-remotephp.md"
|
||||
if without_rphp.exists():
|
||||
tmp.write("\n")
|
||||
tmp.write(without_rphp.read_text())
|
||||
if os.environ.get("WITH_REMOTE_PHP", "false").lower() != "true":
|
||||
without_rphp = repo_root / "tests/acceptance/expected-failures-without-remotephp.md"
|
||||
if without_rphp.exists():
|
||||
tmp.write("\n")
|
||||
tmp.write(without_rphp.read_text())
|
||||
tmp.close()
|
||||
|
||||
# run tests
|
||||
|
||||
@@ -89,14 +89,17 @@ export WEB_DEBUG_ADDR=localhost:10104
|
||||
export WEB_HTTP_ADDR=localhost:10100
|
||||
export WEBDAV_DEBUG_ADDR=127.0.0.1:10119
|
||||
export WEBDAV_HTTP_ADDR=127.0.0.1:10115
|
||||
export NOTIFICATIONS_DEBUG_ADDR=127.0.0.1:10174
|
||||
export WEBFINGER_DEBUG_ADDR=127.0.0.1:10279
|
||||
export WEBFINGER_HTTP_ADDR=127.0.0.1:10275
|
||||
export OCIS_SERVICE_ACCOUNT_ID=serviceaccount
|
||||
export OCIS_SERVICE_ACCOUNT_SECRET=serviceaccountsecret
|
||||
export OCIS_SERVICE_ACCOUNT_ID=service-account-id
|
||||
export OCIS_SERVICE_ACCOUNT_SECRET=service-account-secret
|
||||
export OCIS_DECOMPOSEDFS_PROPAGATOR=async
|
||||
export STORAGE_USERS_ASYNC_PROPAGATOR_PROPAGATION_DELAY=10s
|
||||
export TLS_INSECURE=true
|
||||
export OCIS_INSECURE=true
|
||||
export LDAP_GROUP_SUBSCRIPTION_FILTER_TYPE=any
|
||||
export LDAP_USER_SUBSCRIPTION_FILTER_TYPE=any
|
||||
export IDP_ACCESS_TOKEN_EXPIRATION=9000
|
||||
export GATEWAY_STORAGE_USERS_MOUNT_ID=storage-users-1
|
||||
export STORAGE_USERS_MOUNT_ID=storage-users-1
|
||||
@@ -106,6 +109,13 @@ export OCIS_LOG_LEVEL=info
|
||||
export OCIS_LOG_PRETTY=true
|
||||
export OCIS_LOG_COLOR=true
|
||||
export PROXY_ENABLE_BASIC_AUTH=true
|
||||
export FRONTEND_SEARCH_MIN_LENGTH=2
|
||||
export FRONTEND_CONFIGURABLE_NOTIFICATIONS=true
|
||||
export GRAPH_AVAILABLE_ROLES=b1e2218d-eef8-4d4c-b82d-0f1a1b48f3b5,a8d5fe5e-96e3-418d-825b-534dbdf22b99,fb6c3e19-e378-47e5-b277-9732f9de6e21,58c63c02-1d89-4572-916a-870abc5a1b7d,2d00ce52-1fc2-4dbc-8b95-a73b73395f5a,1c996275-f1c9-4e71-abdf-a42f6495e960,312c0871-5ef7-4b3a-85b6-0e4074c64049,aa97fe03-7980-45ac-9e50-b325749fd7e6,63e64e19-8d43-42ec-a738-2b6af2610efa
|
||||
export COLLABORATION_WOPIAPP_SECRET=some-wopi-secret
|
||||
export SEARCH_EXTRACTOR_TYPE=tika
|
||||
export SEARCH_EXTRACTOR_TIKA_TIKA_URL=http://localhost:9998
|
||||
export SEARCH_EXTRACTOR_CS3SOURCE_INSECURE=true
|
||||
export IDM_CREATE_DEMO_USERS=true
|
||||
export OCIS_ADMIN_USER_ID=some-admin-user-id-0000-000000000000
|
||||
export IDM_ADMIN_PASSWORD=admin
|
||||
@@ -122,4 +132,4 @@ export USERS_LDAP_BIND_PASSWORD=some-ldap-reva-password
|
||||
export AUTH_BASIC_LDAP_BIND_PASSWORD=some-ldap-reva-password
|
||||
export IDM_IDPSVC_PASSWORD=some-ldap-idp-password
|
||||
export IDP_LDAP_BIND_PASSWORD=some-ldap-idp-password
|
||||
export GRAPH_APPLICATION_ID=application-1export
|
||||
export GRAPH_APPLICATION_ID=application-1
|
||||
+9
-3
@@ -128,12 +128,18 @@ type Symlink interface {
|
||||
Readlink(link string) (string, error)
|
||||
}
|
||||
|
||||
// Change abstract the FileInfo change related operations in a storage-agnostic
|
||||
// interface as an extension to the Basic interface
|
||||
type Change interface {
|
||||
// Chmod abstracts the logic around changing file modes.
|
||||
type Chmod interface {
|
||||
// Chmod changes the mode of the named file to mode. If the file is a
|
||||
// symbolic link, it changes the mode of the link's target.
|
||||
Chmod(name string, mode os.FileMode) error
|
||||
}
|
||||
|
||||
// Change abstract the FileInfo change related operations in a storage-agnostic
|
||||
// interface as an extension to the Basic interface
|
||||
type Change interface {
|
||||
Chmod
|
||||
|
||||
// Lchown changes the numeric uid and gid of the named file. If the file is
|
||||
// a symbolic link, it changes the uid and gid of the link itself.
|
||||
Lchown(name string, uid, gid int) error
|
||||
|
||||
+14
@@ -1,6 +1,7 @@
|
||||
package chroot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -200,6 +201,19 @@ func (fs *ChrootHelper) Readlink(link string) (string, error) {
|
||||
return string(os.PathSeparator) + target, nil
|
||||
}
|
||||
|
||||
func (fs *ChrootHelper) Chmod(path string, mode os.FileMode) error {
|
||||
fullpath, err := fs.underlyingPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, ok := fs.underlying.(billy.Chmod)
|
||||
if !ok {
|
||||
return errors.New("underlying fs does not implement billy.Chmod")
|
||||
}
|
||||
return c.Chmod(fullpath, mode)
|
||||
}
|
||||
|
||||
func (fs *ChrootHelper) Chroot(path string) (billy.Filesystem, error) {
|
||||
fullpath, err := fs.underlyingPath(path)
|
||||
if err != nil {
|
||||
|
||||
+10
-1
@@ -13,7 +13,7 @@ type Polyfill struct {
|
||||
c capabilities
|
||||
}
|
||||
|
||||
type capabilities struct{ tempfile, dir, symlink, chroot bool }
|
||||
type capabilities struct{ tempfile, dir, symlink, chroot, chmod bool }
|
||||
|
||||
// New creates a new filesystem wrapping up 'fs' the intercepts all the calls
|
||||
// made and errors if fs doesn't implement any of the billy interfaces.
|
||||
@@ -28,6 +28,7 @@ func New(fs billy.Basic) billy.Filesystem {
|
||||
_, h.c.dir = h.Basic.(billy.Dir)
|
||||
_, h.c.symlink = h.Basic.(billy.Symlink)
|
||||
_, h.c.chroot = h.Basic.(billy.Chroot)
|
||||
_, h.c.chmod = h.Basic.(billy.Chmod)
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -87,6 +88,14 @@ func (h *Polyfill) Chroot(path string) (billy.Filesystem, error) {
|
||||
return h.Basic.(billy.Chroot).Chroot(path)
|
||||
}
|
||||
|
||||
func (h *Polyfill) Chmod(path string, mode os.FileMode) error {
|
||||
if !h.c.chmod {
|
||||
return billy.ErrNotSupported
|
||||
}
|
||||
|
||||
return h.Basic.(billy.Chmod).Chmod(path, mode)
|
||||
}
|
||||
|
||||
func (h *Polyfill) Root() string {
|
||||
if !h.c.chroot {
|
||||
return string(filepath.Separator)
|
||||
|
||||
+4
@@ -177,6 +177,10 @@ func (fs *Memory) Remove(filename string) error {
|
||||
return fs.s.Remove(filename)
|
||||
}
|
||||
|
||||
func (fs *Memory) Chmod(path string, mode os.FileMode) error {
|
||||
return fs.s.Chmod(path, mode)
|
||||
}
|
||||
|
||||
// Falls back to Go's filepath.Join, which works differently depending on the
|
||||
// OS where the code is being executed.
|
||||
func (fs *Memory) Join(elem ...string) string {
|
||||
|
||||
+12
@@ -169,6 +169,18 @@ func (s *storage) Remove(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *storage) Chmod(path string, mode os.FileMode) error {
|
||||
path = clean(path)
|
||||
|
||||
f, has := s.Get(path)
|
||||
if !has {
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
f.mode = mode
|
||||
return nil
|
||||
}
|
||||
|
||||
func clean(path string) string {
|
||||
return filepath.Clean(filepath.FromSlash(path))
|
||||
}
|
||||
|
||||
+16
@@ -126,6 +126,14 @@ func (fs *BoundOS) TempFile(dir, prefix string) (billy.File, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = os.Stat(dir)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
err = os.MkdirAll(dir, defaultDirectoryMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempFile(dir, prefix)
|
||||
@@ -176,6 +184,14 @@ func (fs *BoundOS) Readlink(link string) (string, error) {
|
||||
return os.Readlink(link)
|
||||
}
|
||||
|
||||
func (fs *BoundOS) Chmod(path string, mode os.FileMode) error {
|
||||
abspath, err := fs.abs(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Chmod(abspath, mode)
|
||||
}
|
||||
|
||||
// Chroot returns a new OS filesystem, with the base dir set to the
|
||||
// result of joining the provided path with the underlying base dir.
|
||||
func (fs *BoundOS) Chroot(path string) (billy.Filesystem, error) {
|
||||
|
||||
+4
@@ -74,6 +74,10 @@ func (fs *ChrootOS) Remove(filename string) error {
|
||||
return os.Remove(filename)
|
||||
}
|
||||
|
||||
func (fs *ChrootOS) Chmod(path string, mode os.FileMode) error {
|
||||
return os.Chmod(path, mode)
|
||||
}
|
||||
|
||||
func (fs *ChrootOS) TempFile(dir, prefix string) (billy.File, error) {
|
||||
if err := fs.createDir(dir + string(os.PathSeparator)); err != nil {
|
||||
return nil, err
|
||||
|
||||
+7
-3
@@ -91,8 +91,8 @@ func readVersion(idx *MemoryIndex, r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if v > VersionSupported {
|
||||
return ErrUnsupportedVersion
|
||||
if v != VersionSupported {
|
||||
return fmt.Errorf("%w: v%d", ErrUnsupportedVersion, v)
|
||||
}
|
||||
|
||||
idx.Version = v
|
||||
@@ -106,6 +106,10 @@ func readFanout(idx *MemoryIndex, r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if k > 0 && n < idx.Fanout[k-1] {
|
||||
return fmt.Errorf("%w: fanout table is not monotonically non-decreasing at entry %d", ErrMalformedIdxFile, k)
|
||||
}
|
||||
|
||||
idx.Fanout[k] = n
|
||||
idx.FanoutMapping[k] = noMapping
|
||||
}
|
||||
@@ -155,7 +159,7 @@ func readCRC32(idx *MemoryIndex, r io.Reader) error {
|
||||
}
|
||||
|
||||
func readOffsets(idx *MemoryIndex, r io.Reader) error {
|
||||
var o64cnt int
|
||||
var o64cnt int64
|
||||
for k := 0; k < fanout; k++ {
|
||||
if pos := idx.FanoutMapping[k]; pos != noMapping {
|
||||
if _, err := io.ReadFull(r, idx.Offset32[pos]); err != nil {
|
||||
|
||||
+71
-39
@@ -4,8 +4,8 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -26,12 +26,14 @@ var (
|
||||
ErrInvalidChecksum = errors.New("invalid checksum")
|
||||
// ErrUnknownExtension is returned when an index extension is encountered that is considered mandatory
|
||||
ErrUnknownExtension = errors.New("unknown extension")
|
||||
// ErrMalformedIndexFile is returned when the index file contents are
|
||||
// structurally invalid.
|
||||
ErrMalformedIndexFile = errors.New("index decoder: malformed index file")
|
||||
)
|
||||
|
||||
const (
|
||||
entryHeaderLength = 62
|
||||
entryExtended = 0x4000
|
||||
entryValid = 0x8000
|
||||
nameMask = 0xfff
|
||||
intentToAddMask = 1 << 13
|
||||
skipWorkTreeMask = 1 << 14
|
||||
@@ -140,33 +142,55 @@ func (d *Decoder) readEntry(idx *Index) (*Entry, error) {
|
||||
e.SkipWorktree = extended&skipWorkTreeMask != 0
|
||||
}
|
||||
|
||||
if err := d.readEntryName(idx, e, flags); err != nil {
|
||||
nameConsumed, err := d.readEntryName(idx, e, flags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return e, d.padEntry(idx, e, read)
|
||||
return e, d.padEntry(idx, e, read, nameConsumed)
|
||||
}
|
||||
|
||||
func (d *Decoder) readEntryName(idx *Index, e *Entry, flags uint16) error {
|
||||
var name string
|
||||
var err error
|
||||
|
||||
// readEntryName reads the entry path and sets e.Name. It returns the
|
||||
// number of bytes consumed from the stream for the name portion.
|
||||
func (d *Decoder) readEntryName(idx *Index, e *Entry, flags uint16) (int, error) {
|
||||
switch idx.Version {
|
||||
case 2, 3:
|
||||
len := flags & nameMask
|
||||
name, err = d.doReadEntryName(len)
|
||||
nameLen := flags & nameMask
|
||||
name, consumed, err := d.doReadEntryName(nameLen)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
e.Name = name
|
||||
return consumed, nil
|
||||
case 4:
|
||||
name, err = d.doReadEntryNameV4()
|
||||
name, err := d.doReadEntryNameV4()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
e.Name = name
|
||||
return 0, nil // V4 has no padding; consumed count unused
|
||||
default:
|
||||
return ErrUnsupportedVersion
|
||||
return 0, ErrUnsupportedVersion
|
||||
}
|
||||
}
|
||||
|
||||
// doReadEntryName reads the entry path for V2/V3 indexes. It returns the
|
||||
// name, the number of bytes consumed from the stream, and any error.
|
||||
// When nameLen equals nameMask (0xFFF), the name was too long to fit in
|
||||
// the 12-bit field and the real length is found by scanning for the NUL
|
||||
// terminator — matching C Git's strlen(name) fallback in create_from_disk.
|
||||
func (d *Decoder) doReadEntryName(nameLen uint16) (string, int, error) {
|
||||
if nameLen == nameMask {
|
||||
name, err := binary.ReadUntil(d.r, '\x00')
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return string(name), len(name) + 1, nil // +1 for the consumed NUL delimiter
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
e.Name = name
|
||||
return nil
|
||||
name := make([]byte, nameLen)
|
||||
_, err := io.ReadFull(d.r, name)
|
||||
return string(name), int(nameLen), err
|
||||
}
|
||||
|
||||
func (d *Decoder) doReadEntryNameV4() (string, error) {
|
||||
@@ -177,7 +201,14 @@ func (d *Decoder) doReadEntryNameV4() (string, error) {
|
||||
|
||||
var base string
|
||||
if d.lastEntry != nil {
|
||||
if l < 0 || int(l) > len(d.lastEntry.Name) {
|
||||
return "", fmt.Errorf("%w: invalid V4 entry name strip length %d (previous name length: %d)",
|
||||
ErrMalformedIndexFile, l, len(d.lastEntry.Name))
|
||||
}
|
||||
base = d.lastEntry.Name[:len(d.lastEntry.Name)-int(l)]
|
||||
} else if l > 0 {
|
||||
return "", fmt.Errorf("%w: non-zero strip length %d on first V4 entry",
|
||||
ErrMalformedIndexFile, l)
|
||||
}
|
||||
|
||||
name, err := binary.ReadUntil(d.r, '\x00')
|
||||
@@ -188,24 +219,23 @@ func (d *Decoder) doReadEntryNameV4() (string, error) {
|
||||
return base + string(name), nil
|
||||
}
|
||||
|
||||
func (d *Decoder) doReadEntryName(len uint16) (string, error) {
|
||||
name := make([]byte, len)
|
||||
_, err := io.ReadFull(d.r, name)
|
||||
|
||||
return string(name), err
|
||||
}
|
||||
|
||||
// Index entries are padded out to the next 8 byte alignment
|
||||
// for historical reasons related to how C Git read the files.
|
||||
func (d *Decoder) padEntry(idx *Index, e *Entry, read int) error {
|
||||
// padEntry discards NUL padding bytes that follow each V2/V3 entry on
|
||||
// disk. nameConsumed is the number of stream bytes consumed while reading
|
||||
// the entry name (which may exceed len(e.Name) when a NUL terminator was
|
||||
// consumed for long names where the 12-bit length field overflowed).
|
||||
func (d *Decoder) padEntry(idx *Index, e *Entry, read, nameConsumed int) error {
|
||||
if idx.Version == 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
entrySize := read + len(e.Name)
|
||||
padLen := 8 - entrySize%8
|
||||
_, err := io.CopyN(io.Discard, d.r, int64(padLen))
|
||||
return err
|
||||
padLen -= nameConsumed - len(e.Name)
|
||||
if padLen > 0 {
|
||||
_, err := io.CopyN(io.Discard, d.r, int64(padLen))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Decoder) readExtensions(idx *Index) error {
|
||||
@@ -312,7 +342,7 @@ func (d *Decoder) readChecksum(expected []byte) error {
|
||||
}
|
||||
|
||||
func validateHeader(r io.Reader) (version uint32, err error) {
|
||||
var s = make([]byte, 4)
|
||||
s := make([]byte, 4)
|
||||
if _, err := io.ReadFull(r, s); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -376,24 +406,26 @@ func (d *treeExtensionDecoder) readEntry() (*TreeEntry, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// An entry can be in an invalidated state and is represented by having a
|
||||
// negative number in the entry_count field.
|
||||
if i == -1 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
e.Entries = i
|
||||
trees, err := binary.ReadUntil(d.r, '\n')
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
i, err = strconv.Atoi(string(trees))
|
||||
subtrees, err := strconv.Atoi(string(trees))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
e.Trees = i
|
||||
e.Trees = subtrees
|
||||
|
||||
// An entry can be in an invalidated state and is represented by having a
|
||||
// negative number in the entry_count field. In this case, there is no
|
||||
// object name and the next entry starts immediately after the newline.
|
||||
if i < 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = io.ReadFull(d.r, e.Hash[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+25
-14
@@ -5,9 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing/hash"
|
||||
@@ -160,26 +158,39 @@ func (e *Encoder) encodeEntryName(entry *Entry) error {
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeEntryNameV4(entry *Entry) error {
|
||||
name := entry.Name
|
||||
l := 0
|
||||
// V4 prefix compression: find the longest common prefix between the
|
||||
// previous entry's name and the current one. The strip length tells
|
||||
// the decoder how many bytes to remove from the end of the previous
|
||||
// name, and the suffix is the remainder of the current name.
|
||||
prefix := 0
|
||||
if e.lastEntry != nil {
|
||||
dir := path.Dir(e.lastEntry.Name) + "/"
|
||||
if strings.HasPrefix(entry.Name, dir) {
|
||||
l = len(e.lastEntry.Name) - len(dir)
|
||||
name = strings.TrimPrefix(entry.Name, dir)
|
||||
} else {
|
||||
l = len(e.lastEntry.Name)
|
||||
}
|
||||
prefix = commonPrefixLen(e.lastEntry.Name, entry.Name)
|
||||
}
|
||||
stripLen := 0
|
||||
if e.lastEntry != nil {
|
||||
stripLen = len(e.lastEntry.Name) - prefix
|
||||
}
|
||||
|
||||
e.lastEntry = entry
|
||||
|
||||
err := binary.WriteVariableWidthInt(e.w, int64(l))
|
||||
if err != nil {
|
||||
if err := binary.WriteVariableWidthInt(e.w, int64(stripLen)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return binary.Write(e.w, []byte(name+string('\x00')))
|
||||
suffix := entry.Name[prefix:]
|
||||
return binary.Write(e.w, append([]byte(suffix), '\x00'))
|
||||
}
|
||||
|
||||
// commonPrefixLen returns the length of the longest common byte prefix
|
||||
// between a and b.
|
||||
func commonPrefixLen(a, b string) int {
|
||||
n := min(len(b), len(a))
|
||||
for i := range n {
|
||||
if a[i] != b[i] {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeRawExtension(signature string, data []byte) error {
|
||||
|
||||
+2
@@ -54,6 +54,8 @@ type Index struct {
|
||||
ResolveUndo *ResolveUndo
|
||||
// EndOfIndexEntry represents the 'End of Index Entry' extension
|
||||
EndOfIndexEntry *EndOfIndexEntry
|
||||
// ModTime is the modification time of the index file
|
||||
ModTime time.Time
|
||||
}
|
||||
|
||||
// Add creates a new Entry and returns it. The caller should first check that
|
||||
|
||||
+6
@@ -208,6 +208,12 @@ func Open(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
|
||||
return nil, ErrRepositoryNotExists
|
||||
}
|
||||
|
||||
cfg, err := s.Config()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = verifyExtensions(s, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
cfgformat "github.com/go-git/go-git/v5/plumbing/format/config"
|
||||
"github.com/go-git/go-git/v5/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnsupportedExtensionRepositoryFormatVersion represents when an
|
||||
// extension being used is not compatible with the repository's
|
||||
// core.repositoryFormatVersion.
|
||||
ErrUnsupportedExtensionRepositoryFormatVersion = errors.New("core.repositoryformatversion does not support extension")
|
||||
|
||||
// ErrUnsupportedRepositoryFormatVersion represents when an repository
|
||||
// is using a format version that is not supported.
|
||||
ErrUnsupportedRepositoryFormatVersion = errors.New("core.repositoryformatversion not supported")
|
||||
|
||||
// ErrUnknownExtension represents when a repository has an extension
|
||||
// which is unknown or unsupported by go-git.
|
||||
ErrUnknownExtension = errors.New("unknown extension")
|
||||
|
||||
// builtinExtensions defines the Git extensions that are supported by
|
||||
// the core go-git implementation.
|
||||
//
|
||||
// Some extensions are storage-specific, those are defined by the Storers
|
||||
// themselves by implementing the ExtensionChecker interface.
|
||||
builtinExtensions = map[string]struct{}{
|
||||
// noop does not change git’s behavior at all.
|
||||
// It is useful only for testing format-1 compatibility.
|
||||
//
|
||||
// This extension is respected regardless of the
|
||||
// core.repositoryFormatVersion setting.
|
||||
"noop": {},
|
||||
|
||||
// noop-v1 does not change git’s behavior at all.
|
||||
// It is useful only for testing format-1 compatibility.
|
||||
"noop-v1": {},
|
||||
}
|
||||
|
||||
// Some Git extensions were supported upstream before the introduction
|
||||
// of repositoryformatversion. These are the only extensions that can be
|
||||
// enabled while core.repositoryformatversion is unset or set to 0.
|
||||
extensionsValidForV0 = map[string]struct{}{
|
||||
"noop": {},
|
||||
"partialClone": {},
|
||||
"preciousObjects": {},
|
||||
"worktreeConfig": {},
|
||||
}
|
||||
)
|
||||
|
||||
type extension struct {
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
func extensions(cfg *config.Config) []extension {
|
||||
if cfg == nil || cfg.Raw == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !cfg.Raw.HasSection("extensions") {
|
||||
return nil
|
||||
}
|
||||
|
||||
section := cfg.Raw.Section("extensions")
|
||||
out := make([]extension, 0, len(section.Options))
|
||||
for _, opt := range section.Options {
|
||||
out = append(out, extension{name: strings.ToLower(opt.Key), value: strings.ToLower(opt.Value)})
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func verifyExtensions(st storage.Storer, cfg *config.Config) error {
|
||||
needed := extensions(cfg)
|
||||
|
||||
switch cfg.Core.RepositoryFormatVersion {
|
||||
case "", cfgformat.Version_0, cfgformat.Version_1:
|
||||
default:
|
||||
return fmt.Errorf("%w: %q",
|
||||
ErrUnsupportedRepositoryFormatVersion,
|
||||
cfg.Core.RepositoryFormatVersion)
|
||||
}
|
||||
|
||||
if len(needed) > 0 {
|
||||
if cfg.Core.RepositoryFormatVersion == cfgformat.Version_0 ||
|
||||
cfg.Core.RepositoryFormatVersion == "" {
|
||||
var unsupported []string
|
||||
for _, ext := range needed {
|
||||
if _, ok := extensionsValidForV0[ext.name]; !ok {
|
||||
unsupported = append(unsupported, ext.name)
|
||||
}
|
||||
}
|
||||
if len(unsupported) > 0 {
|
||||
return fmt.Errorf("%w: %s",
|
||||
ErrUnsupportedExtensionRepositoryFormatVersion,
|
||||
strings.Join(unsupported, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
var missing []string
|
||||
for _, ext := range needed {
|
||||
if _, ok := builtinExtensions[ext.name]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
missing = append(missing, ext.name)
|
||||
}
|
||||
|
||||
if len(missing) > 0 {
|
||||
return fmt.Errorf("%w: %s", ErrUnknownExtension, strings.Join(missing, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+23
-2
@@ -3,6 +3,7 @@ package dotgit
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
@@ -137,14 +138,22 @@ func (w *PackWriter) save() error {
|
||||
}
|
||||
|
||||
if err := w.encodeIdx(idx); err != nil {
|
||||
_ = idx.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := idx.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
fixPermissions(w.fs, fmt.Sprintf("%s.idx", base))
|
||||
|
||||
return w.fs.Rename(w.fw.Name(), fmt.Sprintf("%s.pack", base))
|
||||
packPath := fmt.Sprintf("%s.pack", base)
|
||||
if err := w.fs.Rename(w.fw.Name(), packPath); err != nil {
|
||||
return err
|
||||
}
|
||||
fixPermissions(w.fs, packPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *PackWriter) encodeIdx(writer io.Writer) error {
|
||||
@@ -281,5 +290,17 @@ func (w *ObjectWriter) save() error {
|
||||
hex := w.Hash().String()
|
||||
file := w.fs.Join(objectsPath, hex[0:2], hex[2:hash.HexSize])
|
||||
|
||||
return w.fs.Rename(w.f.Name(), file)
|
||||
// Loose objects are content addressable, if they already exist
|
||||
// we can safely delete the temporary file and short-circuit the
|
||||
// operation.
|
||||
if _, err := w.fs.Stat(file); err == nil || os.IsExist(err) {
|
||||
return w.fs.Remove(w.f.Name())
|
||||
}
|
||||
|
||||
if err := w.fs.Rename(w.f.Name(), file); err != nil {
|
||||
return err
|
||||
}
|
||||
fixPermissions(w.fs, file)
|
||||
|
||||
return nil
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
//go:build !windows
|
||||
|
||||
package dotgit
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-billy/v5"
|
||||
"github.com/go-git/go-git/v5/utils/trace"
|
||||
)
|
||||
|
||||
func fixPermissions(fs billy.Filesystem, path string) {
|
||||
if chmodFS, ok := fs.(billy.Chmod); ok {
|
||||
if err := chmodFS.Chmod(path, 0o444); err != nil {
|
||||
trace.General.Printf("failed to chmod %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isReadOnly(fs billy.Filesystem, path string) (bool, error) {
|
||||
fi, err := fs.Stat(path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if fi.Mode().Perm() == 0o444 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
//go:build windows
|
||||
|
||||
package dotgit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-git/go-billy/v5"
|
||||
"github.com/go-git/go-git/v5/utils/trace"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func fixPermissions(fs billy.Filesystem, path string) {
|
||||
fullpath := filepath.Join(fs.Root(), path)
|
||||
p, err := windows.UTF16PtrFromString(fullpath)
|
||||
if err != nil {
|
||||
trace.General.Printf("failed to chmod %s: %v", fullpath, err)
|
||||
return
|
||||
}
|
||||
|
||||
attrs, err := windows.GetFileAttributes(p)
|
||||
if err != nil {
|
||||
trace.General.Printf("failed to chmod %s: %v", fullpath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if attrs&windows.FILE_ATTRIBUTE_READONLY != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
err = windows.SetFileAttributes(p,
|
||||
attrs|windows.FILE_ATTRIBUTE_READONLY,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
trace.General.Printf("failed to chmod %s: %v", fullpath, err)
|
||||
}
|
||||
}
|
||||
|
||||
func isReadOnly(fs billy.Filesystem, path string) (bool, error) {
|
||||
fullpath := filepath.Join(fs.Root(), path)
|
||||
p, err := windows.UTF16PtrFromString(fullpath)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%w: %q", err, fullpath)
|
||||
}
|
||||
|
||||
attrs, err := windows.GetFileAttributes(p)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%w: %q", err, fullpath)
|
||||
}
|
||||
|
||||
if attrs&windows.FILE_ATTRIBUTE_READONLY != 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
+5
@@ -48,6 +48,11 @@ func (s *IndexStorage) Index() (i *index.Index, err error) {
|
||||
|
||||
defer ioutil.CheckClose(f, &err)
|
||||
|
||||
fi, statErr := s.dir.Fs().Stat(f.Name())
|
||||
if statErr == nil {
|
||||
idx.ModTime = fi.ModTime()
|
||||
}
|
||||
|
||||
d := index.NewDecoder(f)
|
||||
err = d.Decode(idx)
|
||||
return idx, err
|
||||
|
||||
+4
@@ -69,7 +69,11 @@ type IndexStorage struct {
|
||||
index *index.Index
|
||||
}
|
||||
|
||||
// SetIndex stores the given index.
|
||||
// Note: this method sets idx.ModTime to simulate filesystem storage behavior.
|
||||
func (c *IndexStorage) SetIndex(idx *index.Index) error {
|
||||
// Set ModTime to enable racy git detection in the metadata optimization.
|
||||
idx.ModTime = time.Now()
|
||||
c.index = idx
|
||||
return nil
|
||||
}
|
||||
|
||||
+103
-5
@@ -4,9 +4,11 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/filemode"
|
||||
"github.com/go-git/go-git/v5/plumbing/format/index"
|
||||
"github.com/go-git/go-git/v5/utils/merkletrie/noder"
|
||||
|
||||
"github.com/go-git/go-billy/v5"
|
||||
@@ -16,6 +18,14 @@ var ignore = map[string]bool{
|
||||
".git": true,
|
||||
}
|
||||
|
||||
// Options contains configuration for the filesystem node.
|
||||
type Options struct {
|
||||
// Index is used to enable the metadata-first comparison optimization while
|
||||
// correctly handling the "racy git" condition. If no index is provided,
|
||||
// the function works without the optimization.
|
||||
Index *index.Index
|
||||
}
|
||||
|
||||
// The node represents a file or a directory in a billy.Filesystem. It
|
||||
// implements the interface noder.Noder of merkletrie package.
|
||||
//
|
||||
@@ -24,6 +34,8 @@ var ignore = map[string]bool{
|
||||
type node struct {
|
||||
fs billy.Filesystem
|
||||
submodules map[string]plumbing.Hash
|
||||
idx *index.Index
|
||||
idxMap map[string]*index.Entry
|
||||
|
||||
path string
|
||||
hash []byte
|
||||
@@ -31,6 +43,7 @@ type node struct {
|
||||
isDir bool
|
||||
mode os.FileMode
|
||||
size int64
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
// NewRootNode returns the root node based on a given billy.Filesystem.
|
||||
@@ -42,7 +55,41 @@ func NewRootNode(
|
||||
fs billy.Filesystem,
|
||||
submodules map[string]plumbing.Hash,
|
||||
) noder.Noder {
|
||||
return &node{fs: fs, submodules: submodules, isDir: true}
|
||||
return NewRootNodeWithOptions(fs, submodules, Options{})
|
||||
}
|
||||
|
||||
// NewRootNodeWithOptions returns the root node based on a given billy.Filesystem
|
||||
// with options to set an index. Providing an index enables the metadata-first
|
||||
// comparison optimization while correctly handling the "racy git" condition. If
|
||||
// no index is provided, the function works without the optimization.
|
||||
//
|
||||
// The index's ModTime field is used to detect the racy git condition. When a file's
|
||||
// mtime equals or is newer than the index ModTime, we must hash the file content
|
||||
// even if other metadata matches, because the file may have been modified in the
|
||||
// same second that the index was written.
|
||||
//
|
||||
// Reference: https://git-scm.com/docs/racy-git
|
||||
func NewRootNodeWithOptions(
|
||||
fs billy.Filesystem,
|
||||
submodules map[string]plumbing.Hash,
|
||||
options Options,
|
||||
) noder.Noder {
|
||||
var idxMap map[string]*index.Entry
|
||||
|
||||
if options.Index != nil {
|
||||
idxMap = make(map[string]*index.Entry, len(options.Index.Entries))
|
||||
for _, entry := range options.Index.Entries {
|
||||
idxMap[entry.Name] = entry
|
||||
}
|
||||
}
|
||||
|
||||
return &node{
|
||||
fs: fs,
|
||||
submodules: submodules,
|
||||
idx: options.Index,
|
||||
idxMap: idxMap,
|
||||
isDir: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Hash the hash of a filesystem is the result of concatenating the computed
|
||||
@@ -133,11 +180,14 @@ func (n *node) newChildNode(file os.FileInfo) (*node, error) {
|
||||
node := &node{
|
||||
fs: n.fs,
|
||||
submodules: n.submodules,
|
||||
idx: n.idx,
|
||||
idxMap: n.idxMap,
|
||||
|
||||
path: path,
|
||||
isDir: file.IsDir(),
|
||||
size: file.Size(),
|
||||
mode: file.Mode(),
|
||||
path: path,
|
||||
isDir: file.IsDir(),
|
||||
size: file.Size(),
|
||||
mode: file.Mode(),
|
||||
modTime: file.ModTime(),
|
||||
}
|
||||
|
||||
if _, isSubmodule := n.submodules[path]; isSubmodule {
|
||||
@@ -161,6 +211,16 @@ func (n *node) calculateHash() {
|
||||
n.hash = append(submoduleHash[:], filemode.Submodule.Bytes()...)
|
||||
return
|
||||
}
|
||||
|
||||
if n.idxMap != nil {
|
||||
if entry, ok := n.idxMap[n.path]; ok {
|
||||
if n.metadataMatches(entry) {
|
||||
n.hash = append(entry.Hash[:], mode.Bytes()...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var hash plumbing.Hash
|
||||
if n.mode&os.ModeSymlink != 0 {
|
||||
hash = n.doCalculateHashForSymlink()
|
||||
@@ -170,6 +230,44 @@ func (n *node) calculateHash() {
|
||||
n.hash = append(hash[:], mode.Bytes()...)
|
||||
}
|
||||
|
||||
func (n *node) metadataMatches(entry *index.Entry) bool {
|
||||
if entry == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if uint32(n.size) != entry.Size {
|
||||
return false
|
||||
}
|
||||
|
||||
if !n.modTime.IsZero() && !n.modTime.Equal(entry.ModifiedAt) {
|
||||
return false
|
||||
}
|
||||
|
||||
mode, err := filemode.NewFromOSFileMode(n.mode)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if mode != entry.Mode {
|
||||
return false
|
||||
}
|
||||
|
||||
if n.idx != nil && !n.idx.ModTime.IsZero() && !n.modTime.IsZero() {
|
||||
if !n.modTime.Before(n.idx.ModTime) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// If we couldn't perform the racy git check (idx is nil or idx.ModTime is zero),
|
||||
// we cannot safely rely on metadata alone — force content hashing.
|
||||
// This can occur with in-memory storage where the index file timestamp is unavailable.
|
||||
if n.idx == nil || n.idx.ModTime.IsZero() {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (n *node) doCalculateHashForRegular() plumbing.Hash {
|
||||
f, err := n.fs.Open(n.path)
|
||||
if err != nil {
|
||||
|
||||
+22
-11
@@ -385,7 +385,8 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string, files []string) ([]
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var removedFiles []string
|
||||
removedFiles := make([]string, 0, len(changes))
|
||||
filesMap := buildFilePathMap(files)
|
||||
for _, ch := range changes {
|
||||
a, err := ch.Action()
|
||||
if err != nil {
|
||||
@@ -407,7 +408,7 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string, files []string) ([]
|
||||
}
|
||||
|
||||
if len(files) > 0 {
|
||||
contains := inFiles(files, name)
|
||||
contains := inFiles(filesMap, name)
|
||||
if !contains {
|
||||
continue
|
||||
}
|
||||
@@ -436,15 +437,11 @@ func (w *Worktree) resetIndex(t *object.Tree, dirs []string, files []string) ([]
|
||||
return removedFiles, w.r.Storer.SetIndex(idx)
|
||||
}
|
||||
|
||||
func inFiles(files []string, v string) bool {
|
||||
// inFiles checks if the given file is in the list of files. The incoming filepaths in files should be cleaned before calling this function.
|
||||
func inFiles(files map[string]struct{}, v string) bool {
|
||||
v = filepath.Clean(v)
|
||||
for _, s := range files {
|
||||
if filepath.Clean(s) == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
_, exists := files[v]
|
||||
return exists
|
||||
}
|
||||
|
||||
func (w *Worktree) resetWorktree(t *object.Tree, files []string) error {
|
||||
@@ -459,6 +456,7 @@ func (w *Worktree) resetWorktree(t *object.Tree, files []string) error {
|
||||
}
|
||||
b := newIndexBuilder(idx)
|
||||
|
||||
filesMap := buildFilePathMap(files)
|
||||
for _, ch := range changes {
|
||||
if err := w.validChange(ch); err != nil {
|
||||
return err
|
||||
@@ -476,7 +474,7 @@ func (w *Worktree) resetWorktree(t *object.Tree, files []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
contains := inFiles(files, file)
|
||||
contains := inFiles(filesMap, file)
|
||||
if !contains {
|
||||
continue
|
||||
}
|
||||
@@ -1206,3 +1204,16 @@ func (b *indexBuilder) Add(e *index.Entry) {
|
||||
func (b *indexBuilder) Remove(name string) {
|
||||
delete(b.entries, filepath.ToSlash(name))
|
||||
}
|
||||
|
||||
// buildFilePathMap creates a map of cleaned file paths for efficient lookup.
|
||||
// Returns nil if the input slice is empty.
|
||||
func buildFilePathMap(files []string) map[string]struct{} {
|
||||
if len(files) == 0 {
|
||||
return nil
|
||||
}
|
||||
filesMap := make(map[string]struct{}, len(files))
|
||||
for _, f := range files {
|
||||
filesMap[filepath.Clean(f)] = struct{}{}
|
||||
}
|
||||
return filesMap
|
||||
}
|
||||
+1
-1
@@ -141,7 +141,7 @@ func (w *Worktree) diffStagingWithWorktree(reverse, excludeIgnoredChanges bool)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
to := filesystem.NewRootNode(w.Filesystem, submodules)
|
||||
to := filesystem.NewRootNodeWithOptions(w.Filesystem, submodules, filesystem.Options{Index: idx})
|
||||
|
||||
var c merkletrie.Changes
|
||||
if reverse {
|
||||
|
||||
Vendored
+3
-3
@@ -470,15 +470,15 @@ github.com/go-git/gcfg
|
||||
github.com/go-git/gcfg/scanner
|
||||
github.com/go-git/gcfg/token
|
||||
github.com/go-git/gcfg/types
|
||||
# github.com/go-git/go-billy/v5 v5.6.2
|
||||
## explicit; go 1.21
|
||||
# github.com/go-git/go-billy/v5 v5.8.0
|
||||
## explicit; go 1.24.0
|
||||
github.com/go-git/go-billy/v5
|
||||
github.com/go-git/go-billy/v5/helper/chroot
|
||||
github.com/go-git/go-billy/v5/helper/polyfill
|
||||
github.com/go-git/go-billy/v5/memfs
|
||||
github.com/go-git/go-billy/v5/osfs
|
||||
github.com/go-git/go-billy/v5/util
|
||||
# github.com/go-git/go-git/v5 v5.16.5
|
||||
# github.com/go-git/go-git/v5 v5.17.1
|
||||
## explicit; go 1.24.0
|
||||
github.com/go-git/go-git/v5
|
||||
github.com/go-git/go-git/v5/config
|
||||
|
||||
Reference in new issue
Block a user