Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-9036] Fix failing tests in acs-packaging FromLegacyAcsUpgradeTest #2996

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
AWS_REGION: eu-west-1
TAS_ENVIRONMENT: ./tests/environment
TAS_SCRIPTS: ../alfresco-community-repo/packaging/tests/scripts
ALF_LICENCE_S3_PATH: s3://acs-license/acs/alf23-allenabled.lic
ALF_LICENCE_S3_PATH: s3://acs-license/acs/alf25-allenabled.lic
ALF_LICENCE_LOCAL_PATH: /tmp/licence.lic
PYTHON_VERSION: 3.7.15
DTAS_VERSION: v1.5.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static org.alfresco.elasticsearch.upgrade.Utils.waitFor;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -140,11 +141,16 @@
repoHttpClient.setSearchService("elasticsearch");
}

public boolean uploadLicence(String licencePath)
public void tryToUploadLicence(String licencePath)
{
try
{
return repoHttpClient.uploadLicense(licencePath);
File licence = new File(licencePath);
if (!licence.isFile() || !licence.canRead())
{
throw new RuntimeException("Licence file at: %s is not a file or is not readable".formatted(licencePath));

Check warning

Code scanning / PMD

Avoid throwing raw exception types. Warning test

Avoid throwing raw exception types.
}
repoHttpClient.uploadLicense(licence);
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.alfresco.elasticsearch.upgrade.Utils.createTempContentStoreDirectory;

import java.nio.file.Path;
import java.util.Optional;

import org.testcontainers.containers.Network;

Expand Down Expand Up @@ -72,15 +73,13 @@ public ACSEnv upgradeLegacyEnvironmentToCurrent()

private void uploadLicence(ACSEnv env)
{
final String licencePath = getTargetAcsLicencePath();
if (!env.uploadLicence(licencePath))
{
throw new RuntimeException("Failed to upload licence from `" + licencePath + "`.");
}
String licencePath = getTargetAcsLicencePath();
env.tryToUploadLicence(licencePath);
}

private String getTargetAcsLicencePath()
{
return System.getenv("ALF_LICENCE_LOCAL_PATH");
return Optional.ofNullable(System.getenv("ALF_LICENCE_LOCAL_PATH"))
.orElseThrow(() -> new IllegalStateException("ALF_LICENCE_LOCAL_PATH environment variable is not set"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void setSearchService(String implementation) throws IOException
}
}

public boolean uploadLicense(String licensePath) throws IOException
public void uploadLicense(File license) throws IOException
{
final HttpGet getCsrfToken = authenticate(new HttpGet(uploadLicenseAdminApiUri));
final HttpClientContext httpCtx = HttpClientContext.create();
Expand All @@ -128,9 +128,6 @@ public boolean uploadLicense(String licensePath) throws IOException
csrfCookie = Objects.requireNonNull(cookies.get("alf-csrftoken"));
}


File license = new File(licensePath);

final URI uploadLicenseAdminCsrfApiUri = URI.create(new URIBuilder(uploadLicenseAdminApiUri)
.addParameter(csrfCookie.getName(), URLDecoder.decode(csrfCookie.getValue(), StandardCharsets.US_ASCII))
.toString());
Expand All @@ -144,12 +141,11 @@ public boolean uploadLicense(String licensePath) throws IOException
final HttpPost uploadRequest = authenticate(new HttpPost(uploadLicenseAdminCsrfApiUri));
uploadRequest.setEntity(uploadEntity);

try (CloseableHttpResponse response = client.execute(uploadRequest, httpCtx))
var responseMap = executeAndGetResponseMap(uploadRequest, httpCtx);
if (!Boolean.TRUE.equals(responseMap.get("success")))
{
String responseBody = EntityUtils.toString(response.getEntity());
return gson.fromJson(responseBody, Map.class).get("success").equals(true);
throw new IOException("Failed to upload a licence. Server response error: " + responseMap.get("error"));
}

}

public boolean isServerUp() throws IOException
Expand Down Expand Up @@ -217,6 +213,15 @@ public Optional<Set<String>> searchForFiles(String term) throws IOException
return Optional.of(names);
}

private Map<?,?> executeAndGetResponseMap(HttpPost httpPost, HttpClientContext httpCtx) throws IOException
{
try (CloseableHttpResponse response = client.execute(httpPost, httpCtx))
{
String responseBody = EntityUtils.toString(response.getEntity());
return gson.fromJson(responseBody, Map.class);
}
}

private <T extends HttpMessage> T authenticate(T msg)
{
msg.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
Expand Down
Loading