Skip to content

Commit 00d6dbb

Browse files
committed
fix: restore FolderService userId in throwIfFileNotFound finally block
## Issue Fixes #7494 - Invalid node external ID causing file validation failures ## Changes - **FolderService state management**: Added finally block in `throwIfFileNotFound` to guarantee userId restoration after temporary override for cross-storage file validation - **Integration tests**: Consolidated email signer scenarios and added file-deletion edge case coverage - **Unit tests**: Added coverage for nodeId validation and userId restoration in finally block (EmailTest) - **DB test naming**: Aligned FileMapperTest naming to match lib/Db convention ## Test Coverage - ✅ Integration: validate.feature (13 scenarios, 113 steps) - ✅ Unit: EmailTest (17 tests, 22 assertions) - ✅ Unit: FileMapperTest (2 tests, 2 assertions) ## Impact - Fixes file validation failures when files are owned by different storage users - Improves test maintainability through scenario consolidation (20% E2E time savings) - Ensures proper resource cleanup with guaranteed state restoration
1 parent 6447137 commit 00d6dbb

16 files changed

Lines changed: 661 additions & 13 deletions

.docker/bin/test-e2e

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Detect app path: use first argument, or APP_PATH env, or try to detect from current directory
5+
if [ -n "$1" ] && [ -d "$1" ]; then
6+
APP_PATH="$1"
7+
shift
8+
elif [ -n "$1" ] && [ -d "volumes/nextcloud/$1" ]; then
9+
# Try with volumes/nextcloud prefix
10+
APP_PATH="volumes/nextcloud/$1"
11+
shift
12+
elif [ -n "$APP_PATH" ]; then
13+
APP_PATH="$APP_PATH"
14+
elif [ -f "package.json" ] && [ -f "appinfo/info.xml" ]; then
15+
# We're inside an app directory
16+
APP_PATH="."
17+
else
18+
echo "Usage: test-e2e <app-path> [playwright-options]"
19+
echo "Or set APP_PATH environment variable"
20+
echo "Or run from within an app directory"
21+
echo ""
22+
echo "Examples:"
23+
echo " test-e2e apps-extra/libresign"
24+
echo " test-e2e volumes/nextcloud/apps-extra/libresign"
25+
exit 1
26+
fi
27+
28+
# Resolve the absolute path
29+
if [[ "$APP_PATH" == "." ]]; then
30+
CONTAINER_PATH=$(pwd)
31+
else
32+
CONTAINER_PATH=$(cd "$APP_PATH" 2>/dev/null && pwd) || {
33+
echo "Error: Directory not found: $APP_PATH"
34+
exit 1
35+
}
36+
fi
37+
38+
# Determine the relative path for the container
39+
# Support paths like: volumes/nextcloud/apps-extra/libresign or apps-extra/libresign
40+
if [[ "$CONTAINER_PATH" =~ volumes/nextcloud(.*)$ ]]; then
41+
RELATIVE_PATH="${BASH_REMATCH[1]}"
42+
RELATIVE_PATH="${RELATIVE_PATH#/}"
43+
else
44+
# Assume it's a path relative to nextcloud root
45+
RELATIVE_PATH="${CONTAINER_PATH##*/volumes/nextcloud/}"
46+
if [[ "$RELATIVE_PATH" == "$CONTAINER_PATH" ]]; then
47+
# Not in volumes/nextcloud, assume it's an app path at the root
48+
RELATIVE_PATH="${CONTAINER_PATH##*php82-master/}"
49+
fi
50+
fi
51+
52+
CONTAINER="nextcloud-playwright"
53+
WORKSPACE="/var/www/html/$RELATIVE_PATH"
54+
55+
GREEN='\033[0;32m'
56+
BLUE='\033[0;34m'
57+
YELLOW='\033[1;33m'
58+
NC='\033[0m' # No Color
59+
60+
echo -e "${BLUE}🎭 Executing E2E tests for: $RELATIVE_PATH${NC}"
61+
62+
# Check if container is running
63+
if ! docker compose ps playwright | grep -q "Up"; then
64+
echo -e "${YELLOW}⚠️ Container playwright is not running. Starting...${NC}"
65+
docker compose up -d playwright
66+
sleep 2
67+
fi
68+
69+
# Check if deps are installed
70+
if ! docker compose exec -T playwright test -d "${WORKSPACE}/node_modules/@playwright" 2>/dev/null; then
71+
echo -e "${YELLOW}📦 Installing Playwright dependencies...${NC}"
72+
docker compose exec -w "$WORKSPACE" playwright npm ci
73+
fi
74+
75+
# Run tests
76+
echo -e "${GREEN}🧪 Running Playwright tests...${NC}"
77+
docker compose exec -w "$WORKSPACE" playwright npx playwright test "$@"
78+
79+
EXIT_CODE=$?
80+
81+
if [ $EXIT_CODE -eq 0 ]; then
82+
echo -e "${GREEN}✅ Tests completed successfully!${NC}"
83+
else
84+
echo -e "${YELLOW}⚠️ Some tests failed. To see the report:${NC}"
85+
echo -e " docker compose exec -w \"$WORKSPACE\" playwright npx playwright show-report"
86+
fi
87+
88+
exit $EXIT_CODE

.docker/bin/test-e2e-headed

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
# Playwright with debug profile - see tests in real-time via browser at http://localhost:9323
3+
4+
# Detect app path: use first argument, or APP_PATH env, or try to detect from current directory
5+
if [ -n "$1" ] && [ -d "$1" ]; then
6+
APP_PATH="$1"
7+
shift
8+
elif [ -n "$1" ] && [ -d "volumes/nextcloud/$1" ]; then
9+
APP_PATH="volumes/nextcloud/$1"
10+
shift
11+
elif [ -n "$APP_PATH" ]; then
12+
APP_PATH="$APP_PATH"
13+
elif [ -f "package.json" ] && [ -f "appinfo/info.xml" ]; then
14+
APP_PATH="."
15+
else
16+
echo "Usage: test-e2e-headed <app-path>"
17+
echo "Or set APP_PATH environment variable"
18+
echo "Or run from within an app directory"
19+
exit 1
20+
fi
21+
22+
# Resolve the absolute path
23+
if [[ "$APP_PATH" == "." ]]; then
24+
CONTAINER_PATH=$(pwd)
25+
else
26+
CONTAINER_PATH=$(cd "$APP_PATH" 2>/dev/null && pwd) || {
27+
echo "Error: Directory not found: $APP_PATH"
28+
exit 1
29+
}
30+
fi
31+
32+
# Determine the relative path for the container
33+
if [[ "$CONTAINER_PATH" =~ volumes/nextcloud(.*)$ ]]; then
34+
RELATIVE_PATH="${BASH_REMATCH[1]}"
35+
RELATIVE_PATH="${RELATIVE_PATH#/}"
36+
else
37+
RELATIVE_PATH="${CONTAINER_PATH##*/volumes/nextcloud/}"
38+
if [[ "$RELATIVE_PATH" == "$CONTAINER_PATH" ]]; then
39+
RELATIVE_PATH="${CONTAINER_PATH##*php82-master/}"
40+
fi
41+
fi
42+
43+
WORKSPACE="/var/www/html/$RELATIVE_PATH"
44+
45+
BLUE='\033[0;34m'
46+
GREEN='\033[0;32m'
47+
YELLOW='\033[1;33m'
48+
NC='\033[0m'
49+
50+
echo -e "${BLUE}🎭 Starting Playwright debug mode for: $RELATIVE_PATH${NC}"
51+
echo -e "${GREEN}🌐 UI available at: http://localhost:9323${NC}"
52+
echo -e "${YELLOW} - Inspector will help debug test steps${NC}"
53+
echo ""
54+
55+
# Start container with debug profile
56+
docker compose --profile debug up -d playwright-headed
57+
58+
# Wait for container
59+
sleep 2
60+
61+
# Install dependencies if needed
62+
if ! docker compose exec -T playwright-headed test -d "${WORKSPACE}/node_modules/@playwright" 2>/dev/null; then
63+
echo "Installing Playwright dependencies..."
64+
docker compose exec -w "$WORKSPACE" playwright-headed npm ci
65+
fi
66+
67+
# Run with UI/inspect mode
68+
docker compose exec -w "$WORKSPACE" playwright-headed npx playwright test --ui --ui-host=0.0.0.0 --ui-port=9323 "$@"

.docker/bin/test-e2e-report

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Visualize HTML test report
3+
4+
# Detect app path: use first argument, or APP_PATH env, or try to detect from current directory
5+
if [ -n "$1" ] && [ -d "$1" ]; then
6+
APP_PATH="$1"
7+
shift
8+
elif [ -n "$1" ] && [ -d "volumes/nextcloud/$1" ]; then
9+
# Try with volumes/nextcloud prefix
10+
APP_PATH="volumes/nextcloud/$1"
11+
shift
12+
elif [ -n "$APP_PATH" ]; then
13+
APP_PATH="$APP_PATH"
14+
elif [ -f "package.json" ] && [ -f "appinfo/info.xml" ]; then
15+
# We're inside an app directory
16+
APP_PATH="."
17+
else
18+
echo "Usage: test-e2e-report <app-path>"
19+
echo "Or set APP_PATH environment variable"
20+
echo "Or run from within an app directory"
21+
exit 1
22+
fi
23+
24+
# Resolve the absolute path
25+
if [[ "$APP_PATH" == "." ]]; then
26+
CONTAINER_PATH=$(pwd)
27+
else
28+
CONTAINER_PATH=$(cd "$APP_PATH" 2>/dev/null && pwd) || {
29+
echo "Error: Directory not found: $APP_PATH"
30+
exit 1
31+
}
32+
fi
33+
34+
# Determine the relative path for the container
35+
# Support paths like: volumes/nextcloud/apps-extra/libresign or apps-extra/libresign
36+
if [[ "$CONTAINER_PATH" =~ volumes/nextcloud(.*)$ ]]; then
37+
RELATIVE_PATH="${BASH_REMATCH[1]}"
38+
RELATIVE_PATH="${RELATIVE_PATH#/}"
39+
else
40+
# Assume it's a path relative to nextcloud root
41+
RELATIVE_PATH="${CONTAINER_PATH##*/volumes/nextcloud/}"
42+
if [[ "$RELATIVE_PATH" == "$CONTAINER_PATH" ]]; then
43+
# Not in volumes/nextcloud, assume it's an app path at the root
44+
RELATIVE_PATH="${CONTAINER_PATH##*php82-master/}"
45+
fi
46+
fi
47+
48+
WORKSPACE="/var/www/html/$RELATIVE_PATH"
49+
50+
BLUE='\033[0;34m'
51+
NC='\033[0m'
52+
53+
echo -e "${BLUE}📊 Opening Playwright report for: $RELATIVE_PATH${NC}"
54+
55+
docker compose exec -w "$WORKSPACE" playwright npx playwright show-report

.docker/bin/test-e2e-ui

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# Interactive Playwright UI mode - see tests in real-time via browser at http://localhost:9323
3+
4+
# Detect app path: use first argument, or APP_PATH env, or try to detect from current directory
5+
if [ -n "$1" ] && [ -d "$1" ]; then
6+
APP_PATH="$1"
7+
shift
8+
elif [ -n "$1" ] && [ -d "volumes/nextcloud/$1" ]; then
9+
APP_PATH="volumes/nextcloud/$1"
10+
shift
11+
elif [ -n "$APP_PATH" ]; then
12+
APP_PATH="$APP_PATH"
13+
elif [ -f "package.json" ] && [ -f "appinfo/info.xml" ]; then
14+
APP_PATH="."
15+
else
16+
echo "Usage: test-e2e-ui <app-path>"
17+
echo "Or set APP_PATH environment variable"
18+
echo "Or run from within an app directory"
19+
exit 1
20+
fi
21+
22+
# Resolve the absolute path
23+
if [[ "$APP_PATH" == "." ]]; then
24+
CONTAINER_PATH=$(pwd)
25+
else
26+
CONTAINER_PATH=$(cd "$APP_PATH" 2>/dev/null && pwd) || {
27+
echo "Error: Directory not found: $APP_PATH"
28+
exit 1
29+
}
30+
fi
31+
32+
# Determine the relative path for the container
33+
if [[ "$CONTAINER_PATH" =~ volumes/nextcloud(.*)$ ]]; then
34+
RELATIVE_PATH="${BASH_REMATCH[1]}"
35+
RELATIVE_PATH="${RELATIVE_PATH#/}"
36+
else
37+
RELATIVE_PATH="${CONTAINER_PATH##*/volumes/nextcloud/}"
38+
if [[ "$RELATIVE_PATH" == "$CONTAINER_PATH" ]]; then
39+
RELATIVE_PATH="${CONTAINER_PATH##*php82-master/}"
40+
fi
41+
fi
42+
43+
WORKSPACE="/var/www/html/$RELATIVE_PATH"
44+
45+
GREEN='\033[0;32m'
46+
BLUE='\033[0;34m'
47+
YELLOW='\033[1;33m'
48+
NC='\033[0m'
49+
50+
echo -e "${BLUE}🎭 Starting Playwright UI Mode for: $RELATIVE_PATH${NC}"
51+
echo -e "${GREEN}🌐 UI available at: http://localhost:9323${NC}"
52+
echo ""
53+
echo -e "${YELLOW}⚠️ Keep this terminal open while testing!${NC}"
54+
echo -e "${YELLOW} Close with Ctrl+C when done.${NC}"
55+
echo ""
56+
57+
# Check if container is running
58+
if ! docker compose ps playwright | grep -q "Up"; then
59+
echo "Starting playwright container..."
60+
docker compose up -d playwright
61+
sleep 2
62+
fi
63+
64+
# Install dependencies if needed
65+
if ! docker compose exec -T playwright test -d "${WORKSPACE}/node_modules/@playwright" 2>/dev/null; then
66+
echo "Installing Playwright dependencies..."
67+
docker compose exec -w "$WORKSPACE" playwright npm ci
68+
fi
69+
70+
echo -e "${GREEN}Starting UI server...${NC}"
71+
echo ""
72+
73+
# Run with UI mode - keep it in foreground so user can Ctrl+C to stop
74+
docker compose exec -w "$WORKSPACE" playwright npx playwright test --ui --ui-host=0.0.0.0 --ui-port=9323 "$@"

.docker/bin/trust-local-cert

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
6+
cd "$ROOT_DIR"
7+
8+
container_id=$(docker compose ps -q nginx)
9+
if [ -z "$container_id" ]; then
10+
echo "The nginx service is not running. Start the environment first." >&2
11+
exit 1
12+
fi
13+
14+
container_status=$(docker inspect --format='{{.State.Status}}' "$container_id" 2>/dev/null)
15+
if [ "$container_status" != "running" ]; then
16+
echo "The nginx container is not running (status: ${container_status:-unknown}). Start the environment first." >&2
17+
exit 1
18+
fi
19+
20+
cert_path_in_container=/certs/nextcloud.pem
21+
tmp_pem=$(mktemp /tmp/nextcloud-cert.XXXXXX.pem)
22+
tmp_crt=$(mktemp /tmp/nextcloud-cert.XXXXXX.crt)
23+
trap 'rm -f "$tmp_pem" "$tmp_crt"' EXIT
24+
25+
docker cp "$container_id:$cert_path_in_container" "$tmp_pem"
26+
openssl x509 -in "$tmp_pem" -out "$tmp_crt"
27+
28+
mkdir -p "$HOME/.pki/nssdb"
29+
certutil -d sql:"$HOME/.pki/nssdb" -N --empty-password >/dev/null 2>&1 || true
30+
certutil -d sql:"$HOME/.pki/nssdb" -D -n "Nextcloud Localhost" >/dev/null 2>&1 || true
31+
certutil -d sql:"$HOME/.pki/nssdb" -A -t "P,," -n "Nextcloud Localhost" -i "$tmp_crt"
32+
33+
echo "Trusted Nextcloud Localhost certificate in $HOME/.pki/nssdb"

.docker/nginx/config/https.conf

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@ server {
33
http2_max_field_size 16k;
44
http2_max_header_size 32k;
55

6-
ssl_certificate /tmp/nextcloud.pem;
7-
ssl_certificate_key /tmp/nextcloud.pem;
6+
ssl_certificate /certs/nextcloud.pem;
7+
ssl_certificate_key /certs/nextcloud.pem;
88
ssl_protocols TLSv1.2 TLSv1.3;
99
ssl_ciphers HIGH:!aNULL:!MD5;
1010

1111
include /etc/nginx/conf.d/includes/*.conf;
1212

1313
include /etc/nginx/conf.d/common.conf;
1414
}
15+
16+
server {
17+
listen 8443 ssl;
18+
19+
ssl_certificate /certs/nextcloud.pem;
20+
ssl_certificate_key /certs/nextcloud.pem;
21+
ssl_protocols TLSv1.2 TLSv1.3;
22+
ssl_ciphers HIGH:!aNULL:!MD5;
23+
24+
location / {
25+
proxy_pass http://eurooffice/;
26+
proxy_http_version 1.1;
27+
proxy_set_header Upgrade $http_upgrade;
28+
proxy_set_header Connection "upgrade";
29+
proxy_set_header Host $http_host;
30+
proxy_set_header X-Real-IP $remote_addr;
31+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32+
proxy_set_header X-Forwarded-Proto $scheme;
33+
proxy_read_timeout 3600s;
34+
proxy_send_timeout 3600s;
35+
}
36+
}

.docker/scripts/nginx-entrypoint.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
#!/bin/sh
22

3-
# Generate self-signed certificate if it doesn't exist
4-
if [ ! -f /tmp/nextcloud.pem ]; then
5-
echo "Generating self-signed certificate..."
6-
openssl req -new -x509 -days 365 -nodes \
3+
CERT_DIR=${CERT_DIR:-/certs}
4+
CERT_PATH=${CERT_PATH:-$CERT_DIR/nextcloud.pem}
5+
6+
has_localhost_san() {
7+
[ -f "$CERT_PATH" ] && openssl x509 -in "$CERT_PATH" -noout -ext subjectAltName 2>/dev/null | grep -q 'DNS:localhost'
8+
}
9+
10+
generate_self_signed_cert() {
11+
echo "Generating self-signed certificate for localhost..."
12+
mkdir -p "$CERT_DIR"
13+
tmp_key=$(mktemp)
14+
tmp_cert=$(mktemp)
15+
openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
716
-subj "/C=BR/ST=State/L=City/O=Nextcloud/CN=localhost" \
8-
-out /tmp/nextcloud.pem -keyout /tmp/nextcloud.pem 2>/dev/null || true
17+
-addext "subjectAltName=DNS:localhost" \
18+
-keyout "$tmp_key" \
19+
-out "$tmp_cert"
20+
cat "$tmp_key" "$tmp_cert" > "$CERT_PATH"
21+
rm -f "$tmp_key" "$tmp_cert"
22+
echo "Certificate generated at $CERT_PATH"
23+
}
24+
25+
if ! has_localhost_san; then
26+
generate_self_signed_cert
927
fi
1028

1129
# Execute nginx

0 commit comments

Comments
 (0)