diff --git a/.githooks/post-receive b/.githooks/post-receive index 2426e63..9f23d3b 100644 --- a/.githooks/post-receive +++ b/.githooks/post-receive @@ -19,8 +19,11 @@ copy_env_file() { local branch="$1" + local env_file + env_file="$(get_deploy_env_file "$branch")" + source "$env_file" # Copy the .env file for the test environment - cp "$(get_deploy_env_file "$branch")" "$tmpdir/.env" || { + cp "$env_file" "$tmpdir/.env" || { echo "Error: Failed to copy .env file for test environment." return 1 } @@ -225,11 +228,7 @@ copy_env_file "$branch" || return 1 initialize_submodules "$tmpdir" || return 1 - - export TEST_PORT=4123 - export TEST_SCHEMA=http - export NODE_ENV=testing - + # echo "Skipping tests" # return 0 @@ -238,6 +237,7 @@ combine_css || return 1 echo "Starting application for tests..." + systemctl --user stop express-blog@"$branch".service nohup node src/app.js >>"$logfile" 2>&1 & echo $! >"$pidfile" @@ -249,7 +249,6 @@ run_tests "$branch" "$pidfile" "$logfile" || return 1 kill "$(cat "$pidfile")" 2>/dev/null || true - unset TEST_PORT TEST_SCHEMA NODE_ENV echo "Tests passed for branch '$branch' in temporary environment." return 0 @@ -274,7 +273,7 @@ wait_for_service() { local logfile="$1" # Wait for the application to become responsive - if ! _wait_for_service "http://127.0.0.1:$TEST_PORT"; then + if ! _wait_for_service "$SERVER_SCHEMA://$SERVER_DOMAIN"; then echo "Application did not start or respond for tests. Check logs in $logfile:" cat "$logfile" # Display logs on failure return 1 diff --git a/.githooks/pre-push b/.githooks/pre-push index 86e9f52..93153bc 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -9,11 +9,6 @@ set -euo pipefail set -x - -export TEST_SCHEMA="http" -export TEST_DOMAIN="127.0.0.1" -export TEST_PORT=4123 - node src/app.js >/dev/null 2>&1 & APP_PID=$! diff --git a/src/middleware/authCheck.js b/src/middleware/authCheck.js index 1f1432c..928b9ab 100644 --- a/src/middleware/authCheck.js +++ b/src/middleware/authCheck.js @@ -26,8 +26,26 @@ } } }, CACHE_TTL); +const SAFE_IPS = ["192.168.1.200", "192.168.1.50"]; module.exports = async (req, res, next) => { + // Determine the client IP address. + // req.ip is often provided by Express and correctly handles X-Forwarded-For if Express is configured for it. + // If not, you might need to manually check req.headers['x-forwarded-for'] + const clientIp = req.ip; // Or req.headers['x-forwarded-for']?.split(',')[0] || req.connection.remoteAddress; + // --- Bypass Logic --- + // Check if the client IP is in the list of safe IPs + if (SAFE_IPS.includes(clientIp)) { + req.isAuthenticated = true; // Mark as authenticated (bypassed) + if (req.log) { + req.log.info(`Bypassing authentication for safe IP: ${clientIp}`); + } else { + console.info(`Bypassing authentication for safe IP: ${clientIp}`); + } + return next(); // Proceed to the next middleware/route handler + } + // --- End Bypass Logic --- + const cookie = req.headers["cookie"] || ""; const authHeader = req.headers["authorization"] || ""; const cacheKey = getCacheKey(cookie, authHeader);