Skip to content

Commit

Permalink
Merge pull request #418 from mudhoney/fix/no-action-found-errors
Browse files Browse the repository at this point in the history
Fix all no action found sentry errors
  • Loading branch information
mudhoney authored Nov 20, 2024
2 parents c451f40 + eacf216 commit dde4579
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"scripts": {
"test-python": "cd install && venv/bin/python -m pytest",
"test": "vendor/bin/phpunit --bootstrap tests/autoload.php --fail-on-warning --testdox tests/unit_tests",
"test-integration": "vendor/bin/phpunit --bootstrap tests/autoload.php --fail-on-warning --testdox tests/unit_tests --group integration",
"local-test": "vendor/bin/phpunit --bootstrap tests/autoload.php --stop-on-failure --testdox --fail-on-warning tests/unit_tests",
"run-test": "vendor/bin/phpunit --bootstrap tests/autoload.php --stop-on-failure --testdox --fail-on-warning tests/unit_tests --filter ",
"make-test-config": "management/ci/make_test_config.sh settings/Config.ini settings/Private.php",
Expand Down
6 changes: 3 additions & 3 deletions docroot/docs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ function recursiveGroup($obj, &$out_arr=array()) {
function footer($api_version, $api_xml_path) {
?>
<div class="container">

<hr>

<footer>
<p><b>Last Updated:</b> <?php echo date('j F Y', filemtime($api_xml_path)); ?></p>
<?php if(($doc_m_time = @filemtime($api_xml_path)) !== FALSE): ?>
<p><b>Last Updated:</b> <?php echo date('j F Y', $doc_m_time); ?></p>
<?php endif; ?>
</footer>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
Expand Down
18 changes: 12 additions & 6 deletions docroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
}

try {

// Parse request and its variables
$params = RequestParams::collect();

Expand Down Expand Up @@ -150,8 +149,10 @@ function loadModule($params) {

include_once HV_ROOT_DIR.'/../src/Validation/InputValidator.php';


try {
if ( !array_key_exists($params['action'], $valid_actions) ) {
// If there is no action specified OR if the given action is not VALID; then ERROR
if ( !array_key_exists('action', $params) || !array_key_exists($params['action'], $valid_actions) ) {
throw new \InvalidArgumentException('Invalid action specified.<br />Consult the <a href="https://api.helioviewer.org/docs/v2/">API Documentation</a> for a list of valid actions.');
} else {

Expand Down Expand Up @@ -284,9 +285,13 @@ function printHTMLErrorMsg($msg) {
<html lang="en">
<head>
<?php
$meta = "<!-- DATE: %s URL: http://%s%s -->\n";
printf($meta, strftime('%Y-%m-%d %H:%m:%S'), $_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']);
// Find out http or https
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';

// Debug information
$meta = "<!-- DATE: %s URL: $protocol://%s%s -->\n";
printf($meta, date('Y-m-d H:m:s'), $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);

?>
<title>Helioviewer.org API - Error</title>
<link rel="stylesheet" type="text/css" href="<?php echo HV_WEB_ROOT_URL; ?>/docs/css/bootstrap-theme.min.css">
Expand All @@ -308,7 +313,8 @@ function printHTMLErrorMsg($msg) {

import_xml($api_version, $api_xml_path, $xml);
foreach ( $xml->endpoint as $endpoint ) {
if ( $endpoint['name'] == $_GET['action'] ) {
// Action has to be defined for documentation to work
if (array_key_exists('action', $_GET) && $endpoint['name'] == $_GET['action']) {
renderEndpoint($endpoint, $xml);
break;
}
Expand Down
30 changes: 30 additions & 0 deletions tests/unit_tests/regression/SentryIssue1Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);

/**
* @author Kasim Necdet Percinel <[email protected]>
*/

use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;

final class SentryIssue1Test extends TestCase
{
/**
* @group regression
* @group integration
**/
public function testItShouldDumpProperResponseCodeAndReasonPhraseIfThereIsNoActionGiven(): void
{
//Create a Guzzle client
$client = new Client();

// Send a GET request to the specified URL
$response = $client->get(HV_WEB_ROOT_URL, [
'http_errors' => false
]);

// Assert Status code and Reason Phrase
$this->assertEquals($response->getStatusCode(), 400);
$this->assertEquals($response->getReasonPhrase(), 'Bad Request');
}
}
6 changes: 3 additions & 3 deletions tests/unit_tests/request/RequestParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ final class RequestParamsTest extends TestCase
{
public function testItShouldCollectParamsEmptyArrIfThereIsNoRequestVariables()
{
$params = RequestParams::collect();

$params = RequestParams::collect();
$this->assertEmpty($params);
}

public function testItShouldCollectParamsIfGetRequest()
{
$_GET = ['get_param' => 'value1'];
$params = RequestParams::collect();
$params = RequestParams::collect();

$this->assertArrayHasKey('get_param', $params);
$this->assertEquals('value1', $params['get_param']);
Expand Down Expand Up @@ -104,6 +103,7 @@ protected function tearDown(): void
{
stream_wrapper_restore('php');
}

protected function setUp(): void
{
$_GET = [];
Expand Down

0 comments on commit dde4579

Please sign in to comment.