Skip to content

Commit

Permalink
tests(agent): add Drupal integration tests (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavarou authored Jul 26, 2023
1 parent 08d1d8e commit aaf84e2
Show file tree
Hide file tree
Showing 49 changed files with 3,280 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/include/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ guzzle/
# byproduct of logging/monolog tests
monolog2/
monolog3/
# byproduct of running drupal tests
drupal_6_bootstrap.inc
drupal_6_common.inc
drupal_7_bootstrap.inc
drupal_7_common.inc
69 changes: 69 additions & 0 deletions tests/include/drupal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/*
* Copyright 2023 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*
* Dupal core modules (bootstrap.inc, common.inc) are not embedded
* in the repository. They are downloaded when Drupal tests are run
* and `download_drupal` is called in the SKIPIF section.
*
* The purpose of this solution is to avoid embedding Drupal code, while still
* being able to run tests in the PR builder. If downloading Drupal core modules
* fails, the test will abort with a warning.
*
*/

/*
* `download_drupal` is called during the SKIPIF sections of integration tests.
* It downloads the bootstrap.inc and common.inc files from drupal project in
* desired version.
*/
function download_drupal($version) {
$pwd = realpath(dirname(__FILE__));
$files = ['bootstrap.inc', 'common.inc'];
$checksums = [
'6' => [
'bootstrap.inc' => '14e7070e475e020775255db84f3d3a73999418aa8b6ac51299eb34078690413b5e7aef4003c89f2538d3966b460e2dbf',
'common.inc' => 'b84b1e7c61cf8d28ded9c6c8b20abc52bc2962bf15ab9f08a2daa90b1c09694501a85a912a8d0e9ede842655be4c446d'],
'7' => [
'bootstrap.inc' => '673244b6d19dd2de6b5048f3412d62f1baf24593245175034d59f0dac305c936b0e67a1a91ba57614d17154cd82e0db5',
'common.inc' => 'f0b758b53f6819bc133b22987c180f947f5055d1225bf14ab2768e84a64c83283e507fcf82e6c3499e3eaf51e65340d0']
];
$file_prefix = 'drupal_' . $version . '_';
$drupal_source = 'https://raw.githubusercontent.com/drupal/drupal/';

if (6 == $version) {
// fd9d1859fce12f359a587e038212d30c2bd738e6 is snapshot in time of 6.x after 6.37 but before 6.38
$drupal_commit_sha = 'fd9d1859fce12f359a587e038212d30c2bd738e6';
} elseif (7 == $version) {
// 728503753272f746bb988ffb30d5327f8f2df4b2 is 7.92
$drupal_commit_sha = '728503753272f746bb988ffb30d5327f8f2df4b2';
} else {
/* Unsupported version */
return false;
}

foreach ($files as $f) {
$src_file_path = $drupal_source . $drupal_commit_sha . '/includes/' . $f;
$dest_file_path = $pwd . '/' . $file_prefix . $f;
if (!file_exists($dest_file_path)) {
copy($src_file_path, $dest_file_path);
}
}

foreach ($files as $f) {
$file_path = $pwd . '/' . $file_prefix . $f;
if (!file_exists($file_path)) {
return false;
}
$got_checksum = hash_file('sha384', $file_path);
$want_checksum = $checksums[$version][$f];
if ($got_checksum != $want_checksum) {
return false;
}
}

return true;
}
15 changes: 15 additions & 0 deletions tests/integration/external/drupal6/skipif.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

if (version_compare(PHP_VERSION, "7.4", ">")) {
die("skip: PHP > 7.4.0 not supported\n");
}

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal.php');

if (!download_drupal(6)) {
die("warn: drupal6 installation required\n");
}
51 changes: 51 additions & 0 deletions tests/integration/external/drupal6/test_basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*DESCRIPTION
Test that a simple request through drupal_http_request gets instrumented.
*/

// force the framework to avoid requiring the drupal detection file
/*INI
newrelic.framework = drupal
newrelic.distributed_tracing_enabled=0
*/

/*SKIPIF
<?php
require("skipif.inc");
*/

/*EXPECT
Hello world!
*/

/*EXPECT_METRICS
[
"?? agent run id",
"?? timeframe start",
"?? timeframe stop",
[
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]]
]
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_bootstrap.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_common.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');

$url = "http://" . $EXTERNAL_HOST;
$rv = drupal_http_request($url);
echo $rv->data;

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/*DESCRIPTION
1. The agent SHALL NOT add X-NewRelic-ID and X-NewRelic-Transaction headers
to external calls when cross application tracing is disabled.
2. The agent SHALL NOT add X-NewRelic-Synthetics headers to external calls when
the Synthetics feature is disabled.
*/

// force the framework to avoid requiring the drupal detection file
/*INI
newrelic.framework = drupal
newrelic.cross_application_tracer.enabled = false
newrelic.synthetics.enabled = false
newrelic.distributed_tracing_enabled=0
*/

/*SKIPIF
<?php
require("skipif.inc");
*/

/*
* The synthetics header contains the following JSON.
* [
* 1,
* 432507,
* "rrrrrrr-rrrr-1234-rrrr-rrrrrrrrrrrr",
* "jjjjjjj-jjjj-1234-jjjj-jjjjjjjjjjjj",
* "mmmmmmm-mmmm-1234-mmmm-mmmmmmmmmmmm"
* ]
*/

/*HEADERS
X-NewRelic-Synthetics=PwcbVVVRDQMHSEMQRUNFFBZDG0EQFBFPAVALVhVKRkBBSEsTQxNBEBZERRMUERofEg4LCF1bXQxJW1xZCEtSUANWFQhSUl4fWQ9TC1sLWQgOXF0LRE8aXl0JDA9aXBoLCVxbHlNUUFYdD1UPVRVZX14IVAxcDF4PCVsVPA==
*/

/*EXPECT
X-NewRelic-ID=missing X-NewRelic-Transaction=missing tracing endpoint reached
*/

/*EXPECT_RESPONSE_HEADERS
*/

/*EXPECT_METRICS
[
"?? agent run id",
"?? start time",
"?? stop time",
[
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Apdex"}, ["??", "??", "??", "??", "??", 0]],
[{"name":"Apdex/Uri__FILE__"}, ["??", "??", "??", "??", "??", 0]],
[{"name":"External/all"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"External/allWeb"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all",
"scope":"WebTransaction/Uri__FILE__"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"HttpDispatcher"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/framework/Drupal/forced"}, [ 1, 0, 0, 0, 0, 0]],
[{"name":"WebTransaction"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransaction/Uri__FILE__"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransactionTotalTime"}, [ 1, "??", "??", "??", "??", "??"]],
[{"name":"WebTransactionTotalTime/Uri__FILE__"}, [ 1, "??", "??", "??", "??", "??"]]
]
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_bootstrap.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_common.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');

$url = "http://" . make_tracing_url(realpath(dirname(__FILE__)) . '/../../../include/tracing_endpoint.php');
$rv = drupal_http_request($url);
echo $rv->data;
55 changes: 55 additions & 0 deletions tests/integration/external/drupal6/test_cat_disabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*DESCRIPTION
The agent SHALL NOT add X-NewRelic-ID and X-NewRelic-Transaction headers
to external calls when cross application tracing is disabled.
*/

// force the framework to avoid requiring the drupal detection file
/*INI
newrelic.framework = drupal
newrelic.cross_application_tracer.enabled = false
newrelic.distributed_tracing_enabled=0
*/

/*SKIPIF
<?php
require("skipif.inc");
*/

/*EXPECT
X-NewRelic-ID=missing X-NewRelic-Transaction=missing tracing endpoint reached
*/

/*EXPECT_RESPONSE_HEADERS
*/

/*EXPECT_METRICS
[
"?? agent run id",
"?? start time",
"?? stop time",
[
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]]
]
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_bootstrap.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_common.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');

$url = "http://" . make_tracing_url(realpath(dirname(__FILE__)) . '/../../../include/tracing_endpoint.php');
$rv = drupal_http_request($url);
echo $rv->data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*DESCRIPTION
Test that cross app tracing works with drupal_http_request when called with an
empty header array.
*/

// force the framework to avoid requiring the drupal detection file
/*INI
newrelic.framework = drupal
newrelic.distributed_tracing_enabled=0
newrelic.cross_application_tracer.enabled = true
*/

/*SKIPIF
<?php
require("skipif.inc");
*/

/*EXPECT
tracing endpoint reached
*/

/*EXPECT_RESPONSE_HEADERS
X-NewRelic-App-Data=??
*/

/*EXPECT_METRICS
[
"?? agent run id",
"?? timeframe start",
"?? timeframe stop",
[
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalApp/127.0.0.1/432507#4741547/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalTransaction/127.0.0.1/432507#4741547/WebTransaction/Custom/tracing"},
[1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalTransaction/127.0.0.1/432507#4741547/WebTransaction/Custom/tracing",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]]
]
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_bootstrap.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_common.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');

$url = "http://" . make_tracing_url(realpath(dirname(__FILE__)) . '/../../../include/tracing_endpoint.php');
$rv = drupal_http_request($url, array());
echo $rv->data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*DESCRIPTION
Test that cross app tracing works with drupal_http_request when called with a
single header.
*/

// force the framework to avoid requiring the drupal detection file
/*INI
newrelic.framework = drupal
newrelic.distributed_tracing_enabled=0
newrelic.cross_application_tracer.enabled = true
*/

/*SKIPIF
<?php
require("skipif.inc");
*/

/*EXPECT
tracing endpoint reached
*/

/*EXPECT_RESPONSE_HEADERS
X-NewRelic-App-Data=??
*/

/*EXPECT_METRICS
[
"?? agent run id",
"?? timeframe start",
"?? timeframe stop",
[
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/127.0.0.1/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"External/allOther"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalApp/127.0.0.1/432507#4741547/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalTransaction/127.0.0.1/432507#4741547/WebTransaction/Custom/tracing"},
[1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"ExternalTransaction/127.0.0.1/432507#4741547/WebTransaction/Custom/tracing",
"scope":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
[{"name":"Supportability/framework/Drupal/forced"}, [1, 0, 0, 0, 0, 0]]
]
]
*/

require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_bootstrap.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/drupal_6_common.inc');
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');

$url = "http://" . make_tracing_url(realpath(dirname(__FILE__)) . '/../../../include/tracing_endpoint.php');
$rv = drupal_http_request($url, array("kiteboarding" => "windsurfing"));
echo $rv->data;
Loading

0 comments on commit aaf84e2

Please sign in to comment.