diff --git a/.github/workflows/patrol-integration-test.yaml b/.github/workflows/patrol-integration-test.yaml
new file mode 100644
index 000000000..14affc60f
--- /dev/null
+++ b/.github/workflows/patrol-integration-test.yaml
@@ -0,0 +1,56 @@
+name: Integration tests
+
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: "0 0 * * *"
+
+env:
+ JAVA_VERSION: 17
+ FLUTTER_VERSION: 3.22.2
+
+jobs:
+ mobile_integration_test:
+ permissions:
+ contents: "read"
+ id-token: "write"
+
+ name: Run integration tests for mobile apps
+ runs-on: ubuntu-latest
+ concurrency:
+ group: ngrok
+ cancel-in-progress: false
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Authenticate to Google Cloud
+ uses: "google-github-actions/auth@v2"
+ with:
+ project_id: ${{ secrets.GOOGLE_CLOUD_PROJECT_ID }}
+ workload_identity_provider: ${{ secrets.GOOGLE_CLOUD_WORKLOAD_IDENTITY_PROVIDER_ID }}
+ service_account: ${{ secrets.GOOGLE_CLOUD_SERVICE_ACCOUNT }}
+
+ - name: Setup Cloud SDK
+ uses: google-github-actions/setup-gcloud@v2
+
+ - name: Setup Flutter
+ uses: subosito/flutter-action@v2
+ with:
+ flutter-version: ${{ env.FLUTTER_VERSION }}
+ channel: "stable"
+ cache: true
+
+ - name: Set up Java
+ uses: actions/setup-java@v4
+ with:
+ java-version: ${{ env.JAVA_VERSION }}
+ distribution: "temurin"
+
+ - name: Run prebuild
+ run: ./scripts/prebuild.sh
+
+ - name: Test
+ env:
+ NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
+ run: ./scripts/patrol-integration-test-with-docker.sh
diff --git a/docker-compose.yaml b/backend-docker/docker-compose.yaml
similarity index 55%
rename from docker-compose.yaml
rename to backend-docker/docker-compose.yaml
index 5727ef8ef..2ce61d4f9 100644
--- a/docker-compose.yaml
+++ b/backend-docker/docker-compose.yaml
@@ -1,26 +1,19 @@
version: "3"
services:
- tmail-frontend:
- image: linagora/tmail-web:master
- container_name: tmail-frontend
- ports:
- - "8080:80"
- volumes:
- - ./env.file:/usr/share/nginx/html/assets/env.file
- networks:
- - tmail
- depends_on:
- - tmail-backend
-
tmail-backend:
image: linagora/tmail-backend:memory-branch-master
container_name: tmail-backend
volumes:
- ./jwt_publickey:/root/conf/jwt_publickey
- ./jwt_privatekey:/root/conf/jwt_privatekey
+ - ./mailetcontainer.xml:/root/conf/mailetcontainer.xml
+ - ./imapserver.xml:/root/conf/imapserver.xml
+ - ./jmap.properties:/root/conf/jmap.properties
ports:
- "80:80"
+ environment:
+ - DOMAIN=example.com
networks:
- tmail
diff --git a/backend-docker/imapserver.xml b/backend-docker/imapserver.xml
new file mode 100644
index 000000000..630cfbc26
--- /dev/null
+++ b/backend-docker/imapserver.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+ imapserver
+ 0.0.0.0:143
+ 200
+
+
+ file://conf/keystore
+ james72laBalle
+ org.bouncycastle.jce.provider.BouncyCastleProvider
+
+ 0
+ 0
+ 120
+ SECONDS
+ true
+ false
+
+
+ imapserver-ssl
+ 0.0.0.0:993
+ 200
+
+
+ file://conf/keystore
+ james72laBalle
+ org.bouncycastle.jce.provider.BouncyCastleProvider
+
+ 0
+ 0
+ 120
+ SECONDS
+ true
+
+
\ No newline at end of file
diff --git a/backend-docker/jmap.properties b/backend-docker/jmap.properties
new file mode 100644
index 000000000..68282ebaa
--- /dev/null
+++ b/backend-docker/jmap.properties
@@ -0,0 +1 @@
+url.prefix=https://a872-222-252-23-73.ngrok-free.app
\ No newline at end of file
diff --git a/backend-docker/mailetcontainer.xml b/backend-docker/mailetcontainer.xml
new file mode 100644
index 000000000..383173ef8
--- /dev/null
+++ b/backend-docker/mailetcontainer.xml
@@ -0,0 +1,155 @@
+
+
+
+
+
+
+
+
+
+ postmaster
+
+
+
+ 20
+ memory://var/mail/error/
+
+
+
+
+
+
+
+ transport
+
+
+
+
+
+ mailetContainerErrors
+
+
+
+ memory://var/mail/error/
+ propagate
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rrt-error
+
+
+ local-delivery
+
+
+ local-address-error
+ 550 - Requested action not taken: no such user here
+
+
+ relay
+
+
+ relay-denied
+
+
+
+
+
+
+
+
+
+ ContactAttribute1
+
+
+
+
+
+
+ outgoing
+ 5000, 100000, 500000
+ 3
+ 0
+ 10
+ true
+ bounces
+
+
+
+
+
+ mailetContainerLocalAddressError
+
+
+ none
+
+
+ memory://var/mail/address-error/
+
+
+
+
+
+ mailetContainerRelayDenied
+
+
+ none
+
+
+ memory://var/mail/relay-denied/
+ Warning: You are sending an e-mail to a remote server. You must be authenticated to perform such an operation
+
+
+
+
+
+ bounces
+
+
+ false
+
+
+
+
+
+ memory://var/mail/rrt-error/
+ true
+
+
+
+
+
+
+
+
+
diff --git a/scripts/patrol-integration-test-with-docker.sh b/scripts/patrol-integration-test-with-docker.sh
new file mode 100755
index 000000000..5f0065930
--- /dev/null
+++ b/scripts/patrol-integration-test-with-docker.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# Install ngrok
+echo "Installing ngrok..."
+curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null &&
+ echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list &&
+ sudo apt update && sudo apt install ngrok
+
+# Install patrol CLI
+echo "Installing patrol CLI..."
+dart pub global activate patrol_cli
+flutter build apk --config-only
+
+# Forward traffic to tmail-backend
+ngrok http http://localhost:80 --log=stdout >/dev/null &
+until [[ $(curl localhost:4040/api/status | jq -r ".status") == "online" ]]; do
+ echo "Waiting for ngrok to connect..."
+ sleep 2
+done
+
+export BASIC_AUTH_URL=$(curl -s localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
+
+cd backend-docker
+
+# Generate keys for tmail backend
+echo "Generating keys for tmail-backend..."
+openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out jwt_privatekey
+openssl rsa -in jwt_privatekey -pubout -out jwt_publickey
+
+# Replace content of jmap.properties with url.prefix=$BASIC_AUTH_URL
+sed -i "s|url.prefix=.*|url.prefix=$BASIC_AUTH_URL|" jmap.properties
+
+echo "Starting services and adding users..."
+docker compose up -d
+# Wait till the service is started to add users
+until (docker compose logs tmail-backend | grep -i "JAMES server started"); do
+ echo "Waiting for tmail-backend to start..."
+ sleep 2
+done
+export BOB="bob"
+export ALICE="alice"
+export DOMAIN="example.com"
+docker exec tmail-backend james-cli AddUser "$BOB@$DOMAIN" "$BOB"
+docker exec tmail-backend james-cli AddUser "$ALICE@$DOMAIN" "$ALICE"
+
+cd ..
+
+echo "Building the app and running tests..."
+flutter build apk --config-only
+patrol build android -v \
+ --dart-define=USERNAME="$BOB" \
+ --dart-define=PASSWORD="$BOB" \
+ --dart-define=ADDITIONAL_MAIL_RECIPIENT="$ALICE@$DOMAIN" \
+ --dart-define=BASIC_AUTH_EMAIL="$BOB@$DOMAIN" \
+ --dart-define=BASIC_AUTH_URL="$BASIC_AUTH_URL"
+gcloud firebase test android run \
+ --type instrumentation \
+ --app build/app/outputs/apk/debug/app-debug.apk \
+ --test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
+ --device 'model=oriole,version=33,locale=en,orientation=portrait' \
+ --timeout 10m \
+ --use-orchestrator \
+ --environment-variables clearPackageData=true
diff --git a/scripts/patrol-local-integration-test-with-docker.sh b/scripts/patrol-local-integration-test-with-docker.sh
new file mode 100755
index 000000000..90f331d83
--- /dev/null
+++ b/scripts/patrol-local-integration-test-with-docker.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+## Pre-requisites
+# Install ngrok
+# Install patrol CLI
+# Open android emulator
+
+# Stoping previous environment if any
+killall ngrok || true
+cd backend-docker
+docker compose down || true
+cd ..
+
+# Forward traffic to tmail-backend
+ngrok http http://localhost:80 --log=stdout >/dev/null &
+until [[ $(curl localhost:4040/api/status | jq -r ".status") == "online" ]]; do
+ echo "Waiting for ngrok to connect..."
+ sleep 2
+done
+
+export BASIC_AUTH_URL=$(curl -s localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')
+
+cd backend-docker
+
+# Generate keys for tmail backend
+echo "Generating keys for tmail-backend..."
+openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:4096 -out jwt_privatekey
+openssl rsa -in jwt_privatekey -pubout -out jwt_publickey
+
+# Replace content of jmap.properties with url.prefix=$BASIC_AUTH_URL
+sed -i '' "s|url.prefix=.*|url.prefix=$BASIC_AUTH_URL|" jmap.properties
+
+echo "Starting services and adding users..."
+docker compose up -d
+# Wait till the service is started to add users
+until (docker compose logs tmail-backend | grep -i "JAMES server started"); do
+ echo "Waiting for tmail-backend to start..."
+ sleep 2
+done
+export BOB="bob"
+export ALICE="alice"
+export DOMAIN="example.com"
+docker exec tmail-backend james-cli AddUser "$BOB@$DOMAIN" "$BOB"
+docker exec tmail-backend james-cli AddUser "$ALICE@$DOMAIN" "$ALICE"
+
+cd ..
+
+echo "Building the app and running tests..."
+flutter build apk --config-only
+patrol test -v \
+ --dart-define=USERNAME="$BOB" \
+ --dart-define=PASSWORD="$BOB" \
+ --dart-define=ADDITIONAL_MAIL_RECIPIENT="$ALICE@$DOMAIN" \
+ --dart-define=BASIC_AUTH_EMAIL="$BOB@$DOMAIN" \
+ --dart-define=BASIC_AUTH_URL="$BASIC_AUTH_URL"
+
+# Clean up
+echo "Cleaning up test environment..."
+killall ngrok
+cd backend-docker
+docker compose down
+cd ..
\ No newline at end of file