Skip to content

Commit

Permalink
Merge branch 'master' into feature/ACS-6305_implement_SAST_pipeline_scan
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajbrzezinski committed Dec 8, 2023
2 parents bb7d50c + e700ada commit 3bfc9fc
Show file tree
Hide file tree
Showing 17 changed files with 387 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engines/aio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV IMAGEMAGICK_DEP_RPM_URL=https://dl.fedoraproject.org/pub/epel/epel-release-l

ARG LIBREOFFICE_VERSION=7.2.5
ENV LIBREOFFICE_RPM_URL=https://nexus.alfresco.com/nexus/service/local/repositories/thirdparty/content/org/libreoffice/libreoffice-dist/${LIBREOFFICE_VERSION}/libreoffice-dist-${LIBREOFFICE_VERSION}-linux.gz
ENV LIBREOFFICE_ARM64_RPM_URL=https://dl.rockylinux.org/pub/rocky/8/Devel/aarch64/os/Packages/l/libreoffice-6.4.7.2-13.el8.aarch64.rpm
ENV LIBREOFFICE_ARM64_RPM_URL=https://dl.rockylinux.org/pub/rocky/8/Devel/aarch64/os/Packages/l/libreoffice-6.4.7.2-15.el8.aarch64.rpm

ARG PDF_RENDERER_VERSION=1.2
ENV ALFRESCO_PDF_RENDERER_LIB_RPM_URL=https://nexus.alfresco.com/nexus/service/local/repositories/releases/content/org/alfresco/alfresco-pdf-renderer/${PDF_RENDERER_VERSION}/alfresco-pdf-renderer-${PDF_RENDERER_VERSION}-linux.tgz
Expand Down
5 changes: 5 additions & 0 deletions engines/aio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

package org.alfresco.transform.aio;

import org.alfresco.transform.base.LivenessReadinessProbeTest;

public class AIOLivenessReadinessProbeIT extends LivenessReadinessProbeTest {
@Override
protected LivenessReadinessProbeTest.ImagesForTests getImageForTest() {
return new ImagesForTests("alfresco-transform-core-aio", "text/plain", "text/plain", "original.txt");
}
}
5 changes: 5 additions & 0 deletions engines/base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.alfresco.transform.base;

import org.junit.jupiter.api.Test;

import org.springframework.core.io.ClassPathResource;

import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.net.URISyntaxException;

import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertEquals;

import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS;

import org.springframework.web.reactive.function.client.WebClient;

public abstract class LivenessReadinessProbeTest
{
protected final Integer MAX_TRANSFORMS = 10;

@Test
public void readinessShouldReturnAn429ErrorAfterReachingMaxTransforms() throws URISyntaxException
{
final ImagesForTests testData = getImageForTest();

try (final var env = createEnv(testData.image))
{
env.start();
var url = "http://localhost:" + env.getFirstMappedPort();

/*
Asserts that /ready probe hasn't died before sending a transformation request.
Each /ready request creates a valid transformation and increases the counter of
used transformations, hence the need to divide MAX_TRANSFORMS
*/
for (int i = 0; i<MAX_TRANSFORMS/2; i++) {
assertProbeIsOk(url);
sendTransformRequest(url, testData.sourceMimetype, testData.targetMimetype, testData.filename);
}

assertProbeDied(url);

final String logs = env.getLogs();
System.out.println(logs);
}
}

protected abstract ImagesForTests getImageForTest();

private GenericContainer<?> createEnv(String image) throws URISyntaxException
{
System.out.println(image);
final GenericContainer<?> transformCore = new GenericContainer<>("alfresco/"+image+":latest");

return transformCore.withEnv("livenessTransformEnabled", "true")
.withEnv("maxTransforms", MAX_TRANSFORMS.toString())
.withNetworkAliases(image)
.withExposedPorts(8090)
.waitingFor(Wait.forListeningPort());
}

protected static class ImagesForTests
{
private final String image;
private final String sourceMimetype;
private final String targetMimetype;
private final String filename;

public ImagesForTests(String image, String sourceMimetype, String targetMimetype, String filename)
{
this.image = Objects.requireNonNull(image);
this.sourceMimetype = Objects.requireNonNull(sourceMimetype);
this.targetMimetype = Objects.requireNonNull(targetMimetype);
this.filename = Objects.requireNonNull(filename);
}
}

private void sendTransformRequest(String url, String sourceMimetype, String targetMimetype, String filename)
{
var builder = createRequestBuilder(sourceMimetype, targetMimetype, filename);
WebClient client = WebClient.create();
WebClient.ResponseSpec responseSpec = client.post()
.uri(url + "/test")
.bodyValue(builder.build())
.retrieve();

System.out.println(responseSpec.toBodilessEntity().block());
assertEquals(OK, responseSpec.toBodilessEntity().block().getStatusCode());
}

private MultipartBodyBuilder createRequestBuilder(String sourceMimetype, String targetMimetype, String filename)
{
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("_sourceMimetype", sourceMimetype);
builder.part("_targetMimetype", targetMimetype);
builder.part("file", new ClassPathResource(filename));

return builder;
}

private static void assertProbeDied(String url)
{
WebTestClient client = WebTestClient.bindToServer().baseUrl(url+"/ready").build();
client.get()
.exchange()
.expectStatus().isEqualTo(TOO_MANY_REQUESTS);
}

private static void assertProbeIsOk(String url)
{
WebTestClient client = WebTestClient.bindToServer().baseUrl(url+"/ready").build();
client.get()
.exchange()
.expectStatus().isEqualTo(OK);
}
}
5 changes: 5 additions & 0 deletions engines/imagemagick/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

package org.alfresco.transform.imagemagick;

import org.alfresco.transform.base.LivenessReadinessProbeTest;

public class ImageMagickLivenessReadinessProbeIT extends LivenessReadinessProbeTest {
@Override
protected ImagesForTests getImageForTest() {
return new ImagesForTests("alfresco-imagemagick", "image/jpeg", "image/png", "quick.jpg");
}
}
2 changes: 1 addition & 1 deletion engines/libreoffice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM alfresco/alfresco-base-java:jre17-rockylinux8-202306121108
ARG LIBREOFFICE_VERSION=7.2.5

ENV LIBREOFFICE_RPM_URL=https://nexus.alfresco.com/nexus/service/local/repositories/thirdparty/content/org/libreoffice/libreoffice-dist/${LIBREOFFICE_VERSION}/libreoffice-dist-${LIBREOFFICE_VERSION}-linux.gz
ENV LIBREOFFICE_ARM64_RPM_URL=https://dl.rockylinux.org/pub/rocky/8/Devel/aarch64/os/Packages/l/libreoffice-6.4.7.2-13.el8.aarch64.rpm
ENV LIBREOFFICE_ARM64_RPM_URL=https://dl.rockylinux.org/pub/rocky/8/Devel/aarch64/os/Packages/l/libreoffice-6.4.7.2-15.el8.aarch64.rpm
ENV JAVA_OPTS=""

# Set default user information
Expand Down
5 changes: 5 additions & 0 deletions engines/libreoffice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

package org.alfresco.transform.libreoffice;

import org.alfresco.transform.base.LivenessReadinessProbeTest;

public class LibreOfficeLivenessReadinessProbeIT extends LivenessReadinessProbeTest {
@Override
protected ImagesForTests getImageForTest() {
return new ImagesForTests("alfresco-libreoffice", "text/plain", "application/pdf", "original.txt");
}
}
5 changes: 5 additions & 0 deletions engines/misc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/

package org.alfresco.transform.misc;

import org.alfresco.transform.base.LivenessReadinessProbeTest;

public class MiscLivenessReadinessProbeIT extends LivenessReadinessProbeTest {
@Override
protected ImagesForTests getImageForTest() {
return new ImagesForTests("alfresco-transform-misc", "text/plain", "text/plain", "original.txt");
}
}
5 changes: 5 additions & 0 deletions engines/pdfrenderer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit 3bfc9fc

Please sign in to comment.