Throw error on invalid packages

This commit is contained in:
Roman Yurchak 2018-08-28 18:45:42 +03:00
parent c9d5ba3c8e
commit 11fcaf8da6
3 changed files with 22 additions and 15 deletions

View File

@ -3,7 +3,7 @@
*/
// Regexp for validating package name and URI
var package_name_regexp = '[a-z0-9_\-]+'
var package_name_regexp = '[a-z0-9_][a-z0-9_\-]*'
var package_uri_regexp =
new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i');
var package_name_regexp = new RegExp('^' + package_name_regexp + '$', 'i');
@ -44,8 +44,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
const package = _uri_to_package_name(package_uri);
if (package == null) {
console.log(`Invalid package name or URI '${package_uri}'`);
break;
throw new Error(`Invalid package name or URI '${package_uri}'`);
} else if (package == package_uri) {
package_uri = 'default channel';
}
@ -54,9 +53,10 @@ var languagePluginLoader = new Promise((resolve, reject) => {
if (package in loadedPackages) {
if (package_uri != loadedPackages[package]) {
console.log(`Error: URI mismatch, attempting to load package ` +
`${package} from ${package_uri} while it is already ` +
`loaded from ${loadedPackages[package]}!`);
throw new Error(
`URI mismatch, attempting to load package ` +
`${package} from ${package_uri} while it is already ` +
`loaded from ${loadedPackages[package]}!`);
}
} else {
toLoad[package] = package_uri;
@ -67,7 +67,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
}
});
} else {
console.log(`Unknown package '${package}'`);
log.console(`Unknown package '${package}'`);
}
}
}

View File

@ -40,7 +40,8 @@ def _display_driver_logs(browser, driver):
elif browser == 'firefox':
# browser logs are not available in GeckoDriver
# https://github.com/mozilla/geckodriver/issues/284
print('Cannot access browser logs for Firefox.')
print('Accessing raw browser logs with Selenium is not '
'supported by Firefox.')
class SeleniumWrapper:

View File

@ -1,3 +1,5 @@
import pytest
from selenium.common.exceptions import WebDriverException
def test_load_from_url(selenium_standalone, web_server):
@ -16,15 +18,19 @@ def test_load_from_url(selenium_standalone, web_server):
def test_uri_mismatch(selenium_standalone):
selenium_standalone.load_package('pyparsing')
selenium_standalone.load_package('http://some_url/pyparsing.js')
with pytest.raises(WebDriverException,
match="URI mismatch, attempting "
"to load package pyparsing"):
selenium_standalone.load_package('http://some_url/pyparsing.js')
assert "Invalid package name or URI" not in selenium_standalone.logs
assert ("URI mismatch, attempting "
"to load package pyparsing") in selenium_standalone.logs
def test_invalid_package_name(selenium):
selenium.load_package('wrong name+$')
assert "Invalid package name or URI" in selenium.logs
with pytest.raises(WebDriverException,
match="Invalid package name or URI"):
selenium.load_package('wrong name+$')
selenium.clean_logs()
selenium.load_package('tcp://some_url')
assert "Invalid package name or URI" in selenium.logs
with pytest.raises(WebDriverException,
match="Invalid package name or URI"):
selenium.load_package('tcp://some_url')