Skip to content

Commit e2977dc

Browse files
authored
Make reuse of sql test code explicit (#45884)
The sql project uses a common set of security tests, which are run in subprojects. Currently these are shared through a shared directory, but this is not setup correctly to ensure it is built before tests run. This commit changes the test classes to be an artifact of the sql/qa/security project and makes the test runner use the built artifact (a directory of classes) for tests. closes #45866
1 parent 6059f8e commit e2977dc

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

x-pack/plugin/sql/qa/build.gradle

+12-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ forbiddenApisMain {
4747
thirdPartyAudit.enabled = false
4848

4949
subprojects {
50-
apply plugin: 'elasticsearch.standalone-rest-test'
50+
if (subprojects.isEmpty()) {
51+
// leaf project
52+
apply plugin: 'elasticsearch.standalone-rest-test'
53+
} else {
54+
apply plugin: 'elasticsearch.build'
55+
}
56+
57+
configurations.testRuntimeClasspath {
58+
resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
59+
}
5160
dependencies {
5261

5362
/* Since we're a standalone rest test we actually get transitive
@@ -65,7 +74,8 @@ subprojects {
6574

6675
// H2GIS testing dependencies
6776
testRuntime ("org.orbisgis:h2gis:${h2gisVersion}") {
68-
exclude group: "org.locationtech.jts"
77+
exclude group: "org.locationtech.jts"
78+
exclude group: "com.fasterxml.jackson.core"
6979
}
7080

7181
testRuntime project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
+27-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
dependencies {
23
testCompile project(':x-pack:plugin:core')
34
}
@@ -6,27 +7,27 @@ Project mainProject = project
67

78
group = "${group}.x-pack.qa.sql.security"
89

10+
configurations.create('testArtifacts')
11+
12+
TaskProvider testJar = tasks.register("testJar", Jar) {
13+
appendix 'test'
14+
from sourceSets.test.output
15+
}
16+
17+
artifacts {
18+
testArtifacts testJar
19+
}
20+
921
// Tests are pushed down to subprojects and will be checked there.
1022
testingConventions.enabled = false
1123

1224
subprojects {
13-
// Use resources from the parent project in subprojects
14-
sourceSets {
15-
test {
16-
mainProject.sourceSets.test.output.classesDirs.each { dir ->
17-
output.addClassesDir { dir }
18-
output.builtBy(mainProject.tasks.testClasses)
19-
}
20-
runtimeClasspath += mainProject.sourceSets.test.output
21-
}
22-
}
23-
24-
processTestResources {
25-
from mainProject.file('src/test/resources')
26-
}
25+
// Use tests from the root security qa project in subprojects
26+
configurations.create('testArtifacts')
2727

2828
dependencies {
2929
testCompile project(":x-pack:plugin:core")
30+
testArtifacts project(path: mainProject.path, configuration: 'testArtifacts')
3031
}
3132

3233
testClusters.integTest {
@@ -42,10 +43,22 @@ subprojects {
4243
user username: "test_admin", password: "x-pack-test-password"
4344
}
4445

46+
File testArtifactsDir = project.file("$buildDir/testArtifacts")
47+
TaskProvider copyTestClasses = tasks.register("copyTestClasses", Copy) {
48+
dependsOn configurations.testArtifacts
49+
from { zipTree(configurations.testArtifacts.singleFile) }
50+
into testArtifactsDir
51+
}
52+
4553
integTest.runner {
54+
dependsOn copyTestClasses
55+
testClassesDirs += project.files(testArtifactsDir)
56+
classpath += configurations.testArtifacts
4657
nonInputProperties.systemProperty 'tests.audit.logfile',
4758
"${ -> testClusters.integTest.singleNode().getAuditLog()}"
4859
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
4960
"${ -> testClusters.integTest.singleNode().getAuditLog().getParentFile()}/integTest_audit-${new Date().format('yyyy-MM-dd')}.json"
5061
}
62+
63+
testingConventions.enabled = false
5164
}

x-pack/plugin/sql/qa/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ public void assertLogs() throws Exception {
641641
assertThat(log.containsKey("user.name"), is(true));
642642
List<String> indices = new ArrayList<>();
643643
if (log.containsKey("indices")) {
644-
indices = (ArrayList<String>) log.get("indices");
644+
@SuppressWarnings("unchecked")
645+
List<String> castIndices = (ArrayList<String>) log.get("indices");
646+
indices = castIndices;
645647
if ("test_admin".equals(log.get("user.name"))) {
646648
/*
647649
* Sometimes we accidentally sneak access to the security tables. This is fine,

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/JdbcTestUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static List<URL> classpathResources(String pattern) throws Exception {
194194
}
195195
}
196196
// normal file access
197-
else {
197+
else if (Files.isDirectory(path)) {
198198
Files.walkFileTree(path, EnumSet.allOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
199199
@Override
200200
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

0 commit comments

Comments
 (0)