-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle host detector with custom error handler and open_basedir (#1454)
if open_basedir is configured such that files that it tries to open are denied with a php warning, and a custom error handler is installed which converts warnings to exceptions, an unhandled exception occurs. add a test for this, suppress error handling around the code that can trigger this.
- Loading branch information
Showing
2 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/Integration/SDK/Resource/Detectors/test_host_detector_with_open_basedir.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Host detector with custom error handler and open_basedir | ||
--DESCRIPTION-- | ||
An error handler is installed which converts PHP warnings to exceptions, and open_basedir | ||
is configured such that /etc/machine-id and friends cannot be read | ||
--SKIPIF-- | ||
<?php if (!in_array(PHP_OS_FAMILY, ['Linux', 'BSD'])) die('skip requires Linux or BSD'); ?> | ||
--INI-- | ||
open_basedir=${PWD} | ||
--FILE-- | ||
<?php | ||
use OpenTelemetry\SDK\Resource\Detectors\Host; | ||
|
||
require_once 'vendor/autoload.php'; | ||
|
||
function warningToException($errno, $errstr, $errfile, $errline) | ||
{ | ||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); | ||
} | ||
set_error_handler('warningToException'); | ||
|
||
$detector = new Host(); | ||
$resource = $detector->getResource(); | ||
var_dump($resource->getAttributes()->toArray()); | ||
?> | ||
--EXPECTF-- | ||
array(2) { | ||
["host.name"]=> | ||
string(%d) "%s" | ||
["host.arch"]=> | ||
string(%d) "%s" | ||
} |