|
|
|
|
@@ -18,13 +18,7 @@ import java.util.List;
|
|
|
|
|
import io.qameta.allure.Description;
|
|
|
|
|
import io.qameta.allure.Feature;
|
|
|
|
|
import io.qameta.allure.Story;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.ApiType;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.ArtifactUrl;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.ArtifactUrlHandler;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.ArtifactUrlHandlerProperties;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.ArtifactUrlHandlerProperties.UrlProtocol;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.PropertyBasedArtifactUrlHandler;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.URLPlaceholder;
|
|
|
|
|
import org.eclipse.hawkbit.artifact.repository.urlhandler.URLPlaceholder.SoftwareData;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
@@ -46,17 +40,18 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
private static final String CONTROLLER_ID = "Test";
|
|
|
|
|
private static final String FILENAME_DECODE = "test123!§$%&";
|
|
|
|
|
private static final String FILENAME_ENCODE = "test123%21%C2%A7%24%25%26";
|
|
|
|
|
private static final long SOFTWAREMODULEID = 87654L;
|
|
|
|
|
private static final long TARGETID = 3474366L;
|
|
|
|
|
private static final String TARGETID_BASE62 = "EZqA";
|
|
|
|
|
private static final long SOFTWARE_MODULE_ID = 87654L;
|
|
|
|
|
private static final long TARGET_ID = 3474366L;
|
|
|
|
|
private static final String TARGET_ID_BASE62 = "EZqA";
|
|
|
|
|
private static final String SHA1HASH = "test12345";
|
|
|
|
|
private static final long ARTIFACTID = 1345678L;
|
|
|
|
|
private static final String ARTIFACTID_BASE62 = "5e4U";
|
|
|
|
|
private static final long ARTIFACT_ID = 1345678L;
|
|
|
|
|
private static final String ARTIFACT_ID_BASE62 = "5e4U";
|
|
|
|
|
private static final String TENANT = "TEST_TENANT";
|
|
|
|
|
|
|
|
|
|
private static final String HTTP_LOCALHOST = "http://localhost:8080/";
|
|
|
|
|
private static URLPlaceholder placeholder = new URLPlaceholder(TENANT, TENANT_ID, CONTROLLER_ID, TARGETID,
|
|
|
|
|
new SoftwareData(SOFTWAREMODULEID, FILENAME_DECODE, ARTIFACTID, SHA1HASH));
|
|
|
|
|
private static final URLPlaceholder placeHolder = new URLPlaceholder(
|
|
|
|
|
TENANT, TENANT_ID, CONTROLLER_ID, TARGET_ID,
|
|
|
|
|
new SoftwareData(SOFTWARE_MODULE_ID, FILENAME_DECODE, ARTIFACT_ID, SHA1HASH));
|
|
|
|
|
private ArtifactUrlHandler urlHandlerUnderTest;
|
|
|
|
|
private ArtifactUrlHandlerProperties properties;
|
|
|
|
|
|
|
|
|
|
@@ -64,7 +59,6 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
public void setup() {
|
|
|
|
|
properties = new ArtifactUrlHandlerProperties();
|
|
|
|
|
urlHandlerUnderTest = new PropertyBasedArtifactUrlHandler(properties, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -72,13 +66,14 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
public void urlGenerationWithDefaultConfiguration() {
|
|
|
|
|
properties.getProtocols().put("download-http", new UrlProtocol());
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI);
|
|
|
|
|
final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI);
|
|
|
|
|
assertThat(ddiUrls).containsExactly(
|
|
|
|
|
new ArtifactUrl("http".toUpperCase(), "download-http", HTTP_LOCALHOST + TENANT + "/controller/v1/"
|
|
|
|
|
+ CONTROLLER_ID + "/softwaremodules/" + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
HTTP_LOCALHOST + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF);
|
|
|
|
|
assertThat(ddiUrls).isEqualTo(dmfUrls);
|
|
|
|
|
assertThat(ddiUrls).isEqualTo(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DMF));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -93,13 +88,11 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
proto.setRef("{protocol}://{ip}:{port}/fw/{tenant}/{controllerId}/sha1/{artifactSHA1}");
|
|
|
|
|
properties.getProtocols().put(TEST_PROTO, proto);
|
|
|
|
|
|
|
|
|
|
List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI);
|
|
|
|
|
|
|
|
|
|
assertThat(urls).isEmpty();
|
|
|
|
|
urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF);
|
|
|
|
|
|
|
|
|
|
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL,
|
|
|
|
|
"coap://127.0.0.1:5683/fw/" + TENANT + "/" + CONTROLLER_ID + "/sha1/" + SHA1HASH));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI)).isEmpty();
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DMF)).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
TEST_PROTO.toUpperCase(), TEST_REL,
|
|
|
|
|
"coap://127.0.0.1:5683/fw/" + TENANT + "/" + CONTROLLER_ID + "/sha1/" + SHA1HASH));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@@ -114,17 +107,15 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
proto.setRef("{protocol}://{ip}:{port}/fws/{tenant}/{targetIdBase62}/{artifactIdBase62}");
|
|
|
|
|
properties.getProtocols().put("ftp", proto);
|
|
|
|
|
|
|
|
|
|
List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI);
|
|
|
|
|
|
|
|
|
|
assertThat(urls).isEmpty();
|
|
|
|
|
urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF);
|
|
|
|
|
|
|
|
|
|
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL,
|
|
|
|
|
TEST_PROTO + "://127.0.0.1:5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI)).isEmpty();
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DMF)).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
TEST_PROTO.toUpperCase(), TEST_REL,
|
|
|
|
|
TEST_PROTO + "://127.0.0.1:5683/fws/" + TENANT + "/" + TARGET_ID_BASE62 + "/" + ARTIFACT_ID_BASE62));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verfies that the full qualified host of the statically defined hostname is replaced with the host of the request.")
|
|
|
|
|
@Description("Verifies that the full qualified host of the statically defined hostname is replaced with the host of the request.")
|
|
|
|
|
public void urlGenerationWithHostFromRequest() throws URISyntaxException {
|
|
|
|
|
final String testHost = "ddi.host.com";
|
|
|
|
|
|
|
|
|
|
@@ -137,15 +128,14 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
proto.setRef("{protocol}://{hostnameRequest}:{port}/fws/{tenant}/{targetIdBase62}/{artifactIdBase62}");
|
|
|
|
|
properties.getProtocols().put("ftp", proto);
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI,
|
|
|
|
|
new URI("https://" + testHost));
|
|
|
|
|
|
|
|
|
|
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + "://"
|
|
|
|
|
+ testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI, new URI("https://" + testHost))).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
TEST_PROTO.toUpperCase(), TEST_REL,
|
|
|
|
|
TEST_PROTO + "://" + testHost + ":5683/fws/" + TENANT + "/" + TARGET_ID_BASE62 + "/" + ARTIFACT_ID_BASE62));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verfies that the protocol of the statically defined hostname is replaced with the protocol of the request.")
|
|
|
|
|
@Description("Verifies that the protocol of the statically defined hostname is replaced with the protocol of the request.")
|
|
|
|
|
public void urlGenerationWithProtocolFromRequest() throws URISyntaxException {
|
|
|
|
|
final String testHost = "ddi.host.com";
|
|
|
|
|
|
|
|
|
|
@@ -153,74 +143,70 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|
|
|
|
proto.setRef("{protocolRequest}://{hostname}:{port}/fws/{tenant}/{targetIdBase62}/{artifactIdBase62}");
|
|
|
|
|
properties.getProtocols().put("download-http", proto);
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI,
|
|
|
|
|
new URI("https://" + testHost));
|
|
|
|
|
|
|
|
|
|
assertThat(urls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http",
|
|
|
|
|
"https://localhost:8080/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI, new URI("https://" + testHost))).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
"https://localhost:8080/fws/" + TENANT + "/" + TARGET_ID_BASE62 + "/" + ARTIFACT_ID_BASE62));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verfies that the port of the statically defined hostname is replaced with the port of the request.")
|
|
|
|
|
@Description("Verifies that the port of the statically defined hostname is replaced with the port of the request.")
|
|
|
|
|
public void urlGenerationWithPortFromRequest() throws URISyntaxException {
|
|
|
|
|
final UrlProtocol proto = new UrlProtocol();
|
|
|
|
|
proto.setRef(
|
|
|
|
|
"{protocol}://{hostname}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
proto.setRef("{protocol}://{hostname}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
|
|
|
|
|
properties.getProtocols().put("download-http", proto);
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI,
|
|
|
|
|
new URI("http://anotherHost.com:8083"));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI, new URI("http://anotherHost.com:8083"))).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
"http://localhost:8083/" + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
assertThat(ddiUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http",
|
|
|
|
|
"http://localhost:8083/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
|
|
|
|
+ SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF);
|
|
|
|
|
|
|
|
|
|
assertThat(dmfUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http",
|
|
|
|
|
"http://localhost:8080/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
|
|
|
|
+ SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DMF)).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
"http://localhost:8080/" + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verfies that if default protocol port in request is used then url is returned without port")
|
|
|
|
|
@Description("Verifies that if default protocol port in request is used then url is returned without port")
|
|
|
|
|
public void urlGenerationWithPortFromRequestForHttps() throws URISyntaxException {
|
|
|
|
|
String protocol = "https";
|
|
|
|
|
final String protocol = "https";
|
|
|
|
|
final UrlProtocol proto = new UrlProtocol();
|
|
|
|
|
proto.setRef(
|
|
|
|
|
"{protocolRequest}://{hostnameRequest}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
proto.setRef("{protocolRequest}://{hostnameRequest}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
proto.setProtocol(protocol);
|
|
|
|
|
properties.getProtocols().put("download-http", proto);
|
|
|
|
|
|
|
|
|
|
URI uri = new URI(protocol + "://anotherHost.com");
|
|
|
|
|
final List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, uri);
|
|
|
|
|
assertThat(urls).containsExactly(new ArtifactUrl(protocol.toUpperCase(), "download-http",
|
|
|
|
|
uri + "/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
|
|
|
|
+ SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
final URI uri = new URI(protocol + "://anotherHost.com");
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI, uri)).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
protocol.toUpperCase(), "download-http",
|
|
|
|
|
uri + "/" + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Description("Verfies that the domain of the statically defined hostname is replaced with the domain of the request.")
|
|
|
|
|
@Description("Verifies that the domain of the statically defined hostname is replaced with the domain of the request.")
|
|
|
|
|
public void urlGenerationWithDomainFromRequest() throws URISyntaxException {
|
|
|
|
|
final UrlProtocol proto = new UrlProtocol();
|
|
|
|
|
proto.setHostname("host.bumlux.net");
|
|
|
|
|
proto.setRef(
|
|
|
|
|
"{protocol}://{domainRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
proto.setRef("{protocol}://{domainRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}");
|
|
|
|
|
|
|
|
|
|
properties.getProtocols().put("download-http", proto);
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI,
|
|
|
|
|
new URI("http://anotherHost.com:8083"));
|
|
|
|
|
assertThat(ddiUrls).containsExactly(
|
|
|
|
|
new ArtifactUrl("http".toUpperCase(), "download-http", "http://host.com/" + TENANT + "/controller/v1/"
|
|
|
|
|
+ CONTROLLER_ID + "/softwaremodules/" + SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
final List<ArtifactUrl> dmfUrls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DMF);
|
|
|
|
|
assertThat(dmfUrls).containsExactly(new ArtifactUrl("http".toUpperCase(), "download-http",
|
|
|
|
|
"http://host.bumlux.net/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
|
|
|
|
+ SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI, new URI("http://anotherHost.com:8083"))).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
"http://host.com/" + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
|
|
|
|
|
assertThat(urlHandlerUnderTest.getUrls(placeHolder, ApiType.DMF)).containsExactly(
|
|
|
|
|
new ArtifactUrl(
|
|
|
|
|
"http".toUpperCase(), "download-http",
|
|
|
|
|
"http://host.bumlux.net/" + TENANT + "/controller/v1/" +
|
|
|
|
|
CONTROLLER_ID + "/softwaremodules/" + SOFTWARE_MODULE_ID + "/artifacts/" + FILENAME_ENCODE));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|