如何处理“有效负载无效”。在 Gitlab CI/CD 管道中?

问题描述 投票:0回答:1

我正在尝试在 GitLab CI/CD 中为我的 (Laravel 11 + React Typescript with Inertiajs) 运行 testJob,但我一直遇到以下错误。我已确保在 CI/CD 变量中设置 APP_KEY 并对其进行回显,以查看它是否与我的预期一致,事实确实如此。我不知道我在哪里错过了。

我确实阅读了相关问题这里这里文档等...但我还没有找到解决方案任何人都可以帮助解决这个问题吗?

// .gitlab-ci.yml 中的测试作业

testJob:
    stage: test
    image: php:latest
    services:
        - name: mysql:latest
    before_script:
        - test -d vendor || { apt-get update && apt-get install -y curl; }
        - test -d vendor || curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
        - test -d vendor || composer install
        - test -d node_modules || { curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs; }
        - test -d node_modules || npm install -g npm@latest
        - touch database/database.sqlite
        - cp .env.example .env
        - echo "APP_ENV=testing" >> .env
        - echo "APP_KEY=$APP_KEY" >> .env
        - php artisan config:clear
        - php artisan migrate
        - php artisan migrate:refresh 
    script:
        - echo "Running PHP Unit Tests"
        - ./vendor/bin/phpunit
        - echo "Running React Tests"
        - npm test
    dependencies:
        - buildJob

//错误和堆栈跟踪如下:

$ ./vendor/bin/phpunit
PHPUnit 11.1.3 by Sebastian Bergmann and contributors.
Runtime:       PHP 8.3.6
Configuration: /builds/group-kse/indupendo/phpunit.xml
.SFF..SFF.SF.SSSFFFFFFFFF.F.FFSFFFFEFFFFF.F                       43 / 43 (100%)
Time: 00:01.553, Memory: 56.50 MB
There was 1 error:
1) Tests\Feature\TwoFactorAuthenticationSettingsTest::test_recovery_codes_can_be_regenerated
Illuminate\Contracts\Encryption\DecryptException: The payload is invalid.
/builds/my-project/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:236
/builds/my-project/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:158
/builds/my-project/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:393
/builds/my-project/vendor/laravel/fortify/src/TwoFactorAuthenticatable.php:37
/builds/my-project/tests/Feature/TwoFactorAuthenticationSettingsTest.php:47
laravel encryption gitlab phpunit cicd
1个回答
0
投票

由于假定

APP_KEY
值存在于
.env.example
文件上方的某处,因此首先会检测到它,因此无法找到合适的值。修改行如下:

- sed -i '/^APP_KEY=/d' .env
- echo "APP_KEY=$APP_KEY" >> .env

或者您可以采取不同的方法,例如在

.env.example
文件中根本不包含此值。

© www.soinside.com 2019 - 2024. All rights reserved.