Skip to content

Commit

Permalink
[HOPSWORKS-2805] Regex for validating library name does not allow squ…
Browse files Browse the repository at this point in the history
…are brackets (#966)
  • Loading branch information
robzor92 committed Nov 23, 2021
1 parent 4023640 commit 5b92555
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 6 additions & 6 deletions hopsworks-IT/src/test/ruby/spec/conda_spec.rb
Expand Up @@ -312,13 +312,13 @@
it 'install versioned libraries' do
@project = create_env_and_update_project(@project, ENV['PYTHON_VERSION'])

install_library(@project[:id], ENV['PYTHON_VERSION'], 'tflearn', 'PIP', '0.3.2', conda_channel)
install_library(@project[:id], ENV['PYTHON_VERSION'], 'modin%5Bdask%5D', 'PIP', '0.11.2', conda_channel)
expect_status(201)

install_library(@project[:id], ENV['PYTHON_VERSION'], 'imageio', 'CONDA', '2.9.0', conda_channel)
expect_status(201)

get_library_commands(@project[:id], ENV['PYTHON_VERSION'], 'tflearn')
get_library_commands(@project[:id], ENV['PYTHON_VERSION'], 'modin%5Bdask%5D')
expect_status(200)
expect(json_body[:count]).to be == 1

Expand All @@ -330,7 +330,7 @@
CondaCommands.find_by(project_id: @project[:id]).nil?
end

get_library_commands(@project[:id], ENV['PYTHON_VERSION'], 'tflearn')
get_library_commands(@project[:id], ENV['PYTHON_VERSION'], 'modin%5Bdask%5D')
expect_status(200)
expect(json_body[:count]).to be == 0

Expand All @@ -340,11 +340,11 @@

list_libraries(@project[:id], ENV['PYTHON_VERSION'])

tflearn_library = json_body[:items].detect { |library| library[:library] == "tflearn" }
modin_library = json_body[:items].detect { |library| library[:library] == "modin" }
imageio_library = json_body[:items].detect { |library| library[:library] == "imageio" }

expect(tflearn_library[:packageSource]).to eq ("PIP")
expect(tflearn_library[:version]).to eq ("0.3.2")
expect(modin_library[:packageSource]).to eq ("PIP")
expect(modin_library[:version]).to eq ("0.11.2")

expect(imageio_library[:packageSource]).to eq("CONDA")
expect(imageio_library[:version]).to eq ("2.9.0")
Expand Down
Expand Up @@ -97,7 +97,7 @@ public class LibraryResource {
@EJB
private JWTHelper jwtHelper;

private static final Pattern VALIDATION_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-\\.]+");
private static final Pattern VALIDATION_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-\\.\\]\\[]+");
private static final Pattern CHANNEL_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-:/~?&\\.]+");

private Project project;
Expand Down
Expand Up @@ -45,6 +45,8 @@
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Stateless
Expand All @@ -60,6 +62,8 @@ public class CommandsController {
private ProjectFacade projectFacade;
@EJB
private LibraryFacade libraryFacade;

private static final Pattern BRACKET_PATTERN = Pattern.compile("^(.*\\[.*\\])$");

public void deleteCommands(Project project, String library) {
//Failed installation commands should remove
Expand Down Expand Up @@ -225,10 +229,12 @@ private boolean isPlaceholderDep(CondaCommands command, CondaOp condaOp) {
command.getInstallType().equals(CondaInstallType.ENVIRONMENT_YAML)) {
return true;
}

Matcher bracketMatcher = BRACKET_PATTERN.matcher(command.getLib());
if(condaOp.equals(CondaOp.INSTALL) &&
(command.getInstallType().equals(CondaInstallType.PIP)
|| command.getInstallType().equals(CondaInstallType.CONDA))
&& command.getVersion().equals(Settings.UNKNOWN_LIBRARY_VERSION)) {
&& (command.getVersion().equals(Settings.UNKNOWN_LIBRARY_VERSION) || bracketMatcher.matches())) {
return true;
}
return false;
Expand Down

0 comments on commit 5b92555

Please sign in to comment.