2018-04-30 07:31:14 -04:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2019-07-10 18:42:28 -04:00
|
|
|
|
2018-04-30 07:31:14 -04:00
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
2019-11-01 14:33:11 -04:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
2018-04-30 07:31:14 -04:00
|
|
|
|
2019-10-31 11:21:36 -04:00
|
|
|
import java.nio.file.Files
|
2018-04-30 07:31:14 -04:00
|
|
|
import java.security.KeyPair
|
|
|
|
import java.security.KeyPairGenerator
|
|
|
|
|
2019-07-10 18:42:28 -04:00
|
|
|
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
|
|
|
|
|
2018-04-30 07:31:14 -04:00
|
|
|
apply plugin: 'elasticsearch.standalone-rest-test'
|
|
|
|
apply plugin: 'elasticsearch.rest-test'
|
2019-11-07 13:27:22 -05:00
|
|
|
apply plugin: 'elasticsearch.test.fixtures'
|
2018-04-30 07:31:14 -04:00
|
|
|
|
2019-10-31 11:21:36 -04:00
|
|
|
// TODO think about flattening qa:google-cloud-storage project into parent
|
|
|
|
dependencies {
|
2019-11-14 06:01:23 -05:00
|
|
|
testCompile project(path: ':plugins:repository-gcs')
|
2019-10-31 11:21:36 -04:00
|
|
|
}
|
|
|
|
|
2019-11-07 13:27:22 -05:00
|
|
|
testFixtures.useFixture(':test:fixtures:gcs-fixture')
|
2018-04-30 07:31:14 -04:00
|
|
|
boolean useFixture = false
|
|
|
|
|
|
|
|
String gcsServiceAccount = System.getenv("google_storage_service_account")
|
|
|
|
String gcsBucket = System.getenv("google_storage_bucket")
|
|
|
|
String gcsBasePath = System.getenv("google_storage_base_path")
|
|
|
|
|
|
|
|
File serviceAccountFile = null
|
|
|
|
if (!gcsServiceAccount && !gcsBucket && !gcsBasePath) {
|
2019-11-14 06:01:23 -05:00
|
|
|
serviceAccountFile = new File(project.buildDir, 'generated-resources/service_account_test.json')
|
|
|
|
gcsBucket = 'bucket'
|
|
|
|
gcsBasePath = 'integration_test'
|
|
|
|
useFixture = true
|
2019-10-31 11:21:36 -04:00
|
|
|
} else if (!gcsServiceAccount || !gcsBucket || !gcsBasePath) {
|
2019-11-14 06:01:23 -05:00
|
|
|
throw new IllegalArgumentException("not all options specified to run tests against external GCS service are present")
|
2018-04-30 07:31:14 -04:00
|
|
|
} else {
|
2019-11-14 06:01:23 -05:00
|
|
|
serviceAccountFile = new File(gcsServiceAccount)
|
2019-10-31 11:21:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
def encodedCredentials = {
|
2019-11-14 06:01:23 -05:00
|
|
|
Base64.encoder.encodeToString(Files.readAllBytes(serviceAccountFile.toPath()))
|
2018-04-30 07:31:14 -04:00
|
|
|
}
|
|
|
|
|
2019-11-07 13:27:22 -05:00
|
|
|
def fixtureAddress = { fixture ->
|
2019-11-14 06:01:23 -05:00
|
|
|
assert useFixture: 'closure should not be used without a fixture'
|
|
|
|
int ephemeralPort = project(':test:fixtures:gcs-fixture').postProcessFixture.ext."test.fixtures.${fixture}.tcp.80"
|
|
|
|
assert ephemeralPort > 0
|
|
|
|
'http://127.0.0.1:' + ephemeralPort
|
2018-04-30 07:31:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** A service account file that points to the Google Cloud Storage service emulated by the fixture **/
|
|
|
|
task createServiceAccountFile() {
|
2019-11-14 06:01:23 -05:00
|
|
|
doLast {
|
|
|
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA")
|
|
|
|
keyPairGenerator.initialize(1024)
|
|
|
|
KeyPair keyPair = keyPairGenerator.generateKeyPair()
|
|
|
|
String encodedKey = Base64.getEncoder().encodeToString(keyPair.private.getEncoded())
|
|
|
|
|
|
|
|
serviceAccountFile.parentFile.mkdirs()
|
|
|
|
serviceAccountFile.setText("{\n" +
|
|
|
|
' "type": "service_account",\n' +
|
|
|
|
' "project_id": "integration_test",\n' +
|
|
|
|
' "private_key_id": "' + UUID.randomUUID().toString() + '",\n' +
|
|
|
|
' "private_key": "-----BEGIN PRIVATE KEY-----\\n' + encodedKey + '\\n-----END PRIVATE KEY-----\\n",\n' +
|
|
|
|
' "client_email": "integration_test@appspot.gserviceaccount.com",\n' +
|
|
|
|
' "client_id": "123456789101112130594"\n' +
|
|
|
|
'}', 'UTF-8')
|
|
|
|
}
|
2018-04-30 07:31:14 -04:00
|
|
|
}
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
task thirdPartyTest(type: Test) {
|
|
|
|
if (useFixture) {
|
|
|
|
thirdPartyTest.dependsOn createServiceAccountFile
|
|
|
|
nonInputProperties.systemProperty 'test.google.endpoint', "${-> fixtureAddress('gcs-fixture-third-party')}"
|
|
|
|
nonInputProperties.systemProperty 'test.google.tokenURI', "${-> fixtureAddress('gcs-fixture-third-party')}/o/oauth2/token"
|
|
|
|
|
|
|
|
gradle.taskGraph.whenReady {
|
|
|
|
if (it.hasTask(gcsThirdPartyTests)) {
|
|
|
|
throw new IllegalStateException("Tried to run third party tests but not all of the necessary environment variables " +
|
|
|
|
"'google_storage_service_account', 'google_storage_bucket', 'google_storage_base_path' are set.")
|
|
|
|
}
|
2019-11-07 13:27:22 -05:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-11-07 13:27:22 -05:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
include '**/GoogleCloudStorageThirdPartyTests.class'
|
|
|
|
systemProperty 'tests.security.manager', false
|
|
|
|
systemProperty 'test.google.bucket', gcsBucket
|
|
|
|
systemProperty 'test.google.base', gcsBasePath + "_third_party_tests_" + BuildParams.testSeed
|
|
|
|
nonInputProperties.systemProperty 'test.google.account', "${-> encodedCredentials.call()}"
|
2019-10-31 11:21:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task gcsThirdPartyTests {
|
2019-11-14 06:01:23 -05:00
|
|
|
dependsOn check
|
2019-10-31 11:21:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
integTest.mustRunAfter(thirdPartyTest)
|
|
|
|
check.dependsOn thirdPartyTest
|
|
|
|
|
2018-04-30 07:31:14 -04:00
|
|
|
Map<String, Object> expansions = [
|
2019-11-14 06:01:23 -05:00
|
|
|
'bucket': gcsBucket,
|
|
|
|
'base_path': gcsBasePath + "_integration_tests"
|
2018-04-30 07:31:14 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
processTestResources {
|
2019-11-14 06:01:23 -05:00
|
|
|
inputs.properties(expansions)
|
|
|
|
MavenFilteringHack.filter(it, expansions)
|
2018-04-30 07:31:14 -04:00
|
|
|
}
|
|
|
|
|
2019-04-26 11:34:03 -04:00
|
|
|
integTest {
|
2019-11-14 06:01:23 -05:00
|
|
|
dependsOn project(':plugins:repository-gcs').bundlePlugin
|
2019-04-26 11:34:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
testClusters.integTest {
|
2019-11-14 06:01:23 -05:00
|
|
|
plugin file(project(':plugins:repository-gcs').bundlePlugin.archiveFile)
|
|
|
|
|
|
|
|
keystore 'gcs.client.integration_test.credentials_file', serviceAccountFile, IGNORE_VALUE
|
|
|
|
|
|
|
|
if (useFixture) {
|
|
|
|
tasks.integTest.dependsOn createServiceAccountFile
|
|
|
|
/* Use a closure on the string to delay evaluation until tests are executed */
|
|
|
|
setting 'gcs.client.integration_test.endpoint', { "${-> fixtureAddress('gcs-fixture')}" }, IGNORE_VALUE
|
|
|
|
setting 'gcs.client.integration_test.token_uri', { "${-> fixtureAddress('gcs-fixture')}/o/oauth2/token" }, IGNORE_VALUE
|
|
|
|
} else {
|
|
|
|
println "Using an external service to test the repository-gcs plugin"
|
|
|
|
}
|
2018-04-30 07:31:14 -04:00
|
|
|
}
|