Skip to content

Commit

Permalink
fix(console): permit valid URL to be use in the device packages tab.
Browse files Browse the repository at this point in the history
- Some valid URL was considered illegal in the device packages tab.
- Add the URL validation check even on the backend side
  • Loading branch information
MDeLuise authored and Coduz committed Jul 3, 2023
1 parent e0ca46c commit 09d9983
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.google.gwt.core.client.GWT;

import org.eclipse.kapua.app.console.module.api.client.messages.ValidationMessages;

import java.util.MissingResourceException;
Expand Down Expand Up @@ -70,7 +69,7 @@ public enum FieldType {
ALPHANUMERIC("alphanumeric", "^[a-zA-Z0-9_]+$"),
NUMERIC("numeric", "^[+0-9.]+$"),
PACKAGE_VERSION("package_version", "^[a-zA-Z0-9.\\-\\_]*$"),
URL("url", "(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)");
URL("url", "^(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=//]{1,256}\\.[a-zA-Z0-9()//]{2,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$");

private String name;
private String regex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.google.common.base.MoreObjects;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.commons.model.id.IdGenerator;
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.commons.util.ArgumentValidator;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions;
import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest;

import java.net.MalformedURLException;
import java.util.Date;

/**
Expand Down Expand Up @@ -143,6 +145,12 @@ public KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDown
// Check Access
AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId));

try {
packageDownloadRequest.getUri().toURL();
} catch (MalformedURLException | IllegalArgumentException ignored) {
throw new KapuaIllegalArgumentException("packageDownloadRequest.uri", packageDownloadRequest.getUri().toString());
}

//
// Generate requestId
KapuaId operationId = new KapuaEid(IdGenerator.generate());
Expand Down

0 comments on commit 09d9983

Please sign in to comment.