Skip to content
Open
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
6 changes: 5 additions & 1 deletion javascript-modules-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<groupId>org.graalvm.regex</groupId>
<artifactId>regex</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>chromeinspector</artifactId>
</dependency>
</dependencies>

<build>
Expand All @@ -78,7 +82,7 @@
<instructions>
<_dsannotations>*</_dsannotations>
<!-- those OSGI dependencies are not provided by Jahia and should be embedded in the bundle -->
<Embed-Dependency>bndlib,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex</Embed-Dependency>
<Embed-Dependency>bndlib,chromeinspector,commons-pool2,pax-swissbox-bnd,graal-sdk,truffle-api,js,icu4j,regex</Embed-Dependency>
</instructions>
<!-- because the Java classes of javascript-modules-engine-java are unpacked into the target/classes folder, -->
<!-- the dependency can and should be excluded to avoid duplicates -->
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
<artifactId>regex</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>chromeinspector</artifactId>
<version>${graalvm.version}</version>
</dependency>

<!-- Jahia dependencies: -->
<dependency>
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/provisioning.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Uninstall the JS modules shipped with Jahia to use the one we want to test
- uninstallBundle: "javascript-modules-engine"
- installBundle:
- "mvn:org.jahia.modules/legacy-default-components"
- "mvn:org.jahia.modules/calendar"
Expand Down
104 changes: 104 additions & 0 deletions tests/cypress/e2e/engine/graalvmEngineTest.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
describe("Check that GraalVM debugger can be enabled", () => {
// these ports must be exposed in docker-compose.yml
const ports = [9229, 10229];

ports.forEach((port) => {
it(`Check that GraalVM debugger can be enabled on port ${port}`, function () {
// extract the host from the JAHIA_URL env var
const host = Cypress.env("JAHIA_URL").split("//")[1].split(":")[0];

// delete the config
deleteGraalVMConfig();
waitForCurlExitCode(
host,
port,
CONNECTION_ERROR_CODES,
"debugger should be disabled by default (no config)",
);

// Enable the debugger
enableGraalVMDebugger(port);
waitForCurlExitCode(host, port, CONNECTION_OK, "debugger should be enabled when configured");
verifyGraalVMInspector(host, port);
});
});
});

// Constants for curl exit codes
const CONNECTION_OK = 0;
const CONNECTION_ERROR_CODES = [7, 56]; // 7=ECONNREFUSED, 56=ECONNRESET

/**
* Wait for curl to return the expected exit code when connecting to host:port Exit codes:
* 0=success, 7=ECONNREFUSED, 56=ECONNRESET
*/
function waitForCurlExitCode(
host: string,
port: number,
expectedExitCode: number | number[],
errorMsg: string,
) {
const expectedCodes = Array.isArray(expectedExitCode) ? expectedExitCode : [expectedExitCode];

cy.waitUntil(
() =>
cy
.exec(`curl -s -o /dev/null -w "%{http_code}" http://${host}:${port}/json/version`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a curl command is used within cy.exec() as it's not possible (at least I couldn't have it working) to rely on a cy.request() to check a network error, the Cypress test is always failing

failOnNonZeroExit: false,
timeout: 4000,
})
.then((result) => {
const actualCode = result.code;

if (expectedCodes.includes(actualCode)) {
const msg =
actualCode === 0
? `Connection successful (HTTP ${result.stdout})`
: `Got expected connection error (exit code: ${actualCode})`;
Cypress.log({ message: msg });
return true;
}

Cypress.log({
message: `Waiting... got exit code ${actualCode}, expected ${expectedCodes.join(" or ")}`,
});
return false;
}),
{
timeout: 5000,
errorMsg: `${errorMsg} - Expected curl exit code ${expectedCodes.join(" or ")}`,
},
);
}

/** Delete the GraalVM Engine configuration */
function deleteGraalVMConfig() {
cy.runProvisioningScript({
script: {
fileContent: JSON.stringify([
{
editConfiguration: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine",
content: "",
},
]),
type: "application/yaml",
},
});
}

/** Enable the GraalVM debugger on a given port */
function enableGraalVMDebugger(port: number) {
cy.apollo({
variables: { inspect: `0.0.0.0:${port}`, suspend: false, secure: false },
mutationFile: "graphql/enableGraalVMDebugger.graphql",
});
}

/** Verify the response is from the GraalVM Chrome DevTools inspector */
function verifyGraalVMInspector(host: string, port: number) {
cy.request(`http://${host}:${port}/json/version`).then((response) => {
expect(response.status).to.equal(200);
expect(response.body).to.have.property("Browser", "GraalVM");
expect(response.body).to.have.property("Protocol-Version", "1.2");
});
}
11 changes: 11 additions & 0 deletions tests/cypress/fixtures/graphql/enableGraalVMDebugger.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mutation enableGraalVMDebugger($inspect: String!, $suspend: String!, $secure: String!) {
admin {
jahia {
configuration(pid: "org.jahia.modules.javascript.modules.engine.jsengine.GraalVMEngine") {
polyGlotInspect: value(name: "polyglot.inspect", value: $inspect)
polyGlotInspectSuspend: value(name: "polyglot.inspect.Suspend", value: $suspend)
polyGlotInspectSecure: value(name: "polyglot.inspect.Secure", value: $secure)
}
}
}
}
1 change: 1 addition & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- "8101:8101"
- "8000:8000"
- "9229:9229"
- "10229:10229" # to test the debugger on a different port
environment:
- SUPER_USER_PASSWORD=${SUPER_USER_PASSWORD}
- JAHIA_LICENSE=${JAHIA_LICENSE}
Expand Down
Loading