TF-2953 Set up test environment for Patrol tests

Made sure only 1 test using ngrok is running at a time
This commit is contained in:
DatDang
2024-10-11 11:58:55 +07:00
committed by Dat H. Pham
parent 25437ba92e
commit 8fe9f2ece0
7 changed files with 403 additions and 12 deletions
@@ -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
@@ -1,26 +1,19 @@
version: "3" version: "3"
services: 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: tmail-backend:
image: linagora/tmail-backend:memory-branch-master image: linagora/tmail-backend:memory-branch-master
container_name: tmail-backend container_name: tmail-backend
volumes: volumes:
- ./jwt_publickey:/root/conf/jwt_publickey - ./jwt_publickey:/root/conf/jwt_publickey
- ./jwt_privatekey:/root/conf/jwt_privatekey - ./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: ports:
- "80:80" - "80:80"
environment:
- DOMAIN=example.com
networks: networks:
- tmail - tmail
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF 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.
-->
<!-- Read https://james.apache.org/server/config-imap4.html for further details -->
<imapservers>
<imapserver enabled="true">
<jmxName>imapserver</jmxName>
<bind>0.0.0.0:143</bind>
<connectionBacklog>200</connectionBacklog>
<tls socketTLS="false" startTLS="true">
<!-- To create a new keystore execute:
keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
-->
<keystore>file://conf/keystore</keystore>
<secret>james72laBalle</secret>
<provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
</tls>
<connectionLimit>0</connectionLimit>
<connectionLimitPerIP>0</connectionLimitPerIP>
<idleTimeInterval>120</idleTimeInterval>
<idleTimeIntervalUnit>SECONDS</idleTimeIntervalUnit>
<enableIdle>true</enableIdle>
<plainAuthDisallowed>false</plainAuthDisallowed>
</imapserver>
<imapserver enabled="true">
<jmxName>imapserver-ssl</jmxName>
<bind>0.0.0.0:993</bind>
<connectionBacklog>200</connectionBacklog>
<tls socketTLS="true" startTLS="false">
<!-- To create a new keystore execute:
keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
-->
<keystore>file://conf/keystore</keystore>
<secret>james72laBalle</secret>
<provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
</tls>
<connectionLimit>0</connectionLimit>
<connectionLimitPerIP>0</connectionLimitPerIP>
<idleTimeInterval>120</idleTimeInterval>
<idleTimeIntervalUnit>SECONDS</idleTimeIntervalUnit>
<enableIdle>true</enableIdle>
</imapserver>
</imapservers>
+1
View File
@@ -0,0 +1 @@
url.prefix=https://a872-222-252-23-73.ngrok-free.app
+155
View File
@@ -0,0 +1,155 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF 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.
-->
<!-- Read https://james.apache.org/server/config-mailetcontainer.html for further details -->
<mailetcontainer enableJmx="true">
<context>
<!-- When the domain part of the postmaster mailAddress is missing, the default domain is appended.
You can configure it to (for example) <postmaster>postmaster@myDomain.com</postmaster> -->
<postmaster>postmaster</postmaster>
</context>
<spooler>
<threads>20</threads>
<errorRepository>memory://var/mail/error/</errorRepository>
</spooler>
<processors>
<processor state="root" enableJmx="true">
<mailet match="All" class="PostmasterAlias"/>
<mailet match="RelayLimit=30" class="Null"/>
<mailet match="All" class="ToProcessor">
<processor>transport</processor>
</mailet>
</processor>
<processor state="error" enableJmx="true">
<mailet match="All" class="MetricsMailet">
<metricName>mailetContainerErrors</metricName>
</mailet>
<mailet match="All" class="Bounce"/>
<mailet match="All" class="ToRepository">
<repositoryPath>memory://var/mail/error/</repositoryPath>
<onMailetException>propagate</onMailetException>
</mailet>
</processor>
<processor state="transport" enableJmx="true">
<matcher name="relay-allowed" match="org.apache.james.mailetcontainer.impl.matchers.Or">
<matcher match="SMTPAuthSuccessful"/>
<matcher match="SMTPIsAuthNetwork"/>
<matcher match="SentByMailet"/>
<matcher match="org.apache.james.jmap.mailet.SentByJmap"/>
</matcher>
<mailet match="All" class="RemoveMimeHeader">
<name>bcc</name>
<onMailetException>ignore</onMailetException>
</mailet>
<mailet match="All" class="RecipientRewriteTable">
<errorProcessor>rrt-error</errorProcessor>
</mailet>
<mailet match="RecipientIsLocal" class="ToProcessor">
<processor>local-delivery</processor>
</mailet>
<mailet match="HostIsLocal" class="ToProcessor">
<processor>local-address-error</processor>
<notice>550 - Requested action not taken: no such user here</notice>
</mailet>
<mailet match="relay-allowed" class="ToProcessor">
<processor>relay</processor>
</mailet>
<mailet match="All" class="ToProcessor">
<processor>relay-denied</processor>
</mailet>
</processor>
<processor state="local-delivery" enableJmx="true">
<mailet match="All" class="VacationMailet"/>
<mailet match="All" class="Sieve"/>
<mailet match="All" class="AddDeliveredToHeader"/>
<mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="All" class="com.linagora.tmail.mailets.TmailLocalDelivery"/>
</processor>
<processor state="relay" enableJmx="true">
<mailet match="All" class="RemoteDelivery">
<outgoingQueue>outgoing</outgoingQueue>
<delayTime>5000, 100000, 500000</delayTime>
<maxRetries>3</maxRetries>
<maxDnsProblemRetries>0</maxDnsProblemRetries>
<deliveryThreads>10</deliveryThreads>
<sendpartial>true</sendpartial>
<bounceProcessor>bounces</bounceProcessor>
</mailet>
</processor>
<processor state="local-address-error" enableJmx="true">
<mailet match="All" class="MetricsMailet">
<metricName>mailetContainerLocalAddressError</metricName>
</mailet>
<mailet match="All" class="Bounce">
<attachment>none</attachment>
</mailet>
<mailet match="All" class="ToRepository">
<repositoryPath>memory://var/mail/address-error/</repositoryPath>
</mailet>
</processor>
<processor state="relay-denied" enableJmx="true">
<mailet match="All" class="MetricsMailet">
<metricName>mailetContainerRelayDenied</metricName>
</mailet>
<mailet match="All" class="Bounce">
<attachment>none</attachment>
</mailet>
<mailet match="All" class="ToRepository">
<repositoryPath>memory://var/mail/relay-denied/</repositoryPath>
<notice>Warning: You are sending an e-mail to a remote server. You must be authenticated to perform such an operation</notice>
</mailet>
</processor>
<processor state="bounces" enableJmx="true">
<mailet match="All" class="MetricsMailet">
<metricName>bounces</metricName>
</mailet>
<mailet match="All" class="DSNBounce">
<passThrough>false</passThrough>
</mailet>
</processor>
<processor state="rrt-error" enableJmx="false">
<mailet match="All" class="ToRepository">
<repositoryPath>memory://var/mail/rrt-error/</repositoryPath>
<passThrough>true</passThrough>
</mailet>
<mailet match="IsSenderInRRTLoop" class="Null"/>
<mailet match="All" class="Bounce"/>
</processor>
</processors>
</mailetcontainer>
+63
View File
@@ -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
+62
View File
@@ -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 ..