Skip to content

Commit

Permalink
Merge a6e74db into dbe733a
Browse files Browse the repository at this point in the history
  • Loading branch information
desistefanova committed May 5, 2022
2 parents dbe733a + a6e74db commit ee8523d
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 53 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,41 @@ jobs:
working-directory: ./flutter/realm_flutter/tests

# Windows jobs
baas-windows:
runs-on: ubuntu-latest
name: BaaS Windows
outputs:
clusterName: ${{ steps.deploy-mdb-apps.outputs.clusterName }}
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: false

- uses: realm/ci-actions/mdb-realm/deployApps@fac1d6958f03d71de743305ce3ab27594efbe7b7
id: deploy-mdb-apps
with:
realmUrl: ${{ secrets.REALM_QA_URL }}
atlasUrl: ${{ secrets.ATLAS_QA_URL }}
projectId: ${{ secrets.ATLAS_QA_PROJECT_ID }}
apiKey: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
privateApiKey: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}
differentiator: dart-windows

- name : Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable

- name: Deploy Apps
run: |
dart run realm_dart deploy-apps \
--baas-url ${{ secrets.REALM_QA_URL }} \
--atlas-cluster ${{ steps.deploy-mdb-apps.outputs.clusterName }} \
--api-key ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }} \
--private-api-key ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }} \
--project-id ${{ secrets.ATLAS_QA_PROJECT_ID }}
build-windows:
# TODO: build on windows-latest
Expand Down Expand Up @@ -306,11 +341,35 @@ jobs:
name: librealm-windows
path: binary/windows/**
retention-days: 1

cleanup-windows:
runs-on: ubuntu-latest
name: Cleanup Windows
needs:
- tests-windows
if: always()
timeout-minutes: 5
steps:
- uses: realm/ci-actions/mdb-realm/cleanup@fac1d6958f03d71de743305ce3ab27594efbe7b7
with:
realmUrl: ${{ secrets.REALM_QA_URL }}
atlasUrl: ${{ secrets.ATLAS_QA_URL }}
projectId: ${{ secrets.ATLAS_QA_PROJECT_ID}}
apiKey: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY}}
privateApiKey: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}
differentiator: dart-windows

tests-windows:
runs-on: windows-latest
name: Tests Windows
env:
BAAS_URL: ${{ secrets.REALM_QA_URL }}
BAAS_CLUSTER: ${{ needs.baas-windows.outputs.clusterName }}
BAAS_API_KEY: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
BAAS_PRIVATE_API_KEY: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}
BAAS_PROJECT_ID: ${{ secrets.ATLAS_QA_PROJECT_ID}}
needs:
- baas-windows
- build-windows
steps:
- name: Checkout
Expand Down
2 changes: 0 additions & 2 deletions flutter/realm_flutter/tests/test_driver/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import '../test/list_test.dart' as list_tests;
import '../test/results_test.dart' as results_tests;
import '../test/credentials_test.dart' as credentials_tests;
import '../test/app_test.dart' as app_tests;
import '../test/email_password_provider_test.dart' as email_password_provider_test;

Future<String> main(List<String> args) async {
final Completer<String> completer = Completer<String>();
Expand All @@ -26,7 +25,6 @@ Future<String> main(List<String> args) async {
await results_tests.main(args);
await credentials_tests.main(args);
await app_tests.main(args);
await email_password_provider_test.main(args);

tearDown(() {
if (Invoker.current?.liveTest.state.result == test_api.Result.error || Invoker.current?.liveTest.state.result == test_api.Result.failure) {
Expand Down
74 changes: 58 additions & 16 deletions lib/src/cli/deployapps/baas_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,27 @@ import 'package:http/http.dart' as http;
import 'dart:convert';

class BaasClient {
static const String _confirmFuncSource = '''exports = ({ token, tokenId, username }) => {
static const String _confirmFuncSource = '''exports = async ({ token, tokenId, username }) => {
// process the confirm token, tokenId and username
if (username.includes("realm_tests_do_autoverify")) {
return { status: 'success' }
}
// do not confirm the user
return { status: 'fail' };
else if (username.includes("realm_tests_pending_confirm")) {
const mdb = context.services.get("BackingDB");
const collection = mdb.db("custom-auth").collection("users");
const existing = await collection.findOne({ username: username });
if (existing) {
return { status: 'success' };
}
await collection.insertOne({ username: username });
return { status: 'pending' }
}
else
{
// do not confirm the user
return { status: 'fail' };
}
};''';

static const String _resetFuncSource = '''exports = ({ token, tokenId, username, password }) => {
Expand All @@ -37,6 +51,7 @@ class BaasClient {
// will not reset the password
return { status: 'fail' };
};''';
static const String defaultAppName = "flexible";

final String _baseUrl;
final String? _clusterName;
Expand Down Expand Up @@ -89,17 +104,19 @@ class BaasClient {
for (final app in apps) {
result[app.name] = app;
}
} else {
final defaultApp = await _createApp('flexible');

result[defaultApp.name] = defaultApp;

// Add more types of apps as we add more tests here.
}

await _createAppIfNotExists(result, defaultAppName);
await _createAppIfNotExists(result, "autoConfirm", confirmationType: "auto");
await _createAppIfNotExists(result, "emailConfirm", confirmationType: "email");
return result;
}

Future<void> _createAppIfNotExists(Map<String, BaasApp> existingApps, String appName, {String? confirmationType}) async {
if (!existingApps.containsKey(appName)) {
existingApps[appName] = await _createApp(appName, confirmationType: confirmationType);
}
}

Future<List<BaasApp>> _getApps() async {
final apps = await _get('groups/$_groupId/apps') as List<dynamic>;
return apps
Expand All @@ -117,7 +134,21 @@ class BaasClient {
.toList();
}

Future<BaasApp> _createApp(String name) async {
Future<void> updateAppConfirmFunction(String name, [String? source]) async {
final dynamic docs = await _get('groups/$_groupId/apps');
dynamic doc = docs.firstWhere((dynamic d) => d["name"] == "$name$_appSuffix", orElse: () => throw Exception("BAAS app not found"));
final appId = doc['_id'] as String;
final clientAppId = doc['client_app_id'] as String;
final app = BaasApp(appId, clientAppId, name);

final dynamic functions = await _get('groups/$_groupId/apps/$appId/functions');
dynamic function = functions.firstWhere((dynamic f) => f["name"] == "confirmFunc", orElse: () => throw Exception("Func 'confirmFunc' not found"));
final confirmFuncId = function['_id'] as String;

await _updateFunction(app, 'confirmFunc', confirmFuncId, source ?? _confirmFuncSource);
}

Future<BaasApp> _createApp(String name, {String? confirmationType}) async {
print('Creating app $name');

final dynamic doc = await _post('groups/$_groupId/apps', '{ "name": "$name$_appSuffix" }');
Expand All @@ -129,18 +160,18 @@ class BaasClient {
final confirmFuncId = await _createFunction(app, 'confirmFunc', _confirmFuncSource);
final resetFuncId = await _createFunction(app, 'resetFunc', _resetFuncSource);

enableProvider(app, 'anon-user');
enableProvider(app, 'local-userpass', '''{
"autoConfirm": false,
"confirmEmailSubject": "",
await enableProvider(app, 'anon-user');
await enableProvider(app, 'local-userpass', '''{
"autoConfirm": ${(confirmationType == "auto").toString()},
"confirmEmailSubject": "Confirmation required",
"confirmationFunctionName": "confirmFunc",
"confirmationFunctionId": "$confirmFuncId",
"emailConfirmationUrl": "http://localhost/confirmEmail",
"resetFunctionName": "resetFunc",
"resetFunctionId": "$resetFuncId",
"resetPasswordSubject": "",
"resetPasswordUrl": "http://localhost/resetPassword",
"runConfirmationFunction": true,
"runConfirmationFunction": ${(confirmationType != "email" && confirmationType != "auto").toString()},
"runResetFunction": true
}''');

Expand Down Expand Up @@ -206,6 +237,17 @@ class BaasClient {
return response['_id'] as String;
}

Future<void> _updateFunction(BaasApp app, String name, String functionId, String source) async {
print('Updating function $name for ${app.name}...');

await _put('groups/$_groupId/apps/$app/functions/$functionId', '''{
"name": "$name",
"source": ${jsonEncode(source)},
"private": false,
"can_evaluate": {}
}''');
}

Future<String> _createMongoDBService(BaasApp app, String syncConfig) async {
final serviceName = _clusterName == null ? 'mongodb' : 'mongodb-atlas';
final mongoConfig = _clusterName == null ? '{ "uri": "mongodb://localhost:26000" }' : '{ "clusterName": "$_clusterName" }';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/native/realm_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ class _RealmCore {
}

static void _logOutCallback(Pointer<Void> userdata, Pointer<realm_app_error> error) {
final Completer<void>? completer = userdata.toObject();
final Completer<void>? completer = userdata.toObject(isPersistent: true);
if (completer == null) {
return;
}
Expand Down

0 comments on commit ee8523d

Please sign in to comment.