Skip to content

Commit

Permalink
Update to latest BAAS test server. (#7601)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelchior authored Dec 2, 2021
1 parent 7db3401 commit c359e60
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
19 changes: 11 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -100,28 +101,55 @@ 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)
}

/**
* Toggle whether or not custom confirmation functions are enabled.
*/
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))

Expand All @@ -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")
Expand Down Expand Up @@ -240,4 +275,5 @@ class ServerAdmin(private val app: App) {
val result = JSONObject(executeRequest(builder))
return result.getString("key")
}

}
11 changes: 10 additions & 1 deletion tools/sync_test_server/start_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit c359e60

Please sign in to comment.