diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1915ca3..9c08b82 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,7 @@ jobs: image: mysql:8.0 env: MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: protector_test ports: - 3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 @@ -56,6 +57,6 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update --dev --no-progress composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/phpunit -c phpunit-ci.xml.dist env: DB_PORT: ${{ job.services.mysql.ports[3306] }} diff --git a/Tests/ExportDumpTest.php b/Tests/ExportDumpTest.php index 8dfdd90..b8285ce 100644 --- a/Tests/ExportDumpTest.php +++ b/Tests/ExportDumpTest.php @@ -1,11 +1,12 @@ <?php use Cybex\Protector\Exceptions\FailedCreatingDestinationPathException; -use Cybex\Protector\Exceptions\InvalidConnectionException; use Illuminate\Contracts\Filesystem\Filesystem; +use Illuminate\Http\Request; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; +use Symfony\Component\HttpFoundation\StreamedResponse; class ExportDumpTest extends BaseTest { @@ -127,4 +128,17 @@ public function failGeneratingDumpWhenTryingToConnectToDatabase() $this->expectException(PDOException::class); $this->runProtectedMethod('generateDump', [['no-data' => true]]); } + + /** + * @test + */ + public function createsStreamedFileDownloadResponse() + { + Config::set('protector.routeMiddleware', []); + + $response = $this->protector->generateFileDownloadResponse(new Request(), null); + + $this->assertInstanceOf(StreamedResponse::class, $response); + $this->assertEquals(200, $response->getStatusCode()); + } } diff --git a/docker-compose.yml b/docker-compose.yml index 8137b3d..b51dc75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,11 @@ services: app: container_name: ${DOCKER_CONTAINER_NAME:-protector_test} build: - context: ./docker/${DOCKER_PHP_VERSION:-8.1} + context: ./docker/${DOCKER_PHP_VERSION:-8.2} dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' - image: sail-${DOCKER_PHP_VERSION:-8.1}/app + image: sail-${DOCKER_PHP_VERSION:-8.2}/app extra_hosts: - 'host.docker.internal:host-gateway' environment: @@ -19,7 +19,6 @@ services: volumes: - '.:/var/www/html' networks: - - shared - internal depends_on: - mysql_testing @@ -41,5 +40,3 @@ services: networks: internal: internal: true - shared: - external: true diff --git a/docker/8.0/Dockerfile b/docker/8.0/Dockerfile index 15456ca..af8c592 100644 --- a/docker/8.0/Dockerfile +++ b/docker/8.0/Dockerfile @@ -14,24 +14,19 @@ ENV TZ=UTC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update \ - && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \ - && mkdir -p ~/.gnupg \ - && chmod 600 ~/.gnupg \ - && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \ - && echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf \ - && gpg --recv-key 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c \ - && gpg --export 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c > /usr/share/keyrings/ppa_ondrej_php.gpg \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils \ + && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null \ && echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ && apt-get update \ && apt-get install -y php8.0-cli php8.0-dev \ - php8.0-pgsql php8.0-sqlite3 php8.0-gd \ + php8.0-pgsql php8.0-sqlite3 php8.0-gd php8.0-imagick \ php8.0-curl php8.0-memcached \ php8.0-imap php8.0-mysql php8.0-mbstring \ php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \ php8.0-intl php8.0-readline php8.0-pcov \ php8.0-msgpack php8.0-igbinary php8.0-ldap \ php8.0-redis php8.0-swoole php8.0-xdebug \ - && php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \ + && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \ && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ && apt-get install -y nodejs \ && npm install -g npm \ diff --git a/docker/8.0/php.ini b/docker/8.0/php.ini index 66d04d5..39dcbca 100644 --- a/docker/8.0/php.ini +++ b/docker/8.0/php.ini @@ -2,3 +2,6 @@ post_max_size = 100M upload_max_filesize = 100M variables_order = EGPCS + +[opcache] +opcache.enable_cli=1 diff --git a/docker/8.1/Dockerfile b/docker/8.1/Dockerfile index 0277709..77589ba 100644 --- a/docker/8.1/Dockerfile +++ b/docker/8.1/Dockerfile @@ -3,8 +3,8 @@ FROM ubuntu:22.04 LABEL maintainer="Taylor Otwell" ARG WWWGROUP -ARG NODE_VERSION=16 -ARG POSTGRES_VERSION=14 +ARG NODE_VERSION=18 +ARG POSTGRES_VERSION=15 WORKDIR /var/www/html @@ -14,17 +14,12 @@ ENV TZ=UTC RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone RUN apt-get update \ - && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \ - && mkdir -p ~/.gnupg \ - && chmod 600 ~/.gnupg \ - && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \ - && echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf \ - && gpg --recv-key 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c \ - && gpg --export 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c > /usr/share/keyrings/ppa_ondrej_php.gpg \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils \ + && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null \ && echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ && apt-get update \ && apt-get install -y php8.1-cli php8.1-dev \ - php8.1-pgsql php8.1-sqlite3 php8.1-gd \ + php8.1-pgsql php8.1-sqlite3 php8.1-gd php8.1-imagick \ php8.1-curl \ php8.1-imap php8.1-mysql php8.1-mbstring \ php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \ @@ -32,7 +27,7 @@ RUN apt-get update \ php8.1-ldap \ php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \ php8.1-memcached php8.1-pcov php8.1-xdebug \ - && php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \ + && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \ && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ && apt-get install -y nodejs \ && npm install -g npm \ diff --git a/docker/8.1/php.ini b/docker/8.1/php.ini index 66d04d5..39dcbca 100644 --- a/docker/8.1/php.ini +++ b/docker/8.1/php.ini @@ -2,3 +2,6 @@ post_max_size = 100M upload_max_filesize = 100M variables_order = EGPCS + +[opcache] +opcache.enable_cli=1 diff --git a/docker/8.2/Dockerfile b/docker/8.2/Dockerfile new file mode 100644 index 0000000..b3ced6a --- /dev/null +++ b/docker/8.2/Dockerfile @@ -0,0 +1,58 @@ +FROM ubuntu:22.04 + +LABEL maintainer="Taylor Otwell" + +ARG WWWGROUP +ARG NODE_VERSION=18 +ARG POSTGRES_VERSION=15 + +WORKDIR /var/www/html + +ENV DEBIAN_FRONTEND noninteractive +ENV TZ=UTC + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils \ + && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \ + && echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ + && apt-get update \ + && apt-get install -y php8.2-cli php8.2-dev \ + php8.2-pgsql php8.2-sqlite3 php8.2-gd php8.2-imagick \ + php8.2-curl \ + php8.2-imap php8.2-mysql php8.2-mbstring \ + php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap \ + php8.2-intl php8.2-readline \ + php8.2-ldap \ + php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole \ + php8.2-memcached php8.2-pcov php8.2-xdebug \ + && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \ + && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ + && apt-get install -y nodejs \ + && npm install -g npm \ + && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn.gpg >/dev/null \ + && echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \ + && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/keyrings/pgdg.gpg >/dev/null \ + && echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ + && apt-get update \ + && apt-get install -y yarn \ + && apt-get install -y mysql-client \ + && apt-get install -y postgresql-client-$POSTGRES_VERSION \ + && apt-get -y autoremove \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2 + +RUN groupadd --force -g $WWWGROUP sail +RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail + +COPY start-container /usr/local/bin/start-container +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY php.ini /etc/php/8.2/cli/conf.d/99-sail.ini +RUN chmod +x /usr/local/bin/start-container + +EXPOSE 8000 + +ENTRYPOINT ["start-container"] diff --git a/docker/8.2/php.ini b/docker/8.2/php.ini new file mode 100644 index 0000000..39dcbca --- /dev/null +++ b/docker/8.2/php.ini @@ -0,0 +1,7 @@ +[PHP] +post_max_size = 100M +upload_max_filesize = 100M +variables_order = EGPCS + +[opcache] +opcache.enable_cli=1 diff --git a/docker/8.2/start-container b/docker/8.2/start-container new file mode 100644 index 0000000..b864399 --- /dev/null +++ b/docker/8.2/start-container @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +if [ ! -z "$WWWUSER" ]; then + usermod -u $WWWUSER sail +fi + +if [ ! -d /.composer ]; then + mkdir /.composer +fi + +chmod -R ugo+rw /.composer + +if [ $# -gt 0 ]; then + exec gosu $WWWUSER "$@" +else + exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf +fi diff --git a/docker/8.2/supervisord.conf b/docker/8.2/supervisord.conf new file mode 100644 index 0000000..9d28479 --- /dev/null +++ b/docker/8.2/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true +user=root +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +[program:php] +command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80 +user=sail +environment=LARAVEL_SAIL="1" +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/phpunit-ci.xml.dist b/phpunit-ci.xml.dist new file mode 100644 index 0000000..eb6274b --- /dev/null +++ b/phpunit-ci.xml.dist @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" + colors="true" testdox="true" processIsolation="false" stopOnFailure="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"> + <testsuites> + <testsuite name="Test Suite"> + <directory>Tests</directory> + </testsuite> + </testsuites> + <coverage> + <include> + <directory suffix=".php">./src</directory> + </include> + <report> + <html outputDirectory="build/coverage"/> + <text outputFile="build/coverage.txt"/> + <clover outputFile="build/logs/clover.xml"/> + </report> + </coverage> + <logging> + <junit outputFile="build/report.junit.xml"/> + </logging> + <php> + <env name="PROTECTOR_PRIVATE_KEY" + value="e195f1252346e31fe7b87e899f69a87d6fe99f38bd6e7c3cbdde411fcd9cc93e2c1d0ea6e0f8e207b38bef11bfcd5c0615c3cf4695876631b1da523a552b6022"/> + <env name="PROTECTOR_PUBLIC_KEY" value="2c1d0ea6e0f8e207b38bef11bfcd5c0615c3cf4695876631b1da523a552b6022"/> + <env name="PROTECTOR_ENCRYPTED_MESSAGE" + value="c93e1c30857b0a5a36dddd11237ff65ef153144e0c400304cc80501da7e9b41a99c568fb34491629577ba4b5c0ec632e50067d61cf1ece27e1eabc"/> + <env name="PROTECTOR_DECRYPTED_MESSAGE" value="hello world"/> + <env name="PROTECTOR_AUTH_TOKEN" value="1|bxa5BBNo7lXxgtRY4DN775JdAtQSAlN4UfgRnFhz"/> + <env name="DB_HOST" value="127.0.0.1"/> + <env name="DB_DATABASE" value="protector_test"/> + <env name="DB_USERNAME" value="root"/> + <env name="DB_PASSWORD" value=""/> + <env name="APP_URL" value="http://protector.invalid"/> + </php> +</phpunit> diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 73c3d9b..97f62f4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" testdox="true" processIsolation="false" stopOnFailure="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" - backupStaticProperties="false"> + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"> <testsuites> <testsuite name="Test Suite"> <directory>Tests</directory> diff --git a/sail b/sail deleted file mode 100755 index af31cc0..0000000 --- a/sail +++ /dev/null @@ -1,486 +0,0 @@ -#!/usr/bin/env bash - -UNAMEOUT="$(uname -s)" - -# Verify operating system is supported... -case "${UNAMEOUT}" in - Linux*) MACHINE=linux;; - Darwin*) MACHINE=mac;; - *) MACHINE="UNKNOWN" -esac - -if [ "$MACHINE" == "UNKNOWN" ]; then - echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2 - - exit 1 -fi - -# Determine if stdout is a terminal... -if test -t 1; then - # Determine if colors are supported... - ncolors=$(tput colors) - - if test -n "$ncolors" && test "$ncolors" -ge 8; then - BOLD="$(tput bold)" - YELLOW="$(tput setaf 3)" - GREEN="$(tput setaf 2)" - NC="$(tput sgr0)" - fi -fi - -# Function that prints the available commands... -function display_help { - echo "Laravel Sail" - echo - echo "${YELLOW}Usage:${NC}" >&2 - echo " sail COMMAND [options] [arguments]" - echo - echo "Unknown commands are passed to the docker-compose binary." - echo - echo "${YELLOW}docker-compose Commands:${NC}" - echo " ${GREEN}sail up${NC} Start the application" - echo " ${GREEN}sail up -d${NC} Start the application in the background" - echo " ${GREEN}sail stop${NC} Stop the application" - echo " ${GREEN}sail restart${NC} Restart the application" - echo " ${GREEN}sail ps${NC} Display the status of all containers" - echo - echo "${YELLOW}Artisan Commands:${NC}" - echo " ${GREEN}sail artisan ...${NC} Run an Artisan command" - echo " ${GREEN}sail artisan queue:work${NC}" - echo - echo "${YELLOW}PHP Commands:${NC}" - echo " ${GREEN}sail php ...${NC} Run a snippet of PHP code" - echo " ${GREEN}sail php -v${NC}" - echo - echo "${YELLOW}Composer Commands:${NC}" - echo " ${GREEN}sail composer ...${NC} Run a Composer command" - echo " ${GREEN}sail composer require laravel/sanctum${NC}" - echo - echo "${YELLOW}Node Commands:${NC}" - echo " ${GREEN}sail node ...${NC} Run a Node command" - echo " ${GREEN}sail node --version${NC}" - echo - echo "${YELLOW}NPM Commands:${NC}" - echo " ${GREEN}sail npm ...${NC} Run a npm command" - echo " ${GREEN}sail npx${NC} Run a npx command" - echo " ${GREEN}sail npm run prod${NC}" - echo - echo "${YELLOW}Yarn Commands:${NC}" - echo " ${GREEN}sail yarn ...${NC} Run a Yarn command" - echo " ${GREEN}sail yarn run prod${NC}" - echo - echo "${YELLOW}Database Commands:${NC}" - echo " ${GREEN}sail mysql${NC} Start a MySQL CLI session within the 'mysql' container" - echo " ${GREEN}sail mariadb${NC} Start a MySQL CLI session within the 'mariadb' container" - echo " ${GREEN}sail psql${NC} Start a PostgreSQL CLI session within the 'pgsql' container" - echo " ${GREEN}sail redis${NC} Start a Redis CLI session within the 'redis' container" - echo - echo "${YELLOW}Debugging:${NC}" - echo " ${GREEN}sail debug ...${NC} Run an Artisan command in debug mode" - echo " ${GREEN}sail debug queue:work${NC}" - echo - echo "${YELLOW}Running Tests:${NC}" - echo " ${GREEN}sail test${NC} Run the PHPUnit tests via the Artisan test command" - echo " ${GREEN}sail phpunit ...${NC} Run PHPUnit" - echo " ${GREEN}sail pint ...${NC} Run Pint" - echo " ${GREEN}sail dusk${NC} Run the Dusk tests (Requires the laravel/dusk package)" - echo " ${GREEN}sail dusk:fails${NC} Re-run previously failed Dusk tests (Requires the laravel/dusk package)" - echo - echo "${YELLOW}Container CLI:${NC}" - echo " ${GREEN}sail shell${NC} Start a shell session within the application container" - echo " ${GREEN}sail bash${NC} Alias for 'sail shell'" - echo " ${GREEN}sail root-shell${NC} Start a root shell session within the application container" - echo " ${GREEN}sail root-bash${NC} Alias for 'sail root-shell'" - echo " ${GREEN}sail tinker${NC} Start a new Laravel Tinker session" - echo - echo "${YELLOW}Sharing:${NC}" - echo " ${GREEN}sail share${NC} Share the application publicly via a temporary URL" - echo - echo "${YELLOW}Binaries:${NC}" - echo " ${GREEN}sail bin ...${NC} Run Composer binary scripts from the vendor/bin directory" - echo - echo "${YELLOW}Customization:${NC}" - echo " ${GREEN}sail artisan sail:publish${NC} Publish the Sail configuration files" - echo " ${GREEN}sail build --no-cache${NC} Rebuild all of the Sail containers" - - exit 1 -} - -# Proxy the "help" command... -if [ $# -gt 0 ]; then - if [ "$1" == "help" ] || [ "$1" == "-h" ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then - display_help - fi -else - display_help -fi - -# Source the ".env" file so Laravel's environment variables are available... -if [ -f ./.env ]; then - source ./.env -fi - -# Define environment variables... -export APP_PORT=${APP_PORT:-80} -export APP_SERVICE=${APP_SERVICE:-"laravel.test"} -export DB_PORT=${DB_PORT:-3306} -export WWWUSER=${WWWUSER:-$UID} -export WWWGROUP=${WWWGROUP:-$(id -g)} - -export SAIL_FILES=${SAIL_FILES:-""} -export SAIL_SHARE_DASHBOARD=${SAIL_SHARE_DASHBOARD:-4040} -export SAIL_SHARE_SERVER_HOST=${SAIL_SHARE_SERVER_HOST:-"laravel-sail.site"} -export SAIL_SHARE_SERVER_PORT=${SAIL_SHARE_SERVER_PORT:-8080} -export SAIL_SHARE_SUBDOMAIN=${SAIL_SHARE_SUBDOMAIN:-""} - -# Function that outputs Sail is not running... -function sail_is_not_running { - echo "${BOLD}Sail is not running.${NC}" >&2 - echo "" >&2 - echo "${BOLD}You may Sail using the following commands:${NC} './vendor/bin/sail up' or './vendor/bin/sail up -d'" >&2 - - exit 1 -} - -# Define Docker Compose command prefix... -docker compose &> /dev/null -if [ $? == 0 ]; then - DOCKER_COMPOSE=(docker compose) -else - DOCKER_COMPOSE=(docker-compose) -fi - -if [ -n "$SAIL_FILES" ]; then - # Convert SAIL_FILES to an array... - IFS=':' read -ra SAIL_FILES <<< "$SAIL_FILES" - - for FILE in "${SAIL_FILES[@]}"; do - if [ -f "$FILE" ]; then - DOCKER_COMPOSE+=(-f "$FILE") - else - echo "${BOLD}Unable to find Docker Compose file: '${FILE}'${NC}" >&2 - - exit 1 - fi - done -fi - -EXEC="yes" - -if [ -z "$SAIL_SKIP_CHECKS" ]; then - # Ensure that Docker is running... - if ! docker info > /dev/null 2>&1; then - echo "${BOLD}Docker is not running.${NC}" >&2 - - exit 1 - fi - - # Determine if Sail is currently up... - if "${DOCKER_COMPOSE[@]}" ps "$APP_SERVICE" 2>&1 | grep 'Exit\|exited'; then - echo "${BOLD}Shutting down old Sail processes...${NC}" >&2 - - "${DOCKER_COMPOSE[@]}" down > /dev/null 2>&1 - - EXEC="no" - elif [ -z "$("${DOCKER_COMPOSE[@]}" ps -q)" ]; then - EXEC="no" - fi -fi - -ARGS=() - -# Proxy PHP commands to the "php" binary on the application container... -if [ "$1" == "php" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" "php" "$@") - else - sail_is_not_running - fi - -# Proxy vendor binary commands on the application container... -elif [ "$1" == "bin" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" ./vendor/bin/"$@") - else - sail_is_not_running - fi - -# Proxy docker-compose commands to the docker-compose binary on the application container... -elif [ "$1" == "docker-compose" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" "${DOCKER_COMPOSE[@]}") - else - sail_is_not_running - fi - -# Proxy Composer commands to the "composer" binary on the application container... -elif [ "$1" == "composer" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" "composer" "$@") - else - sail_is_not_running - fi - -# Proxy Artisan commands to the "artisan" binary on the application container... -elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php artisan "$@") - else - sail_is_not_running - fi - -# Proxy the "debug" command to the "php artisan" binary on the application container with xdebug enabled... -elif [ "$1" == "debug" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail -e XDEBUG_SESSION=1) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php artisan "$@") - else - sail_is_not_running - fi - -# Proxy the "test" command to the "php artisan test" Artisan command... -elif [ "$1" == "test" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php artisan test "$@") - else - sail_is_not_running - fi - -# Proxy the "phpunit" command to "php vendor/bin/phpunit"... -elif [ "$1" == "phpunit" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php vendor/bin/phpunit "$@") - else - sail_is_not_running - fi - -# Proxy the "pint" command to "php vendor/bin/pint"... -elif [ "$1" == "pint" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php vendor/bin/pint "$@") - else - sail_is_not_running - fi - -# Proxy the "dusk" command to the "php artisan dusk" Artisan command... -elif [ "$1" == "dusk" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(-e "APP_URL=http://${APP_SERVICE}") - ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub") - ARGS+=("$APP_SERVICE" php artisan dusk "$@") - else - sail_is_not_running - fi - -# Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command... -elif [ "$1" == "dusk:fails" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(-e "APP_URL=http://${APP_SERVICE}") - ARGS+=(-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub") - ARGS+=("$APP_SERVICE" php artisan dusk:fails "$@") - else - sail_is_not_running - fi - -# Initiate a Laravel Tinker session within the application container... -elif [ "$1" == "tinker" ] ; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" php artisan tinker) - else - sail_is_not_running - fi - -# Proxy Node commands to the "node" binary on the application container... -elif [ "$1" == "node" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" node "$@") - else - sail_is_not_running - fi - -# Proxy NPM commands to the "npm" binary on the application container... -elif [ "$1" == "npm" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" npm "$@") - else - sail_is_not_running - fi - -# Proxy NPX commands to the "npx" binary on the application container... -elif [ "$1" == "npx" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" npx "$@") - else - sail_is_not_running - fi - -# Proxy YARN commands to the "yarn" binary on the application container... -elif [ "$1" == "yarn" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" yarn "$@") - else - sail_is_not_running - fi - -# Initiate a MySQL CLI terminal session within the "mysql" container... -elif [ "$1" == "mysql" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(mysql bash -c) - ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}") - else - sail_is_not_running - fi - -# Initiate a MySQL CLI terminal session within the "mariadb" container... -elif [ "$1" == "mariadb" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(mariadb bash -c) - ARGS+=("MYSQL_PWD=\${MYSQL_PASSWORD} mysql -u \${MYSQL_USER} \${MYSQL_DATABASE}") - else - sail_is_not_running - fi - -# Initiate a PostgreSQL CLI terminal session within the "pgsql" container... -elif [ "$1" == "psql" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(pgsql bash -c) - ARGS+=("PGPASSWORD=\${PGPASSWORD} psql -U \${POSTGRES_USER} \${POSTGRES_DB}") - else - sail_is_not_running - fi - -# Initiate a Bash shell within the application container... -elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec -u sail) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" bash "$@") - else - sail_is_not_running - fi - -# Initiate a root user Bash shell within the application container... -elif [ "$1" == "root-shell" ] || [ "$1" == "root-bash" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=("$APP_SERVICE" bash "$@") - else - sail_is_not_running - fi - -# Initiate a Redis CLI terminal session within the "redis" container... -elif [ "$1" == "redis" ] ; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - ARGS+=(exec) - [ ! -t 0 ] && ARGS+=(-T) - ARGS+=(redis redis-cli) - else - sail_is_not_running - fi - -# Share the site... -elif [ "$1" == "share" ]; then - shift 1 - - if [ "$EXEC" == "yes" ]; then - docker run --init --rm -p "$SAIL_SHARE_DASHBOARD":4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \ - --server-host="$SAIL_SHARE_SERVER_HOST" \ - --server-port="$SAIL_SHARE_SERVER_PORT" \ - --auth="$SAIL_SHARE_TOKEN" \ - --subdomain="$SAIL_SHARE_SUBDOMAIN" \ - "$@" - - exit - else - sail_is_not_running - fi - -# Pass unknown commands to the "docker-compose" binary... -else - ARGS+=("$@") -fi - -# Run Docker Compose with the defined arguments... -"${DOCKER_COMPOSE[@]}" "${ARGS[@]}" diff --git a/src/Protector.php b/src/Protector.php index f784444..d568a23 100644 --- a/src/Protector.php +++ b/src/Protector.php @@ -490,8 +490,8 @@ public function generateFileDownloadResponse( $shouldEncrypt = $this->shouldEncrypt(); // Only proceed when either Laravel Sanctum is turned off or the user's token is valid. - if (!$shouldEncrypt || $request->user()->tokenCan('protector:import')) { - if ($this->configure($connectionName)) { + if (!$shouldEncrypt || $request->user()?->tokenCan('protector:import')) { + if ($this->withConnectionName($connectionName)) { try { $serverFilePath = $this->createDump(); $publicKey = $this->getPublicKey($request); @@ -647,7 +647,7 @@ public function decryptString(string $encryptedString): string protected function getPublicKey(Request $request): string { try { - $publicKey = sodium_hex2bin($request->user()->protector_public_key); + $publicKey = sodium_hex2bin($request->user()?->protector_public_key); } catch (SodiumException) { throw new InvalidConfigurationException( 'There was an error receiving the crypto keys. This might be due to mismatching crypto keys.'