From fa53ce1723cdb6fef6793a39259e65d2066d6482 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sun, 8 Nov 2020 13:10:55 +0100 Subject: [PATCH] Add tests for Generator::getServerSSL() Signed-off-by: William Desportes --- test/classes/Html/GeneratorTest.php | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/test/classes/Html/GeneratorTest.php b/test/classes/Html/GeneratorTest.php index 42377b3274..5fd5cdb273 100644 --- a/test/classes/Html/GeneratorTest.php +++ b/test/classes/Html/GeneratorTest.php @@ -282,4 +282,107 @@ class GeneratorTest extends AbstractTestCase Generator::formatSql('SELECT 1 < 2', true) ); } + + /** + * Test for getServerSSL + */ + public function testGetServerSSL(): void + { + global $cfg; + + $sslNotUsed = 'SSL is not being used' + . ' Documentation'; + + $sslNotUsedCaution = 'SSL is not being used' + . ' Documentation'; + + $cfg['Server'] = [ + 'ssl' => false, + 'host' => '127.0.0.1', + ]; + $this->assertEquals( + $sslNotUsed, + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => false, + 'host' => 'custom.host', + ]; + $cfg['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1']; + + $this->assertEquals( + $sslNotUsedCaution, + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => false, + 'host' => 'custom.host', + ]; + $cfg['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1', 'custom.host']; + + $this->assertEquals( + $sslNotUsed, + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => false, + 'ssl_verify' => true, + 'host' => 'custom.host', + ]; + + $this->assertEquals( + $sslNotUsed, + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => true, + 'ssl_verify' => false, + 'host' => 'custom.host', + ]; + + $this->assertEquals( + 'SSL is used with disabled verification' + . ' Documentation', + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => true, + 'ssl_verify' => true, + 'host' => 'custom.host', + ]; + + $this->assertEquals( + 'SSL is used without certification authority' + . ' Documentation', + Generator::getServerSSL() + ); + + $cfg['Server'] = [ + 'ssl' => true, + 'ssl_verify' => true, + 'ssl_ca' => '/etc/ssl/ca.crt', + 'host' => 'custom.host', + ]; + + $this->assertEquals( + 'SSL is used' + . ' Documentation', + Generator::getServerSSL() + ); + } }