From 7c6b2c8cd37aa0530c045a8c826338acd17ea911 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 10 Jan 2023 14:14:38 -0800 Subject: [PATCH] Disable extern/soap.php. Remove implementation and tests. --- CRM/Utils/SoapServer.php | 319 +------------------------- extern/soap.php | 31 +-- tests/phpunit/E2E/Extern/SoapTest.php | 98 -------- 3 files changed, 17 insertions(+), 431 deletions(-) delete mode 100644 tests/phpunit/E2E/Extern/SoapTest.php diff --git a/CRM/Utils/SoapServer.php b/CRM/Utils/SoapServer.php index 46c24b98b6..4e13610579 100644 --- a/CRM/Utils/SoapServer.php +++ b/CRM/Utils/SoapServer.php @@ -10,322 +10,21 @@ */ /** - * This class handles all SOAP client requests. + * (OBSOLETE) This class previously handled SOAP requests. * + * The class is still referenced in some other repos. A stub is preserved to avoid hard-crashes + * when scanning the codebase. + * + * @deprecated * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing */ class CRM_Utils_SoapServer { - /** - * Number of seconds we should let a soap process idle - * @var int - */ - public static $soap_timeout = 0; - - /** - * Cache the actual UF Class - * @var string - */ - public $ufClass; - - /** - * Class constructor. This caches the real user framework class locally, - * so we can use it for authentication and validation. - * - * @internal param string $uf The userframework class - */ - public function __construct() { - // any external program which call SoapServer is responsible for - // creating and attaching the session - $args = func_get_args(); - $this->ufClass = array_shift($args); - } - - /** - * Simple ping function to test for liveness. - * - * @param string $var - * The string to be echoed. - * - * @return string - */ - public function ping($var) { - $session = CRM_Core_Session::singleton(); - $key = $session->get('key'); - $session->set('key', $var); - return "PONG: $var ($key)"; - } - - /** - * Verify a SOAP key. - * - * @param string $key - * The soap key generated by authenticate(). - * - * @throws SoapFault - */ - public function verify($key) { - $session = CRM_Core_Session::singleton(); - - $soap_key = $session->get('soap_key'); - $t = time(); - - if ($key !== sha1($soap_key)) { - throw new SoapFault('Client', 'Invalid key'); - } - - if (self::$soap_timeout && - $t > ($session->get('soap_time') + self::$soap_timeout) - ) { - throw new SoapFault('Client', 'Expired key'); - } - - // otherwise, we're ok. update the timestamp - - $session->set('soap_time', $t); - } - - /** - * Authentication wrapper to the UF Class. - * - * @param string $name - * Login name. - * @param string $pass - * Password. - * - * @param bool $loadCMSBootstrap - * - * @throws SoapFault - * @return string - * The SOAP Client key - */ - public function authenticate($name, $pass, $loadCMSBootstrap = FALSE) { - require_once str_replace('_', DIRECTORY_SEPARATOR, $this->ufClass) . '.php'; - - if ($this->ufClass == 'CRM_Utils_System_Joomla' - || $this->ufClass == 'CRM_Utils_System_WordPress') { - $loadCMSBootstrap = TRUE; - } - - $result = CRM_Utils_System::authenticate($name, $pass, $loadCMSBootstrap); - - if (empty($result)) { - throw new SoapFault('Client', 'Invalid login'); - } - - $session = CRM_Core_Session::singleton(); - $session->set('soap_key', $result[2]); - $session->set('soap_time', time()); - - return sha1($result[2]); - } - - /** - * MAILER API. - * - * @param string $key - * @param int $job - * @param int $queue - * @param string $hash - * @param string $body - * - * @return array|int - * @throws \SoapFault - */ - public function mailer_event_bounce($key, $job, $queue, $hash, $body) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'time_stamp' => date('YmdHis'), - 'event_queue_id' => $queue, - 'hash' => $hash, - 'body' => $body, - 'version' => 3, - ]; - $result = civicrm_api('Mailing', 'event_bounce', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * Mailer event unsubscribe. - * - * @param string $key - * @param int $job - * @param int $queue - * @param string $hash - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_unsubscribe($key, $job, $queue, $hash) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'time_stamp' => date('YmdHis'), - 'org_unsubscribe' => 0, - 'event_queue_id' => $queue, - 'hash' => $hash, - 'version' => 3, - ]; - $result = civicrm_api('MailingGroup', 'event_unsubscribe', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $job - * @param $queue - * @param $hash - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_domain_unsubscribe($key, $job, $queue, $hash) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'time_stamp' => date('YmdHis'), - 'org_unsubscribe' => 1, - 'event_queue_id' => $queue, - 'hash' => $hash, - 'version' => 3, - ]; - $result = civicrm_api('MailingGroup', 'event_domain_unsubscribe', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $job - * @param $queue - * @param $hash - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_resubscribe($key, $job, $queue, $hash) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'time_stamp' => date('YmdHis'), - 'org_unsubscribe' => 0, - 'event_queue_id' => $queue, - 'hash' => $hash, - 'version' => 3, - ]; - $result = civicrm_api('MailingGroup', 'event_resubscribe', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $email - * @param $domain - * @param $group - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_subscribe($key, $email, $domain, $group) { - $this->verify($key); - $params = [ - 'email' => $email, - 'group_id' => $group, - 'version' => 3, - ]; - $result = civicrm_api('MailingGroup', 'event_subscribe', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $contact - * @param $subscribe - * @param $hash - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_confirm($key, $contact, $subscribe, $hash) { - $this->verify($key); - $params = [ - 'contact_id' => $contact, - 'subscribe_id' => $subscribe, - 'time_stamp' => date('YmdHis'), - 'event_subscribe_id' => $subscribe, - 'hash' => $hash, - 'version' => 3, - ]; - $result = civicrm_api('Mailing', 'event_confirm', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $job - * @param $queue - * @param $hash - * @param $bodyTxt - * @param $rt - * @param null $bodyHTML - * @param null $fullEmail - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_reply($key, $job, $queue, $hash, $bodyTxt, $rt, $bodyHTML = NULL, $fullEmail = NULL) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'event_queue_id' => $queue, - 'hash' => $hash, - 'bodyTxt' => $bodyTxt, - 'replyTo' => $rt, - 'bodyHTML' => $bodyHTML, - 'fullEmail' => $fullEmail, - 'time_stamp' => date('YmdHis'), - 'version' => 3, - ]; - $result = civicrm_api('Mailing', 'event_reply', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param $job - * @param $queue - * @param $hash - * @param $email - * - * @return array|int - * @throws SoapFault - */ - public function mailer_event_forward($key, $job, $queue, $hash, $email) { - $this->verify($key); - $params = [ - 'job_id' => $job, - 'event_queue_id' => $queue, - 'hash' => $hash, - 'email' => $email, - 'version' => 3, - ]; - $result = civicrm_api('Mailing', 'event_forward', $params); - return CRM_Utils_Array::encode_items($result); - } - - /** - * @param $key - * @param array $params - * - * @return array|int - * @throws SoapFault - */ - public function get_contact($key, $params) { - $this->verify($key); - $params['version'] = 3; - $result = civicrm_api('contact', 'get', $params); - return CRM_Utils_Array::encode_items($result); + public function __call($name, $arguments) { + throw new \SoapFault('obsolete', 'SOAP support is no longer included with civicrm-core.'); + // It's removed because (a) the main consumer is no longer live, (b) it's awkward to maintain 'extern/' scripts, + // and (c) there's an extensionized version at https://lab.civicrm.org/extensions/civismtp/ } } diff --git a/extern/soap.php b/extern/soap.php index fcd2318d66..3da3f2ce58 100644 --- a/extern/soap.php +++ b/extern/soap.php @@ -14,26 +14,11 @@ if (defined('PANTHEON_ENVIRONMENT')) { } session_start(); -require_once '../civicrm.config.php'; -require_once 'CRM/Core/Config.php'; - -$server = new SoapServer(NULL, - array( - 'uri' => 'urn:civicrm', - 'soap_version' => SOAP_1_2, - ) -); - - -require_once 'CRM/Utils/SoapServer.php'; -$crm_soap = new CRM_Utils_SoapServer(); - -/* Cache the real UF, override it with the SOAP environment */ - -$civicrmConfig = CRM_Core_Config::singleton(); - -$server->setClass('CRM_Utils_SoapServer', $civicrmConfig->userFrameworkClass); - -$server->setPersistence(SOAP_PERSISTENCE_SESSION); - -$server->handle(); +$server = new SoapServer(NULL, [ + 'uri' => 'urn:civicrm', + 'soap_version' => SOAP_1_2, +]); + +$server->fault('obsolete', "SOAP support is no longer included with civicrm-core."); +// It's removed because (a) the main consumer is no longer live, (b) it's awkward to maintain 'extern/' scripts, +// and (c) there's an extensionized version at https://lab.civicrm.org/extensions/civismtp/ diff --git a/tests/phpunit/E2E/Extern/SoapTest.php b/tests/phpunit/E2E/Extern/SoapTest.php deleted file mode 100644 index 1a8af4079b..0000000000 --- a/tests/phpunit/E2E/Extern/SoapTest.php +++ /dev/null @@ -1,98 +0,0 @@ -markTestSkipped('Unsupported environment'); - } - - global $_CV; - $this->adminUser = $_CV['ADMIN_USER']; - $this->adminPass = $_CV['ADMIN_PASS']; - $this->url = CRM_Core_Resources::singleton()->getUrl('civicrm', 'extern/soap.php'); - - foreach (array('adminUser', 'adminPass', 'url') as $prop) { - if (empty($this->{$prop})) { - $this->markTestSkipped("Failed to lookup SOAP URL, user, or password. Have you configured `cv` for testing?"); - } - } - } - - /** - * Send a request with bad credentials. - */ - public function testAuthenticationBadPassword() { - $this->expectException(SoapFault::class); - $client = $this->createClient(); - $client->authenticate($this->adminUser, mt_rand()); - } - - /** - * Send a request with bad credentials. - */ - public function testAuthenticationBadKey() { - $this->expectException(SoapFault::class); - $client = $this->createClient(); - $key = $client->authenticate($this->adminUser, $this->adminPass); - $client->get_contact(mt_rand(), []); - } - - /** - * A basic test for one SOAP function. - */ - public function testGetContact() { - $client = $this->createClient(); - $key = $client->authenticate($this->adminUser, $this->adminPass); - $contacts = $client->get_contact($key, array( - 'contact_id' => 101, - 'return.display_name' => 1, - )); - $this->assertEquals($contacts['is_error'], 0); - $this->assertEquals($contacts['count'], 1); - $this->assertEquals($contacts['values'][101]['contact_id'], 101); - } - - /** - * @return \SoapClient - */ - protected function createClient() { - return new SoapClient(NULL, array( - 'location' => $this->url, - 'uri' => 'urn:civicrm', - 'trace' => 1, - )); - } - -} -- 2.25.1