6 lines
2.3 KiB
PHP
6 lines
2.3 KiB
PHP
<?php
|
|
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true,64,JSON_THROW_ON_ERROR);$out=$s['root'].'/sourcing-loader.json';if(file_exists($out))throw new LogicException('Loader proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$root=$s['root'].'/loader-probes';if(file_exists($root))throw new LogicException('Fresh loader probes required');mkdir($root);mkdir($root.'/app/Fixture',0777,true);$method=new ReflectionMethod(App\Modules\Purchasing\ReceiptRuntime::class,'loadClass');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$refuse=function($fn,$name)use($ok){try{$fn();throw new RuntimeException('Expected refusal');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){$ok($e->getStatusCode()===503,$name);}};
|
|
$file=$root.'/app/Fixture/Verified.php';file_put_contents($file,"<?php namespace Tempo\\Purchasing\\Embedded\\Fixture; class Verified {} \$GLOBALS['loader_verified']=true;");$pin=hash_file('sha256',$file);$method->invoke(null,'Tempo\\Purchasing\\Embedded\\Fixture\\Verified',$root,['app/Fixture/Verified.php'=>$pin]);$ok(($GLOBALS['loader_verified']??false)===true,'known dependency is verified before execution');
|
|
$file=$root.'/app/Fixture/Tampered.php';file_put_contents($file,"<?php namespace Tempo\\Purchasing\\Embedded\\Fixture; class Tampered {} \$GLOBALS['loader_tampered']=true;");$refuse(fn()=>$method->invoke(null,'Tempo\\Purchasing\\Embedded\\Fixture\\Tampered',$root,['app/Fixture/Tampered.php'=>str_repeat('0',64)]),'altered dependency is refused');$ok(!class_exists('Tempo\\Purchasing\\Embedded\\Fixture\\Tampered',false)&&!isset($GLOBALS['loader_tampered']),'unverified code is never executed');
|
|
$refuse(fn()=>$method->invoke(null,'Tempo\\Purchasing\\Embedded\\Fixture\\Unlisted',$root,[]),'unlisted dependency is refused');$refuse(fn()=>$method->invoke(null,'Tempo\\Purchasing\\Embedded\\..\\Outside',$root,[]),'class path traversal is refused');$method->invoke(null,'Unrelated\\Library\\ClassName',$root,[]);$ok(true,'other namespace loaders remain available');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'business_writes'=>0,'reference_bundle_modified'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|