Skip to content

Commit

Permalink
Make reuse of sql test code explicit (#45884)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst authored Sep 11, 2019
1 parent 6059f8e commit e2977dc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
14 changes: 12 additions & 2 deletions x-pack/plugin/sql/qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ forbiddenApisMain {
thirdPartyAudit.enabled = false

subprojects {
apply plugin: 'elasticsearch.standalone-rest-test'
if (subprojects.isEmpty()) {
// leaf project
apply plugin: 'elasticsearch.standalone-rest-test'
} else {
apply plugin: 'elasticsearch.build'
}

configurations.testRuntimeClasspath {
resolutionStrategy.force "org.slf4j:slf4j-api:1.7.25"
}
dependencies {

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

// H2GIS testing dependencies
testRuntime ("org.orbisgis:h2gis:${h2gisVersion}") {
exclude group: "org.locationtech.jts"
exclude group: "org.locationtech.jts"
exclude group: "com.fasterxml.jackson.core"
}

testRuntime project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
Expand Down
41 changes: 27 additions & 14 deletions x-pack/plugin/sql/qa/security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

dependencies {
testCompile project(':x-pack:plugin:core')
}
Expand All @@ -6,27 +7,27 @@ Project mainProject = project

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

configurations.create('testArtifacts')

TaskProvider testJar = tasks.register("testJar", Jar) {
appendix 'test'
from sourceSets.test.output
}

artifacts {
testArtifacts testJar
}

// Tests are pushed down to subprojects and will be checked there.
testingConventions.enabled = false

subprojects {
// Use resources from the parent project in subprojects
sourceSets {
test {
mainProject.sourceSets.test.output.classesDirs.each { dir ->
output.addClassesDir { dir }
output.builtBy(mainProject.tasks.testClasses)
}
runtimeClasspath += mainProject.sourceSets.test.output
}
}

processTestResources {
from mainProject.file('src/test/resources')
}
// Use tests from the root security qa project in subprojects
configurations.create('testArtifacts')

dependencies {
testCompile project(":x-pack:plugin:core")
testArtifacts project(path: mainProject.path, configuration: 'testArtifacts')
}

testClusters.integTest {
Expand All @@ -42,10 +43,22 @@ subprojects {
user username: "test_admin", password: "x-pack-test-password"
}

File testArtifactsDir = project.file("$buildDir/testArtifacts")
TaskProvider copyTestClasses = tasks.register("copyTestClasses", Copy) {
dependsOn configurations.testArtifacts
from { zipTree(configurations.testArtifacts.singleFile) }
into testArtifactsDir
}

integTest.runner {
dependsOn copyTestClasses
testClassesDirs += project.files(testArtifactsDir)
classpath += configurations.testArtifacts
nonInputProperties.systemProperty 'tests.audit.logfile',
"${ -> testClusters.integTest.singleNode().getAuditLog()}"
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
"${ -> testClusters.integTest.singleNode().getAuditLog().getParentFile()}/integTest_audit-${new Date().format('yyyy-MM-dd')}.json"
}

testingConventions.enabled = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ public void assertLogs() throws Exception {
assertThat(log.containsKey("user.name"), is(true));
List<String> indices = new ArrayList<>();
if (log.containsKey("indices")) {
indices = (ArrayList<String>) log.get("indices");
@SuppressWarnings("unchecked")
List<String> castIndices = (ArrayList<String>) log.get("indices");
indices = castIndices;
if ("test_admin".equals(log.get("user.name"))) {
/*
* Sometimes we accidentally sneak access to the security tables. This is fine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static List<URL> classpathResources(String pattern) throws Exception {
}
}
// normal file access
else {
else if (Files.isDirectory(path)) {
Files.walkFileTree(path, EnumSet.allOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Expand Down

0 comments on commit e2977dc

Please sign in to comment.