-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take into consideration appsec envs on the tracer
- Loading branch information
1 parent
7f6fc56
commit da51431
Showing
7 changed files
with
127 additions
and
147 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
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
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
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
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,31 @@ | ||
--TEST-- | ||
DD_APPSEC_SCA_ENABLED is set by INI | ||
--DESCRIPTION-- | ||
This configuration is used by the backend to display/charge customers | ||
--SKIPIF-- | ||
<?php | ||
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}"); | ||
if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing sensitive test - valgrind is too slow'); | ||
?> | ||
--ENV-- | ||
DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 | ||
--INI-- | ||
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_04-telemetry.out" | ||
datadog.appsec.sca_enabled=1 | ||
--FILE_EXTERNAL-- | ||
sca_test.inc | ||
--EXPECT-- | ||
array(3) { | ||
["name"]=> | ||
string(18) "appsec.sca_enabled" | ||
["value"]=> | ||
string(1) "1" | ||
["origin"]=> | ||
string(6) "EnvVar" | ||
} | ||
string(4) "Sent" | ||
--CLEAN-- | ||
<?php | ||
|
||
@unlink(__DIR__ . '/sca_flag_is_sent_04-telemetry.out'); |
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,31 @@ | ||
--TEST-- | ||
DD_APPSEC_SCA_ENABLED is set by INI | ||
--DESCRIPTION-- | ||
This configuration is used by the backend to display/charge customers | ||
--SKIPIF-- | ||
<?php | ||
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}"); | ||
if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing sensitive test - valgrind is too slow'); | ||
?> | ||
--ENV-- | ||
DD_TRACE_GENERATE_ROOT_SPAN=0 | ||
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1 | ||
--INI-- | ||
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_05-telemetry.out" | ||
datadog.appsec.sca_enabled=0 | ||
--FILE_EXTERNAL-- | ||
sca_test.inc | ||
--EXPECT-- | ||
array(3) { | ||
["name"]=> | ||
string(18) "appsec.sca_enabled" | ||
["value"]=> | ||
string(1) "0" | ||
["origin"]=> | ||
string(6) "EnvVar" | ||
} | ||
string(4) "Sent" | ||
--CLEAN-- | ||
<?php | ||
|
||
@unlink(__DIR__ . '/sca_flag_is_sent_05-telemetry.out'); |
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,46 @@ | ||
<?php | ||
DDTrace\start_span(); | ||
$root = DDTrace\root_span(); | ||
|
||
$id = basename(__FILE__, ".php"); | ||
|
||
$root->service = $id.'-telemetry-app'; | ||
$root->meta['env'] = 'test-env'; | ||
|
||
DDTrace\close_span(); | ||
|
||
// At this stage, the service and env are stored to be used by telemetry | ||
dd_trace_serialize_closed_spans(); | ||
|
||
dd_trace_internal_fn("finalize_telemetry"); | ||
|
||
for ($i = 0; $i < 100; ++$i) { | ||
usleep(100000); | ||
if (file_exists(__DIR__ . '/'.$id.'-telemetry.out')) { | ||
$batches = []; | ||
foreach (file(__DIR__ . '/'.$id.'-telemetry.out') as $l) { | ||
if ($l) { | ||
$json = json_decode($l, true); | ||
array_push($batches, ...($json["request_type"] == "message-batch" ? $json["payload"] : [$json])); | ||
} | ||
} | ||
$found = array_filter($batches, function ($json) { | ||
if ($json["request_type"] !== "app-started") { | ||
return false; | ||
} | ||
foreach($json["payload"]["configuration"] as $configuration) { | ||
if (str_contains($configuration["name"], "sca_enabled")) { | ||
var_dump($configuration); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
if (count($found) == 1) { | ||
var_dump("Sent"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
?> |