From c359e60e35d87dc022564f48c08d22286c02b271 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 2 Dec 2021 10:37:22 +0100 Subject: [PATCH] Update to latest BAAS test server. (#7601) --- Jenkinsfile | 19 ++++--- dependencies.list | 2 +- .../kotlin/io/realm/admin/ServerAdmin.kt | 50 ++++++++++++++++--- tools/sync_test_server/start_server.sh | 11 +++- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5a85af724d..8fd7e90350 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -121,14 +121,17 @@ try { // Prepare Docker containers used by Instrumentation tests // TODO: How much of this logic can be moved to start_server.sh for shared logic with local testing. - - def tempDir = runCommand('mktemp -d -t app_config.XXXXXXXXXX') - sh "tools/sync_test_server/app_config_generator.sh ${tempDir} tools/sync_test_server/app_template testapp1 testapp2" - - sh "docker network create ${dockerNetworkId}" - mongoDbRealmContainer = mdbRealmImage.run("--network ${dockerNetworkId} -v$tempDir:/apps") - mongoDbRealmCommandServerContainer = commandServerEnv.run("--network container:${mongoDbRealmContainer.id} -v$tempDir:/apps") - sh "timeout 60 sh -c \"while [[ ! -f $tempDir/testapp1/app_id || ! -f $tempDir/testapp2/app_id ]]; do echo 'Waiting for server to start'; sleep 1; done\"" + withCredentials([ + [$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'realm-kotlin-baas-aws-credentials', accessKeyVariable: 'BAAS_AWS_ACCESS_KEY_ID', secretKeyVariable: 'BAAS_AWS_SECRET_ACCESS_KEY'] + ]) { + def tempDir = runCommand('mktemp -d -t app_config.XXXXXXXXXX') + sh "tools/sync_test_server/app_config_generator.sh ${tempDir} tools/sync_test_server/app_template testapp1 testapp2" + + sh "docker network create ${dockerNetworkId}" + mongoDbRealmContainer = mdbRealmImage.run("--network ${dockerNetworkId} -v$tempDir:/apps -e AWS_ACCESS_KEY_ID='$BAAS_AWS_ACCESS_KEY_ID' -e AWS_SECRET_ACCESS_KEY='$BAAS_AWS_SECRET_ACCESS_KEY'") + mongoDbRealmCommandServerContainer = commandServerEnv.run("--network container:${mongoDbRealmContainer.id} -v$tempDir:/apps") + sh "timeout 60 sh -c \"while [[ ! -f $tempDir/testapp1/app_id || ! -f $tempDir/testapp2/app_id ]]; do echo 'Waiting for server to start'; sleep 1; done\"" + } } // There is a chance that real devices are attached to the host, so if the emulator is diff --git a/dependencies.list b/dependencies.list index d5c78c238b..3ea41ad4c8 100644 --- a/dependencies.list +++ b/dependencies.list @@ -4,7 +4,7 @@ REALM_CORE=11.6.0 # Version of MongoDB Realm used by integration tests # See https://github.com/realm/ci/packages/147854 for available versions -MONGODB_REALM_SERVER=2021-04-22 +MONGODB_REALM_SERVER=2021-11-28 # Common Android settings across projects GRADLE_BUILD_TOOLS=7.1.0-beta03 diff --git a/realm/realm-library/src/androidTestObjectServer/kotlin/io/realm/admin/ServerAdmin.kt b/realm/realm-library/src/androidTestObjectServer/kotlin/io/realm/admin/ServerAdmin.kt index 2e346def8c..6bda27f205 100644 --- a/realm/realm-library/src/androidTestObjectServer/kotlin/io/realm/admin/ServerAdmin.kt +++ b/realm/realm-library/src/androidTestObjectServer/kotlin/io/realm/admin/ServerAdmin.kt @@ -1,5 +1,6 @@ package io.realm.admin +import android.os.SystemClock import io.realm.log.LogLevel import io.realm.log.RealmLog import io.realm.mongodb.App @@ -100,19 +101,45 @@ class ServerAdmin(private val app: App) { */ fun setAutomaticConfirmation(enabled: Boolean) { val providerId: String = getLocalUserPassProviderId() + val url = "$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId" var request = Request.Builder() - .url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId") + .url(url) .get() val authProviderConfig = JSONObject(executeRequest(request, true)) authProviderConfig.getJSONObject("config").apply { put("autoConfirm", enabled) - put("emailConfirmationUrl", "http://realm.io/confirm-user") } // Change autoConfirm and update the provider request = Request.Builder() - .url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId") + .url(url) .patch(RequestBody.create(json, authProviderConfig.toString())) - executeRequest(request) + executeRequest(request, true) + + request = Request.Builder() + .url(url) + .get() + val config = JSONObject(executeRequest(request, true)) + RealmLog.error("SetAutomaticConfirmation($enabled): ${config.toString(4)}") + waitForDeployment() + } + + private fun waitForDeployment() { + // TODO Attempt to work-around, what looks like a race condition on the server deploying + // changes to the server. Even though the /deployments endpoint report success, it seems + // like the change hasn't propagated fully. This usually surfaces as registerUser errors + // where it tries to use the customFunc instead of automatically registering. + val url = "$baseUrl/groups/$groupId/apps/$appId/deployments" + var request = Request.Builder() + .url(url) + .get() + val deployments = JSONArray(executeRequest(request, true)) + val dep = deployments[0] as JSONObject + if (dep.getString("status") != "successful") { + RealmLog.error("Failed to deploy: ${dep.toString(4)}") + } + + // Work-around for /deployments reporting success, but /register still failing. + SystemClock.sleep(5000) } /** @@ -120,8 +147,9 @@ class ServerAdmin(private val app: App) { */ fun setCustomConfirmation(enabled: Boolean) { val providerId: String = getLocalUserPassProviderId() + val url = "$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId" var request = Request.Builder() - .url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId") + .url(url) .get() val authProviderConfig = JSONObject(executeRequest(request, true)) @@ -131,9 +159,16 @@ class ServerAdmin(private val app: App) { } // Change autoConfirm and update the provider request = Request.Builder() - .url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId") + .url(url) .patch(RequestBody.create(json, authProviderConfig.toString())) - executeRequest(request) + executeRequest(request, true) + + request = Request.Builder() + .url(url) + .get() + val config = JSONObject(executeRequest(request, true)) + RealmLog.error("setCustomConfirmation($enabled): ${config.toString(4)}") + waitForDeployment() } val JSON = MediaType.parse("application/json; charset=utf-8") @@ -240,4 +275,5 @@ class ServerAdmin(private val app: App) { val result = JSONObject(executeRequest(builder)) return result.getString("key") } + } diff --git a/tools/sync_test_server/start_server.sh b/tools/sync_test_server/start_server.sh index 890d2bb6ee..baa6daedbe 100755 --- a/tools/sync_test_server/start_server.sh +++ b/tools/sync_test_server/start_server.sh @@ -43,7 +43,16 @@ $SCRIPTPATH/app_config_generator.sh $APP_CONFIG_DIR $SCRIPTPATH/app_template tes # Run Stitch and Stitch CLI Docker images docker network create mongodb-realm-network docker build $DOCKERFILE_DIR -t mongodb-realm-command-server || { echo "Failed to build Docker image." ; exit 1 ; } -ID=$(docker run --rm -i -t -d -v$APP_CONFIG_DIR:/apps --network mongodb-realm-network -p9090:9090 -p8888:8888 -p26000:26000 --name mongodb-realm docker.pkg.github.com/realm/ci/mongodb-realm-test-server:$MONGODB_REALM_VERSION) +ID=$(docker run --rm -i -t -d -v$APP_CONFIG_DIR:/apps \ + --network mongodb-realm-network \ + -p9090:9090 \ + -p8888:8888 \ + -p26000:26000 \ + --name mongodb-realm \ + -e AWS_ACCESS_KEY_ID="${BAAS_AWS_ACCESS_KEY_ID}" \ + -e AWS_SECRET_ACCESS_KEY="${BAAS_AWS_SECRET_ACCESS_KEY}" \ + docker.pkg.github.com/realm/ci/mongodb-realm-test-server:$MONGODB_REALM_VERSION \ +) docker run --rm -i -t -d --network container:$ID -v$APP_CONFIG_DIR:/apps --name mongodb-realm-command-server mongodb-realm-command-server echo "Template apps are generated in/served from $APP_CONFIG_DIR"