From f9ee9d1ddfac13fa883cdeeb0bc11ab78cb2ca1d Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 24 Nov 2016 00:20:09 +0530 Subject: [PATCH 1/2] Refactor SSL requires div to use template Signed-off-by: Deven Bansod --- js/server_privileges.js | 4 +- libraries/server_privileges.lib.php | 236 +++++++----------- templates/privileges/require_options.phtml | 16 ++ .../privileges/require_options_item.phtml | 23 ++ 4 files changed, 137 insertions(+), 142 deletions(-) create mode 100644 templates/privileges/require_options.phtml create mode 100644 templates/privileges/require_options_item.phtml diff --git a/js/server_privileges.js b/js/server_privileges.js index 154f74770e..18c37875f2 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -392,7 +392,7 @@ AJAX.registerOnload('server_privileges.js', function () { $(document).on('change', 'input[name="ssl_type"]', function (e) { var $div = $('#specified_div'); - if ($('#ssl_type_specified').is(':checked')) { + if ($('#ssl_type_SPECIFIED').is(':checked')) { $div.find('input').prop('disabled', false); } else { $div.find('input').prop('disabled', true); @@ -403,7 +403,7 @@ AJAX.registerOnload('server_privileges.js', function () { var $div = $('#require_ssl_div'); if ($(this).is(':checked')) { $div.find('input').prop('disabled', false); - $('#ssl_type_specified').trigger('change'); + $('#ssl_type_SPECIFIED').trigger('change'); } else { $div.find('input').prop('disabled', true); } diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 5488f79770..80dbece16c 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -699,148 +699,104 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', */ function PMA_getHtmlForRequires($row) { - $html_output = '
'; - $html_output .= 'SSL'; - - $html_output .= '
'; - - // REQUIRE NONE - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE SSL - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE X509 - $html_output .= '
'; - $html_output .= ''; - - $html_output .= ''; - $html_output .= '
'; - - // Specified $specified = (isset($row['ssl_type']) && $row['ssl_type'] == 'SPECIFIED'); - $html_output .= '
'; - $html_output .= ''; + $require_options = array( + array( + 'name' => 'ssl_type', + 'value' => 'NONE', + 'description' => __( + 'Does not require SSL-encrypted connections.' + ), + 'label' => 'REQUIRE NONE', + 'checked' => ((isset($row['ssl_type']) + && ($row['ssl_type'] == 'NONE' + || $row['ssl_type'] == '')) + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'ANY', + 'description' => __( + 'Requires SSL-encrypted connections.' + ), + 'label' => 'REQUIRE SSL', + 'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'ANY') + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'X509', + 'description' => __( + 'Requires a valid X509 certificate.' + ), + 'label' => 'REQUIRE SSL', + 'checked' => (isset($row['ssl_type']) && ($row['ssl_type'] == 'X509') + ? 'checked="checked"' + : '' + ), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_type', + 'value' => 'SPECIFIED', + 'description' => '', + 'label' => 'SPECIFIED', + 'checked' => ($specified ? 'checked="checked"' : ''), + 'disabled' => false, + 'radio' => true + ), + array( + 'name' => 'ssl_cipher', + 'value' => (isset($row['ssl_cipher']) + ? htmlspecialchars($row['ssl_cipher']) : '' + ), + 'description' => __( + 'Requires that a specific cipher method be used for a connection.' + ), + 'label' => 'REQUIRE CIPHER', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + array( + 'name' => 'x509_issuer', + 'value' => (isset($row['x509_issuer']) + ? htmlspecialchars($row['x509_issuer']) : '' + ), + 'description' => __( + 'Requires that a valid X509 certificate issued by this CA be presented.' + ), + 'label' => 'REQUIRE ISSUER', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + array( + 'name' => 'x509_subject', + 'value' => (isset($row['x509_subject']) + ? htmlspecialchars($row['x509_subject']) : '' + ), + 'description' => __( + 'Requires that a valid X509 certificate with this subject be presented.' + ), + 'label' => 'REQUIRE SUBJECT', + 'checked' => '', + 'disabled' => ! $specified, + 'radio' => false + ), + ); - $html_output .= ''; - $html_output .= '
'; - - $html_output .= '
'; - - // REQUIRE CIPHER - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE ISSUER - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - // REQUIRE SUBJECT - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; - - $html_output .= '
'; - - $html_output .= '
'; - $html_output .= '
'; + $html_output = Template::get('privileges/require_options') + ->render(array('require_options' => $require_options)); return $html_output; } diff --git a/templates/privileges/require_options.phtml b/templates/privileges/require_options.phtml new file mode 100644 index 0000000000..6261786246 --- /dev/null +++ b/templates/privileges/require_options.phtml @@ -0,0 +1,16 @@ +
+ SSL +
+ + +
+ + render( + array('require_option' => $require_option) + ); + ?> + +
+
+
\ No newline at end of file diff --git a/templates/privileges/require_options_item.phtml b/templates/privileges/require_options_item.phtml new file mode 100644 index 0000000000..867fea919e --- /dev/null +++ b/templates/privileges/require_options_item.phtml @@ -0,0 +1,23 @@ +
+ + + /> + + + + + disabled + + /> + +
\ No newline at end of file From 8eec21b21b17dcb332b1bc7d05c7bb21908c4d26 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 24 Nov 2016 00:20:47 +0530 Subject: [PATCH 2/2] Add tests Signed-off-by: Deven Bansod --- test/libraries/PMA_server_privileges_test.php | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index d781f3607e..83f67726fd 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -372,7 +372,138 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase _pgettext('None privileges', 'None'), $html ); + } + /** + * Test for PMA_getHtmlForRequires + * + * @return void + */ + public function testPMAGetHtmlForRequires() + { + /* Assertion 1 */ + $row = array( + 'ssl_type' => '', + 'ssh_cipher' => '' + ); + + $html = PMA_getHtmlForRequires( + $row + ); + // SSL + $this->assertContains( + 'SSL', + $html + ); + $this->assertContains( + 'value="NONE" checked="checked"', + $html + ); + $this->assertContains( + 'value="ANY"', + $html + ); + $this->assertContains( + 'value="X509"', + $html + ); + $this->assertContains( + 'value="SPECIFIED"', + $html + ); + + /* Assertion 2 */ + $row = array( + 'ssl_type' => 'ANY', + 'ssh_cipher' => '' + ); + + $html = PMA_getHtmlForRequires( + $row + ); + // SSL + $this->assertContains( + 'SSL', + $html + ); + $this->assertContains( + 'value="NONE"', + $html + ); + $this->assertContains( + 'value="ANY" checked="checked"', + $html + ); + $this->assertContains( + 'value="X509"', + $html + ); + $this->assertContains( + 'value="SPECIFIED"', + $html + ); + + /* Assertion 3 */ + $row = array( + 'ssl_type' => 'X509', + 'ssh_cipher' => '' + ); + + $html = PMA_getHtmlForRequires( + $row + ); + // SSL + $this->assertContains( + 'SSL', + $html + ); + $this->assertContains( + 'value="NONE"', + $html + ); + $this->assertContains( + 'value="ANY"', + $html + ); + $this->assertContains( + 'value="X509" checked="checked"', + $html + ); + $this->assertContains( + 'value="SPECIFIED"', + $html + ); + + /* Assertion 4 */ + $row = array( + 'ssl_type' => 'SPECIFIED', + 'ssh_cipher' => '' + ); + + $html = PMA_getHtmlForRequires( + $row + ); + // SSL + $this->assertContains( + 'SSL', + $html + ); + $this->assertContains( + 'value="NONE"', + $html + ); + $this->assertContains( + 'value="ANY"', + $html + ); + $this->assertContains( + 'value="X509"', + $html + ); + $this->assertContains( + 'value="SPECIFIED" checked="checked"', + $html + ); } /**