Repository: php/pie (php)

Issue:
`pie self-verify` fallback requires GitHub API authentication
Running PIE in a clean container and attempting to verify it results in:

```
root@a7c4663e5c97:/pwd# ./pie self-verify 
🥧 PHP Installer for Extensions (PIE) 0.10.0, from The PHP Foundation
You are running PHP 8.1.32
Target PHP installation: 8.1.32 nts, on Linux/OSX/etc x86_64 (from /usr/local/bin/php)

In CurlDownloader.php line 660:
                                                                                                                                                                          
  The "https://api.github.com/orgs/php/attestations/sha256:a630d071d0618f7cfbd1ca5ea9afcdcc67645546629a1d53bf4329628708d341" file could not be downloaded (HTTP/2 401 ):  
  {"message":"Requires authentication","documentation_url":"https://docs.github.com/rest/guides/getting-started-with-the-rest-api#authentication","status":"401"}         
                                                                                                                                                                          

self-verify [--with-php-config WITH-PHP-CONFIG] [--with-php-path WITH-PHP-PATH] [--with-phpize-path WITH-PHPIZE-PATH]
```

or

```
root@a7c4663e5c97:/pwd# ./pie self-verify -vvv

Box Requirements Checker
========================

> Using PHP 8.1.32
> PHP is not using any php.ini file.

> Checking Box requirements:
  ✔ This application requires a PHP version matching "8.1.*||8.2.*||8.3.*||8.4.*".
  ✔ The package "justinrainbow/json-schema" requires the extension "json".
  ✔ The package "composer/ca-bundle" requires the extension "openssl".
  ✔ The package "composer/ca-bundle" requires the extension "pcre".
  ✔ The package "marc-mabe/php-enum" requires the extension "reflection".
  ✔ The package "symfony/service-contracts" conflicts with the extension "psr".
  
                                                                                                                                                                                                                                                                                                                                                                                              
 [OK] Your system is ready to run the application.                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                              

🥧 PHP Installer for Extensions (PIE) 0.10.0, from The PHP Foundation
You are running PHP 8.1.32
Target PHP installation: 8.1.32 nts, on Linux/OSX/etc x86_64 (from /usr/local/bin/php)
Using pie.json: /root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9/pie.json
Reading /root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9/pie.json
Loading config file /root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9/pie.json (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9/pie.json)
Checked CA file /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a file.
Checked directory /etc/pki/tls/certs/ca-bundle.crt does not exist or it is not a directory.
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'git' 'branch' '-a' '--no-color' '--no-abbrev' '-v'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'git' 'describe' '--exact-match' '--tags'
Executing command (CWD): 'git' '--version'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'git' 'log' '--pretty=%H' '-n1' 'HEAD'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'hg' 'branch'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'fossil' 'branch' 'list'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'fossil' 'tag' 'list'
Executing command (/root/.pie/php8.1_361571197ae1546d4e788bfc2a07f2c9): 'svn' 'info' '--xml'
Failed to initialize global composer: Composer could not find the config file: /root/.composer/composer.json

The GitHub "gh" CLI tool was not available.
Falling back to basic verification. To use full verification, install the `gh` CLI tool.
Downloading https://api.github.com/orgs/php/attestations/sha256:a630d071d0618f7cfbd1ca5ea9afcdcc67645546629a1d53bf4329628708d341
[401] https://api.github.com/orgs/php/attestations/sha256:a630d071d0618f7cfbd1ca5ea9afcdcc67645546629a1d53bf4329628708d341

In CurlDownloader.php line 660:
                                                                                                                                                                          
  [Composer\Downloader\TransportException (401)]                                                                                                                          
  The "https://api.github.com/orgs/php/attestations/sha256:a630d071d0618f7cfbd1ca5ea9afcdcc67645546629a1d53bf4329628708d341" file could not be downloaded (HTTP/2 401 ):  
  {"message":"Requires authentication","documentation_url":"https://docs.github.com/rest/guides/getting-started-with-the-rest-api#authentication","status":"401"}         
                                                                                                                                                                          

Exception trace:
  at phar:///pwd/pie/vendor/composer/composer/src/Composer/Util/Http/CurlDownloader.php:660
 Composer\Util\Http\CurlDownloader->failResponse() at phar:///pwd/pie/vendor/composer/composer/src/Composer/Util/Http/CurlDownloader.php:460
 Composer\Util\Http\CurlDownloader->tick() at phar:///pwd/pie/vendor/composer/composer/src/Composer/Util/HttpDownloader.php:392
 Composer\Util\HttpDownloader->countActiveJobs() at phar:///pwd/pie/vendor/composer/composer/src/Composer/Util/HttpDownloader.php:363
 Composer\Util\HttpDownloader->wait() at phar:///pwd/pie/vendor/composer/composer/src/Composer/Util/HttpDownloader.php:114
 Composer\Util\HttpDownloader->get() at phar:///pwd/pie/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php:291
 Php\Pie\SelfManage\Verify\FallbackVerificationUsingOpenSsl->downloadAttestations() at phar:///pwd/pie/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php:65
 Php\Pie\SelfManage\Verify\FallbackVerificationUsingOpenSsl->verify() at phar:///pwd/pie/src/SelfManage/Verify/VerifyPieReleaseUsingAttestation.php:48
 Php\Pie\SelfManage\Verify\VerifyPieReleaseUsingAttestation->verify() at phar:///pwd/pie/src/Command/SelfVerifyCommand.php:71
 Php\Pie\Command\SelfVerifyCommand->execute() at phar:///pwd/pie/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at phar:///pwd/pie/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at phar:///pwd/pie/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at phar:///pwd/pie/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at phar:///pwd/pie/bin/pie:53
 require() at /pwd/pie:15

self-verify [--with-php-config WITH-PHP-CONFIG] [--with-php-path WITH-PHP-PATH] [--with-phpize-path WITH-PHPIZE-PATH]
```

for the verbose output.

Should it interactively request API credentials if none are available yet? I think other commands do.

Pull request:
Fix self-update command issues
Fixes #232 

Two issues identified;

 - `retry-auth-failure` should be `true` to allow interactive prompting
 - `resources` path was not being included in compiled PHAR

Patch:
diff --git a/box.json.dist b/box.json.dist
index 0263f18..453105b 100644
--- a/box.json.dist
+++ b/box.json.dist
@@ -1,5 +1,9 @@
 {
     "alias": "pie.phar",
     "output": "pie.phar",
-    "git": "pie_version"
+    "git": "pie_version",
+    "force-autodiscovery": true,
+    "directories": [
+        "resources"
+    ]
 }
diff --git a/src/Downloading/GithubPackageReleaseAssets.php b/src/Downloading/GithubPackageReleaseAssets.php
index 4b526ae..8eb891c 100644
--- a/src/Downloading/GithubPackageReleaseAssets.php
+++ b/src/Downloading/GithubPackageReleaseAssets.php
@@ -80,7 +80,7 @@ final class GithubPackageReleaseAssets implements PackageReleaseAssets
             $decodedRepsonse = $httpDownloader->get(
                 $this->githubApiBaseUrl . '/repos/' . $package->githubOrgAndRepository() . '/releases/tags/' . $package->version(),
                 [
-                    'retry-auth-failure' => false,
+                    'retry-auth-failure' => true,
                     'http' => [
                         'method' => 'GET',
                         'header' => $authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $package->downloadUrl()),
diff --git a/src/SelfManage/Update/FetchPieReleaseFromGitHub.php b/src/SelfManage/Update/FetchPieReleaseFromGitHub.php
index 4e1d4ab..e56ce9e 100644
--- a/src/SelfManage/Update/FetchPieReleaseFromGitHub.php
+++ b/src/SelfManage/Update/FetchPieReleaseFromGitHub.php
@@ -37,7 +37,7 @@ final class FetchPieReleaseFromGitHub implements FetchPieRelease
         $decodedRepsonse = $this->httpDownloader->get(
             $url,
             [
-                'retry-auth-failure' => false,
+                'retry-auth-failure' => true,
                 'http' => [
                     'method' => 'GET',
                     'header' => $this->authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $url),
@@ -81,7 +81,7 @@ final class FetchPieReleaseFromGitHub implements FetchPieRelease
         $pharContent = $this->httpDownloader->get(
             $releaseMetadata->downloadUrl,
             [
-                'retry-auth-failure' => false,
+                'retry-auth-failure' => true,
                 'http' => [
                     'method' => 'GET',
                     'header' => $this->authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $releaseMetadata->downloadUrl),
diff --git a/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php b/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php
index d5d7bff..aca1f7c 100644
--- a/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php
+++ b/src/SelfManage/Verify/FallbackVerificationUsingOpenSsl.php
@@ -285,7 +285,7 @@ final class FallbackVerificationUsingOpenSsl implements VerifyPiePhar
             $decodedJson = $this->httpDownloader->get(
                 $attestationUrl,
                 [
-                    'retry-auth-failure' => false,
+                    'retry-auth-failure' => true,
                     'http' => [
                         'method' => 'GET',
                         'header' => $this->authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $attestationUrl),


Test patch:
diff --git a/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php b/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php
index 73f245d..5af96f3 100644
--- a/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php
+++ b/test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php
@@ -36,7 +36,7 @@ final class FetchPieReleaseFromGitHubTest extends TestCase
             ->with(
                 $url,
                 [
-                    'retry-auth-failure' => false,
+                    'retry-auth-failure' => true,
                     'http' => [
                         'method' => 'GET',
                         'header' => ['Authorization: Bearer fake-token'],
@@ -91,7 +91,7 @@ final class FetchPieReleaseFromGitHubTest extends TestCase
             ->with(
                 $url,
                 [
-                    'retry-auth-failure' => false,
+                    'retry-auth-failure' => true,
                     'http' => [
                         'method' => 'GET',
                         'header' => ['Authorization: Bearer fake-token'],
diff --git a/test/unit/SelfManage/Verify/FallbackVerificationUsingOpenSslTest.php b/test/unit/SelfManage/Verify/FallbackVerificationUsingOpenSslTest.php
index d286463..cf820c1 100644
--- a/test/unit/SelfManage/Verify/FallbackVerificationUsingOpenSslTest.php
+++ b/test/unit/SelfManage/Verify/FallbackVerificationUsingOpenSslTest.php
@@ -142,7 +142,7 @@ EOF);
             ->with(
                 $url,
                 [
-                    'retry-auth-failure' => false,
+                    'retry-auth-failure' => true,
                     'http' => [
                         'method' => 'GET',
                         'header' => ['Authorization: Bearer fake-token'],