Skip to content

Commit

Permalink
Dev test cypher versions docker (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j authored Feb 4, 2025
1 parent e9e7f8f commit 4d2910d
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 182 deletions.
12 changes: 10 additions & 2 deletions common/src/main/java/apoc/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import static org.eclipse.jetty.util.URIUtil.encodePath;
import static org.neo4j.configuration.GraphDatabaseSettings.SYSTEM_DATABASE_NAME;

import apoc.ApocConfig;
import apoc.Pools;
import apoc.convert.ConvertUtils;
import apoc.export.util.CountingInputStream;
Expand Down Expand Up @@ -90,6 +89,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.neo4j.configuration.Config;
import org.neo4j.configuration.GraphDatabaseInternalSettings;
import org.neo4j.configuration.connectors.BoltConnector;
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.graphdb.Entity;
Expand Down Expand Up @@ -463,7 +463,7 @@ public static StreamConnection readHttpInputStream(
int redirectLimit,
URLAccessChecker urlAccessChecker)
throws IOException {
URL url = ApocConfig.apocConfig().checkAllowedUrlAndPinToIP(urlAddress, urlAccessChecker);
URL url = apocConfig().checkAllowedUrlAndPinToIP(urlAddress, urlAccessChecker);
URLConnection con = openUrlConnection(url, headers);
writePayload(con, payload);
String newUrl = handleRedirect(con, urlAddress);
Expand Down Expand Up @@ -1373,4 +1373,12 @@ public static List<String> getCypherVersions() {
})
.toList();
}

public static String getCypherVersion(GraphDatabaseInternalSettings.CypherVersion version) {
return switch (version) {
case Default -> "default";
case Cypher5 -> "5";
case Cypher25 -> "25";
};
}
}
50 changes: 43 additions & 7 deletions it/src/test/java/apoc/it/core/ApocSplitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
*/
package apoc.it.core;

import static apoc.it.core.ApocVersionsTest.DEPRECATED_CORE_FUNCTIONS_5;
import static apoc.it.core.ApocVersionsTest.DEPRECATED_CORE_PROCEDURES_5;

import apoc.util.Neo4jContainerExtension;
import apoc.util.TestContainerUtil;
import apoc.util.TestContainerUtil.ApocPackage;
import apoc.util.TestUtil;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -476,24 +480,56 @@ public class ApocSplitTest {
"apoc.agg.slice");

@Test
public void test() {
public void testCypher5() {
Neo4jContainerExtension neo4jContainer = TestContainerUtil.createEnterpriseDB(
List.of(ApocPackage.CORE), !TestUtil.isRunningInCI())
.withNeo4jConfig("dbms.transaction.timeout", "60s");

neo4jContainer.start();

Session session = neo4jContainer.getSession();
Set<String> procedureNames = session.run("SHOW PROCEDURES YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());
Set<String> functionNames = session.run("SHOW FUNCTIONS YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());
Set<String> procedureNames =
session.run("CYPHER 5 SHOW PROCEDURES YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());
Set<String> functionNames =
session.run("CYPHER 5 SHOW FUNCTIONS YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());

Assert.assertEquals(CORE_PROCEDURES, procedureNames);
Assert.assertEquals(CORE_FUNCTIONS, functionNames);
session.close();
neo4jContainer.close();
}

@Test
public void testCypher25() {
Neo4jContainerExtension neo4jContainer = TestContainerUtil.createEnterpriseDB(
List.of(ApocPackage.CORE), !TestUtil.isRunningInCI())
.withNeo4jConfig("dbms.transaction.timeout", "60s");

neo4jContainer.start();

Session session = neo4jContainer.getSession();
Set<String> procedureNames =
session.run("CYPHER 25 SHOW PROCEDURES YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());
Set<String> functionNames =
session.run("CYPHER 25 SHOW FUNCTIONS YIELD name WHERE name STARTS WITH 'apoc'").stream()
.map(s -> s.get("name").asString())
.collect(Collectors.toSet());

Set<String> proceduresCypher25 = new HashSet<>(CORE_PROCEDURES);
proceduresCypher25.removeAll(DEPRECATED_CORE_PROCEDURES_5);

Set<String> functionsCypher25 = new HashSet<>(CORE_FUNCTIONS);
functionsCypher25.removeAll(DEPRECATED_CORE_FUNCTIONS_5);

Assert.assertEquals(proceduresCypher25, procedureNames);
Assert.assertEquals(functionsCypher25, functionNames);
session.close();
neo4jContainer.close();
}
}
18 changes: 15 additions & 3 deletions it/src/test/java/apoc/it/core/RBACOnLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ public void testRBACOnDeny() throws IOException {
"apoc.load.jsonArray($url)",
"apoc.load.jsonParams($url, null, null, null, {})",
"apoc.load.xml($url)",
"apoc.load.arrow($url)",
"apoc.import.csv([{fileName: $url, labels: ['Person']}], [], {})",
"apoc.import.graphml($url, {})",
"apoc.import.json($url)",
"apoc.import.xml($url)");

List<String> loadableAPOCProcsCypher5Only =
List.of("apoc.load.jsonParams($url, null, null, null, {})", "apoc.load.arrow($url)");

for (String loadableAPOCProc : loadableAPOCProcs) {
var cypherVersion = loadableAPOCProcsCypher5Only.contains(loadableAPOCProc) ? "CYPHER 5 " : "";
RuntimeException e = assertThrows(
RuntimeException.class,
() -> testCall(testUserSession, "CALL " + loadableAPOCProc, Map.of("url", url), r -> {}));
() -> testCall(
testUserSession, cypherVersion + "CALL " + loadableAPOCProc, Map.of("url", url), r -> {}));

Assertions.assertThat(e.getMessage()).contains("URLAccessValidationError");
Assertions.assertThat(e.getMessage())
Expand Down Expand Up @@ -171,13 +175,21 @@ public void testRBACOnFileDenyAll() throws IOException {
"apoc.import.json($url)",
"apoc.import.xml($url)");

List<String> loadableAPOCProcsCypher5Only =
List.of("apoc.load.jsonParams($url, null, null, null, {})", "apoc.load.arrow($url)");

addRBACDenyAll("test");

for (String url : urls) {
for (String loadableAPOCProc : loadableAPOCProcs) {
var cypherVersion = loadableAPOCProcsCypher5Only.contains(loadableAPOCProc) ? "CYPHER 5 " : "";
RuntimeException e = assertThrows(
RuntimeException.class,
() -> testCall(testUserSession, "CALL " + loadableAPOCProc, Map.of("url", url), r -> {}));
() -> testCall(
testUserSession,
cypherVersion + "CALL " + loadableAPOCProc,
Map.of("url", url),
r -> {}));

Assertions.assertThat(e.getMessage()).contains("URLAccessValidationError");
}
Expand Down
Loading

0 comments on commit 4d2910d

Please sign in to comment.