-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19727 from totten/master-authx-rest
(dev/core#2077) Make 'civicrm/ajax/rest' interoperable with 'extern/rest.php' parameters
- Loading branch information
Showing
9 changed files
with
210 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Authx; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
|
||
/** | ||
* Historically, 'extern/rest.php' and 'civicrm/ajax/rest' were similar interfaces | ||
* based on the same controller, but they used different authentication styles. | ||
* | ||
* This authenticator is activated if one requests 'civicrm/ajax/rest' using the | ||
* authentication style of 'extern/rest.php'. | ||
* | ||
* @package Civi\Authx | ||
*/ | ||
class LegacyRestAuthenticator extends Authenticator { | ||
|
||
protected function reject($message = 'Authentication failed') { | ||
$data = ["error_message" => "FATAL: $message", "is_error" => 1]; | ||
$r = new Response(200, ['Content-Type' => 'text/javascript'], json_encode($data)); | ||
\CRM_Utils_System::sendResponse($r); | ||
} | ||
|
||
protected function login(AuthenticatorTarget $tgt) { | ||
parent::login($tgt); | ||
\Civi::dispatcher()->addListener('hook_civicrm_permission_check', function ($e) { | ||
if ($e->permission === 'access AJAX API') { | ||
$e->granted = TRUE; | ||
} | ||
}); | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Verify that the REST API bindings correctly parse and authenticate requests. | ||
* | ||
* @group e2e | ||
*/ | ||
class E2E_Extern_AuthxRestTest extends E2E_Extern_BaseRestTest { | ||
|
||
public static function setUpBeforeClass(): void { | ||
parent::setUpBeforeClass(); | ||
\Civi\Test::e2e() | ||
->install(['authx']) | ||
->callback( | ||
function() { | ||
\CRM_Utils_System::synchronizeUsers(); | ||
}, | ||
'synchronizeUsers' | ||
) | ||
->apply(); | ||
} | ||
|
||
protected function getRestUrl() { | ||
return CRM_Utils_System::url('civicrm/ajax/rest', NULL, TRUE, NULL, FALSE, TRUE); | ||
} | ||
|
||
public function apiTestCases() { | ||
$r = parent::apiTestCases(); | ||
$r = array_filter($r, function($case) { | ||
// The 'civicrm/ajax/rest' end-point does not support '?q' inputs. | ||
return !isset($case[0]['q']); | ||
}); | ||
return $r; | ||
} | ||
|
||
} |
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 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Verify that the REST API bindings correctly parse and authenticate requests. | ||
* | ||
* @group e2e | ||
*/ | ||
class E2E_Extern_LegacyRestTest extends E2E_Extern_BaseRestTest { | ||
|
||
protected function setUp(): void { | ||
if (CIVICRM_UF === 'Drupal8') { | ||
$this->markTestSkipped('Legacy extern/rest.php does not apply to Drupal 8+'); | ||
} | ||
parent::setUp(); | ||
} | ||
|
||
protected function getRestUrl() { | ||
return CRM_Core_Resources::singleton() | ||
->getUrl('civicrm', 'extern/rest.php'); | ||
} | ||
|
||
} |