toaster: fix validation checks for DL_DIR and SSTATE_DIR
PATCH 2/2 bitbake: toaster-tests: tests for project config
In reply to Elliot SmithFrom: Sujith H <[email protected]>
Add basic tests to validate the value, user types in the text box for DL_DIR and SSTATE_DIR. Added test case to validate the first char and inclusion of space between the characters.
[YOCTO #9646]
--- .../tests/browser/test_project_config_page.py | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+)
bitbake/lib/toaster/tests/browser/test_project_config_page.py +113 -0
@@ -31,6 +31,9 @@ class TestProjectConfigsPage(SeleniumTestCase): """ Test data at /project/X/builds is displayed correctly """ PROJECT_NAME = 'test project' + INVALID_PATH_START_TEXT = 'The directory path should either start with a /' + INVALID_PATH_CHAR_TEXT = 'The directory path cannot include spaces or ' \ + 'any of these characters' def setUp(self): bbv = BitbakeVersion.objects.create(name='bbv1', giturl='/tmp/',
@@ -116,3 +119,113 @@ class TestProjectConfigsPage(SeleniumTestCase): checkbox.click() self.assertTrue(("cpio" not in element.text), "Image still present in the textbox") + + def test_set_download_dir(self): + """ + Validate the allowed and disallowed types in the directory field for + DL_DIR + """ + + ProjectVariable.objects.get_or_create(project=self.project1, + name='DL_DIR') + url = reverse('projectconf', args=(self.project1.id,)) + self.get(url) + + # activate the input to edit download dir + self.click('#change-dl_dir-icon') + self.wait_until_visible('#new-dl_dir') + + # downloads dir path doesn't start with / or ${...} + self.enter_text('#new-dl_dir', 'home/foo') + element = self.wait_until_visible('#hintError-initialChar-dl_dir') + + msg = 'downloads directory path starts with invalid character but ' \ + 'treated as valid' + self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) + + # downloads dir path has a space + self.driver.find_element_by_id('new-dl_dir').clear() + self.enter_text('#new-dl_dir', '/foo/bar a') + + element = self.wait_until_visible('#hintError-dl_dir') + msg = 'downloads directory path characters invalid but treated as valid' + self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) + + # downloads dir path starts with ${...} but has a space + self.driver.find_element_by_id('new-dl_dir').clear() + self.enter_text('#new-dl_dir', '${TOPDIR}/down foo') + + element = self.wait_until_visible('#hintError-dl_dir') + msg = 'downloads directory path characters invalid but treated as valid' + self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) + + # downloads dir path starts with / + self.driver.find_element_by_id('new-dl_dir').clear() + self.enter_text('#new-dl_dir', '/bar/foo') + + hidden_element = self.driver.find_element_by_id('hintError-dl_dir') + self.assertEqual(hidden_element.is_displayed(), False, + 'downloads directory path valid but treated as invalid') + + # downloads dir path starts with ${...} + self.driver.find_element_by_id('new-dl_dir').clear() + self.enter_text('#new-dl_dir', '${TOPDIR}/down') + + hidden_element = self.driver.find_element_by_id('hintError-dl_dir') + self.assertEqual(hidden_element.is_displayed(), False, + 'downloads directory path valid but treated as invalid') + + def test_set_sstate_dir(self): + """ + Validate the allowed and disallowed types in the directory field for + SSTATE_DIR + """ + + ProjectVariable.objects.get_or_create(project=self.project1, + name='SSTATE_DIR') + url = reverse('projectconf', args=(self.project1.id,)) + self.get(url) + + self.click('#change-sstate_dir-icon') + + self.wait_until_visible('#new-sstate_dir') + + # path doesn't start with / or ${...} + self.enter_text('#new-sstate_dir', 'home/foo') + element = self.wait_until_visible('#hintError-initialChar-sstate_dir') + + msg = 'sstate directory path starts with invalid character but ' \ + 'treated as valid' + self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg) + + # path has a space + self.driver.find_element_by_id('new-sstate_dir').clear() + self.enter_text('#new-sstate_dir', '/foo/bar a') + + element = self.wait_until_visible('#hintError-sstate_dir') + msg = 'sstate directory path characters invalid but treated as valid' + self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) + + # path starts with ${...} but has a space + self.driver.find_element_by_id('new-sstate_dir').clear() + self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo') + + element = self.wait_until_visible('#hintError-sstate_dir') + msg = 'sstate directory path characters invalid but treated as valid' + self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg) + + # path starts with / + self.driver.find_element_by_id('new-sstate_dir').clear() + self.enter_text('#new-sstate_dir', '/bar/foo') + + hidden_element = self.driver.find_element_by_id('hintError-sstate_dir') + self.assertEqual(hidden_element.is_displayed(), False, + 'sstate directory path valid but treated as invalid') + + # paths starts with ${...} + self.driver.find_element_by_id('new-sstate_dir').clear() + self.enter_text('#new-sstate_dir', '${TOPDIR}/down') + + hidden_element = self.driver.find_element_by_id('hintError-sstate_dir') + self.assertEqual(hidden_element.is_displayed(), False, + 'sstate directory path valid but treated as invalid')
Signature · 1 line
2.7.4
PATCH 1/2 toaster: fix validation checks for DL_DIR and SSTATE_DIR
From: Sujith H <[email protected]>
Validation logic on the project configuration page prevented a user from adding ${variable} to these paths.
Update validation so a user can see a better message when they type characters into the text inputs. Two types of validation are implemented.
Either:
* The value should start with a "/", to allow absolute paths.
or
* The value should start with a "$", to allow bitbake variables like ${TOPDIR}.
[YOCTO #9646]
--- .../toaster/toastergui/templates/projectconf.html | 71 +++++++++++++++------- 1 file changed, 49 insertions(+), 22 deletions(-)
bitbake/lib/toaster/toastergui/templates/projectconf.html +49 -22
@@ -41,7 +41,8 @@ </div> <button id="apply-change-dl_dir" class="btn btn-default" type="button">Save</button> <button id="cancel-change-dl_dir" type="button" class="btn btn-link">Cancel</button> - <p class="help-block" id="hintError-dl_dir">A valid directory cannot include spaces or any of these characters: . \ ? % * : | " " < ></p> + <p class="help-block" id="hintError-dl_dir" style="display:none;">The directory path cannot include spaces or any of these characters: . \ ? % * : | " " < ></p> + <p class="help-block" id="hintError-initialChar-dl_dir" style="display:none;">The directory path should either start with a /, e.g. /home/toaster/downloads; or with a variable, e.g. ${TOPDIR}/downloads.</p> </form> </dd> {% endif %}
@@ -88,7 +89,7 @@ <input type="text" class="form-control" id="new-image_install" placeholder="Type one or more package names"> </div> <button id="apply-change-image_install" class="btn btn-default" type="button">Save</button> - <button id="cancel-change-image_install" type="button" class="btn btn-link">Cancel</button> + <button id="cancel-change-image_install" type="button" class="btn btn-link">Cancel</button> </form> </dd> {% endif %}
@@ -149,7 +150,8 @@ </div> <button id="apply-change-sstate_dir" class="btn btn-default" type="button">Save</button> <button id="cancel-change-sstate_dir" type="button" class="btn btn-link">Cancel</button> - <p class="help-block" id="hintError-sstate_dir">A valid directory cannot include spaces or any of these characters: . \ ? % * : | " " < ></p> + <p class="help-block" id="hintError-sstate_dir" style="display:none;">The directory path cannot include spaces or any of these characters: . \ ? % * : | " " < ></p> + <p class="help-block" id="hintError-initialChar-sstate_dir" style="display:none;">The directory path should either start with a /, e.g. /home/toaster/sstate-cache; or with a variable, e.g. ${TOPDIR}/sstate-cache.</p> </form> </dd> {% endif %}
@@ -369,8 +371,8 @@ function setEventHandlersForDynamicElements() { $("#new-config_var_"+pk).val(current_val); if ( $("#new-config_var_"+pk).val().length ) { $("#apply-change-config_var_"+pk).removeAttr("disabled"); - } - else { + } + else { $("#apply-change-config_var_"+pk).attr("disabled"); } });
@@ -410,7 +412,7 @@ function setEventHandlersForDynamicElements() { var pk = $(this).attr("x-data"); // fade out the variable+value div, then refresh the variable list - $(this).fadeOut(); + $(this).fadeOut(); $(this).tooltip("hide"); $("config_var_entry_"+pk).fadeOut(); $('#config_var_value_'+pk).parent("dd").fadeOut();
@@ -553,7 +555,6 @@ $(document).ready(function() { // change DL_DIR variable $('#change-dl_dir-icon').click(function() { - $('#hintError-dl_dir').hide(); $('#change-dl_dir-form').removeClass('has-error'); // preset the edit value var current_val = $("#dl_dir").text().trim();
@@ -575,6 +576,8 @@ $(document).ready(function() { }); $('#cancel-change-dl_dir').click(function(){ + $("#hintError-dl_dir").hide(); + $("#hintError-initialChar-dl_dir").hide(); $("#change-dl_dir-form").slideUp(function() { $('#dl_dir, #change-dl_dir-icon').show(); });
@@ -583,20 +586,31 @@ $(document).ready(function() { $("#new-dl_dir").on('input', function(){ if ($(this).val().trim().length == 0) { $("#apply-change-dl_dir").attr("disabled","disabled"); + $('#change-dl_dir-form').addClass('has-error'); + $('#hintError-dl_dir').hide(); + $('#hintError-initialChar-dl_dir').hide(); } else { var input = $(this); - var re = /^\/([^ <>\\|":\.%\?\*]+)$/; + var reBeginWithSlash = /^\//; + var reCheckVariable = /^\$/; + var re = /([ <>\\|":\.%\?\*]+)/; var invalidDir = re.test(input.val()); - console.log(invalidDir); - if ( invalidDir ) { - $('#change-dl_dir-form').removeClass('has-error'); - $("#apply-change-dl_dir").removeAttr("disabled"); - $('#hintError-dl_dir').hide(); - } else { + var invalidSlash = reBeginWithSlash.test(input.val()); + var invalidVar = reCheckVariable.test(input.val()); + if (!invalidSlash && !invalidVar) { + $('#change-dl_dir-form').addClass('has-error'); + $("#apply-change-dl_dir").attr("disabled","disabled"); + $('#hintError-initialChar-dl_dir').show(); + } else if (invalidDir) { $('#change-dl_dir-form').addClass('has-error'); $("#apply-change-dl_dir").attr("disabled","disabled"); $('#hintError-dl_dir').show(); + } else { + $('#change-dl_dir-form').removeClass('has-error'); + $("#apply-change-dl_dir").removeAttr("disabled"); + $('#hintError-dl_dir').hide(); + $('#hintError-initialChar-dl_dir').hide(); } } });
@@ -905,7 +919,7 @@ $(document).ready(function() { // change SSTATE_DIR variable $('#change-sstate_dir-icon').click(function() { - $('#hintError-sstate_dir').hide(); + $('#change-sstate_dir-form').removeClass('has-error'); // preset the edit value var current_val = $("span#sstate_dir").text().trim(); if (current_val == "Not set") {
@@ -927,6 +941,8 @@ $(document).ready(function() { }); $('#cancel-change-sstate_dir').click(function(){ + $("#hintError-sstate_dir").hide(); + $("#hintError-initialChar-sstate_dir").hide(); $("#change-sstate_dir-form").slideUp(function() { $('#sstate_dir, #change-sstate_dir-icon').show(); });
@@ -935,20 +951,31 @@ $(document).ready(function() { $("#new-sstate_dir").on('input', function(){ if ($(this).val().trim().length == 0) { $("#apply-change-sstate_dir").attr("disabled","disabled"); + $('#change-sstate_dir-form').addClass('has-error'); + $('#hintError-sstate_dir').hide(); + $('#hintError-initialChar-sstate_dir').hide(); } else { var input = $(this); - var re = /^\/([^ <>\\|":\.%\?\*]+)$/; + var reBeginWithSlash = /^\//; + var reCheckVariable = /^\$/; + var re = /([ <>\\|":\.%\?\*]+)/; var invalidDir = re.test(input.val()); - console.log(invalidDir); - if ( invalidDir ) { + var invalidSlash = reBeginWithSlash.test(input.val()); + var invalidVar = reCheckVariable.test(input.val()); + if (!invalidSlash && !invalidVar) { + $('#change-sstate_dir-form').addClass('has-error'); + $("#apply-change-sstate_dir").attr("disabled","disabled"); + $('#hintError-initialChar-sstate_dir').show(); + } else if (invalidDir) { + $('#change-sstate_dir-form').addClass('has-error'); + $("#apply-change-sstate_dir").attr("disabled","disabled"); + $('#hintError-sstate_dir').show(); + } else { $('#change-sstate_dir-form').removeClass('has-error'); $("#apply-change-sstate_dir").removeAttr("disabled"); $('#hintError-sstate_dir').hide(); - } else { - $('#change-sstate_dir-form').addClass('has-error'); - $("#apply-change-sstate_dir").attr("disabled","disabled"); - $('#hintError-sstate_dir').show(); + $('#hintError-initialChar-sstate_dir').hide(); } } });
Signature · 1 line
2.7.4