ConnectionConfiguration - add $verifySslCertificate property - if is set to true, the SSL certificate verification is turned on, otherwise - turned off

It's useful while running application with custom, non-official SSL certificate, e.g. while development process.
This commit is contained in:
Meritoo
2017-09-27 21:32:28 +02:00
parent 0fbfc9780d
commit b3b0e66fb3
3 changed files with 63 additions and 6 deletions

View File

@@ -59,15 +59,26 @@ class ConnectionConfiguration
*/ */
private $debugMode = false; private $debugMode = false;
/**
* If is set to true, the SSL certificate verification is turned on. Otherwise - turned off.
* It's useful while running application with custom, non-official SSL certificate, e.g. while development process.
*
* @var bool
*/
private $verifySslCertificate = true;
/** /**
* Class constructor * Class constructor
* *
* @param string $baseUrl Base url. Protocol & domain. * @param string $baseUrl Base url. Protocol & domain.
* @param string $username Name of user used to authenticate to LimeSurvey * @param string $username Name of user used to authenticate to LimeSurvey
* @param string $password Password used to authenticate to LimeSurvey * @param string $password Password used to authenticate to LimeSurvey
* @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise - turned off. * @param bool $debugMode (optional) If is set to true, the "debug" mode is turned on. Otherwise -
* turned off.
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned
* on. Otherwise - turned off.
*/ */
public function __construct($baseUrl, $username, $password, $debugMode = false) public function __construct($baseUrl, $username, $password, $debugMode = false, $verifySslCertificate = true)
{ {
$this $this
->setBaseUrl($baseUrl) ->setBaseUrl($baseUrl)
@@ -201,6 +212,30 @@ class ConnectionConfiguration
return $this; return $this;
} }
/**
* Returns information if the SSL certificate verification is turned on
*
* @return bool
*/
public function isVerifySslCertificateOn()
{
return $this->verifySslCertificate;
}
/**
* Sets information if the SSL certificate verification is turned on
*
* @param bool $verifySslCertificate (optional) If is set to true, the SSL certificate verification is turned on.
* Otherwise - turned off.
* @return $this
*/
public function setVerifySslCertificate($verifySslCertificate = true)
{
$this->verifySslCertificate = $verifySslCertificate;
return $this;
}
/* /*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Additional / extra methods (neither getters, nor setters) * Additional / extra methods (neither getters, nor setters)

View File

@@ -90,6 +90,16 @@ class JsonRpcClientManager
->getHttpClient() ->getHttpClient()
->withDebug(); ->withDebug();
} }
/*
* The SSL certificate verification is turned off?
*/
if (!$this->connectionConfiguration->isVerifySslCertificateOn()) {
$this
->rpcClient
->getHttpClient()
->withoutSslVerification();
}
} }
return $this->rpcClient; return $this->rpcClient;

View File

@@ -31,7 +31,7 @@ class ConnectionConfigurationTest extends BaseTestCase
public function testConstructorVisibilityAndArguments() public function testConstructorVisibilityAndArguments()
{ {
static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 4, 3); static::assertConstructorVisibilityAndArguments(ConnectionConfiguration::class, OopVisibilityType::IS_PUBLIC, 5, 3);
} }
/** /**
@@ -101,6 +101,18 @@ class ConnectionConfigurationTest extends BaseTestCase
static::assertTrue($this->simpleConfiguration->isDebugModeOn()); static::assertTrue($this->simpleConfiguration->isDebugModeOn());
} }
public function testSetVerifySslCertificate()
{
$this->simpleConfiguration->setVerifySslCertificate();
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
$this->simpleConfiguration->setVerifySslCertificate(false);
static::assertFalse($this->simpleConfiguration->isVerifySslCertificateOn());
$this->simpleConfiguration->setVerifySslCertificate(true);
static::assertTrue($this->simpleConfiguration->isVerifySslCertificateOn());
}
public function testGetFullUrl() public function testGetFullUrl()
{ {
$this->simpleConfiguration->setRemoteControlUrl('lorem/ipsum'); $this->simpleConfiguration->setRemoteControlUrl('lorem/ipsum');