Skip to content

Commit fb9f604

Browse files
sampaiodiegoricardogarim
authored andcommitted
test(federation): improve and slim down config and scripts (#37769)
1 parent c291ac0 commit fb9f604

File tree

8 files changed

+177
-111
lines changed

8 files changed

+177
-111
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ jobs:
626626
ROCKETCHAT_IMAGE: ghcr.io/${{ needs.release-versions.outputs.lowercase-repo }}/rocket.chat:${{ needs.release-versions.outputs.gh-docker-tag }}
627627
ENTERPRISE_LICENSE_RC1: ${{ secrets.ENTERPRISE_LICENSE_RC1 }}
628628
QASE_TESTOPS_JEST_API_TOKEN: ${{ secrets.QASE_TESTOPS_JEST_API_TOKEN }}
629+
PR_NUMBER: ${{ github.event.number }}
629630
run: yarn test:integration --image "${ROCKETCHAT_IMAGE}"
630631

631632
report-coverage:

ee/packages/federation-matrix/jest.config.federation.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@
88
import server from '@rocket.chat/jest-presets/server';
99
import type { Config } from 'jest';
1010

11+
function qaseRunTitle(): string {
12+
const title = ['Federation E2E Tests'];
13+
14+
if (process.env.PR_NUMBER) {
15+
title.push(`PR ${process.env.PR_NUMBER}`);
16+
}
17+
18+
if (process.env.GITHUB_RUN_ID) {
19+
title.push(`Run ${process.env.GITHUB_RUN_ID}`);
20+
}
21+
22+
title.push(new Date().toISOString());
23+
24+
return title.join(' - ');
25+
}
26+
1127
export default {
1228
preset: server.preset,
1329
transformIgnorePatterns: [
@@ -36,7 +52,10 @@ export default {
3652
testops: {
3753
api: { token: process.env.QASE_TESTOPS_JEST_API_TOKEN },
3854
project: 'RC',
39-
run: { complete: true },
55+
run: {
56+
title: qaseRunTitle(),
57+
complete: true,
58+
},
4059
},
4160
debug: true,
4261
},

ee/packages/federation-matrix/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint:fix": "eslint src --fix",
1515
"test": "jest",
1616
"test:integration": "./tests/scripts/run-integration-tests.sh",
17-
"testend-to-end": "IS_EE=true NODE_EXTRA_CA_CERTS=$(pwd)/docker-compose/traefik/certs/ca/rootCA.crt jest --config jest.config.federation.ts --forceExit --testTimeout=30000",
17+
"test:federation": "jest --config jest.config.federation.ts",
1818
"testunit": "jest",
1919
"typecheck": "tsc --noEmit --skipLibCheck"
2020
},

ee/packages/federation-matrix/tests/end-to-end/messaging.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { SynapseClient } from '../helper/synapse-client';
2222
beforeAll(async () => {
2323
// Create admin request config for RC1
2424
rc1AdminRequestConfig = await getRequestConfig(
25-
federationConfig.rc1.apiUrl,
25+
federationConfig.rc1.url,
2626
federationConfig.rc1.adminUser,
2727
federationConfig.rc1.adminPassword,
2828
);

ee/packages/federation-matrix/tests/end-to-end/room.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { SynapseClient } from '../helper/synapse-client';
3030
beforeAll(async () => {
3131
// Create admin request config for RC1
3232
rc1AdminRequestConfig = await getRequestConfig(
33-
federationConfig.rc1.apiUrl,
33+
federationConfig.rc1.url,
3434
federationConfig.rc1.adminUser,
3535
federationConfig.rc1.adminPassword,
3636
);
@@ -48,7 +48,7 @@ import { SynapseClient } from '../helper/synapse-client';
4848

4949
// Create user1 request config for RC1
5050
rc1User1RequestConfig = await getRequestConfig(
51-
federationConfig.rc1.apiUrl,
51+
federationConfig.rc1.url,
5252
federationConfig.rc1.additionalUser1.username,
5353
federationConfig.rc1.additionalUser1.password,
5454
);
@@ -84,7 +84,7 @@ import { SynapseClient } from '../helper/synapse-client';
8484
beforeAll(async () => {
8585
const user = { username: `user-${Date.now()}`, password: '123' };
8686
createdUser = await createUser(user, rc1AdminRequestConfig);
87-
userRequestConfig = await getRequestConfig(federationConfig.rc1.apiUrl, user.username, user.password);
87+
userRequestConfig = await getRequestConfig(federationConfig.rc1.url, user.username, user.password);
8888
});
8989

9090
afterAll(async () => {
@@ -256,7 +256,7 @@ import { SynapseClient } from '../helper/synapse-client';
256256
describe('Go to the composer and use the /invite slash command to add a federated user', () => {
257257
it('It should not allow and show an error message', async () => {
258258
// Set up DDP listener to catch ephemeral messages
259-
const ddpListener = createDDPListener(federationConfig.rc1.apiUrl, rc1AdminRequestConfig);
259+
const ddpListener = createDDPListener(federationConfig.rc1.url, rc1AdminRequestConfig);
260260

261261
// Connect to DDP and subscribe to ephemeral messages
262262
await ddpListener.connect();

ee/packages/federation-matrix/tests/helper/config.ts

Lines changed: 44 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,22 @@
55
* Rocket.Chat instances, Matrix homeservers, and user credentials needed
66
* for end-to-end federation testing.
77
*/
8-
export interface IFederationConfig {
9-
rc1: {
10-
apiUrl: string;
11-
adminUser: string;
12-
adminPassword: string;
13-
adminMatrixUserId: string;
14-
additionalUser1: {
15-
username: string;
16-
password: string;
17-
matrixUserId: string;
18-
};
19-
};
20-
hs1: {
21-
url: string;
22-
adminMatrixUserId: string;
8+
9+
type FederationServerConfig = {
10+
url: string;
11+
domain: string;
12+
adminUser: string;
13+
adminPassword: string;
14+
adminMatrixUserId: string;
15+
additionalUser1: {
16+
username: string;
2317
password: string;
24-
homeserver: string;
25-
adminUser: string;
26-
adminPassword: string;
27-
additionalUser1: {
28-
username: string;
29-
password: string;
30-
matrixUserId: string;
31-
};
18+
matrixUserId: string;
3219
};
20+
};
21+
export interface IFederationConfig {
22+
rc1: FederationServerConfig;
23+
hs1: FederationServerConfig;
3324
}
3425

3526
/**
@@ -40,13 +31,12 @@ export interface IFederationConfig {
4031
* Throws an error if a required variable is missing or empty.
4132
*
4233
* @param name - The name of the environment variable for error messages
43-
* @param value - The environment variable value (may be undefined)
4434
* @param defaultValue - Optional default value to use if variable is not set
4535
* @returns The validated value (either the env var or default)
4636
* @throws Error if the variable is required but missing or empty
4737
*/
48-
function validateEnvVar(name: string, value: string | undefined, defaultValue?: string): string {
49-
const finalValue = value || defaultValue;
38+
function validateEnvVar(name: string, defaultValue?: string): string {
39+
const finalValue = process.env[name] || defaultValue;
5040
if (!finalValue || finalValue.trim() === '') {
5141
throw new Error(`Required environment variable ${name} is not set or is empty`);
5242
}
@@ -65,45 +55,41 @@ function validateEnvVar(name: string, value: string | undefined, defaultValue?:
6555
* @throws Error if any required configuration is missing or invalid
6656
*/
6757
function getFederationConfig(): IFederationConfig {
58+
const rcDomain = validateEnvVar('FEDERATION_RC1_DOMAIN', 'rc1');
59+
const rcAdminUser = validateEnvVar('FEDERATION_RC1_ADMIN_USER', 'admin');
60+
const rcAdminPassword = validateEnvVar('FEDERATION_RC1_ADMIN_PASSWORD', 'admin');
61+
const rcAdditionalUser1 = validateEnvVar('FEDERATION_RC1_ADDITIONAL_USER1', 'user2');
62+
const rcAdditionalUser1Password = validateEnvVar('FEDERATION_RC1_ADDITIONAL_USER1_PASSWORD', 'user2pass');
63+
64+
const hs1Domain = validateEnvVar('FEDERATION_SYNAPSE_DOMAIN', 'hs1');
65+
const hs1AdminUser = validateEnvVar('FEDERATION_SYNAPSE_ADMIN_USER', 'admin');
66+
const hs1AdminPassword = validateEnvVar('FEDERATION_SYNAPSE_ADMIN_PASSWORD', 'admin');
67+
const hs1AdditionalUser1 = validateEnvVar('FEDERATION_SYNAPSE_ADDITIONAL_USER1', 'alice');
68+
const hs1AdditionalUser1Password = validateEnvVar('FEDERATION_SYNAPSE_ADDITIONAL_USER1_PASSWORD', 'alice');
69+
6870
return {
6971
rc1: {
70-
apiUrl: validateEnvVar('FEDERATION_RC1_API_URL', process.env.FEDERATION_RC1_API_URL, 'https://rc1'),
71-
adminUser: validateEnvVar('FEDERATION_RC1_ADMIN_USER', process.env.FEDERATION_RC1_ADMIN_USER, 'admin'),
72-
adminPassword: validateEnvVar('FEDERATION_RC1_ADMIN_PASSWORD', process.env.FEDERATION_RC1_ADMIN_PASSWORD, 'admin'),
73-
adminMatrixUserId: validateEnvVar('FEDERATION_RC1_USER_ID', process.env.FEDERATION_RC1_USER_ID, '@admin:rc1'),
72+
url: `https://${rcDomain}`,
73+
domain: rcDomain,
74+
adminUser: rcAdminUser,
75+
adminPassword: rcAdminPassword,
76+
adminMatrixUserId: `@${rcAdminUser}:${rcDomain}`,
7477
additionalUser1: {
75-
username: validateEnvVar('FEDERATION_RC1_ADDITIONAL_USER1', process.env.FEDERATION_RC1_ADDITIONAL_USER1, 'user2'),
76-
password: validateEnvVar(
77-
'FEDERATION_RC1_ADDITIONAL_USER1_PASSWORD',
78-
process.env.FEDERATION_RC1_ADDITIONAL_USER1_PASSWORD,
79-
'user2pass',
80-
),
81-
matrixUserId: validateEnvVar(
82-
'FEDERATION_RC1_ADDITIONAL_USER1_MATRIX_ID',
83-
process.env.FEDERATION_RC1_ADDITIONAL_USER1_MATRIX_ID,
84-
'@user2:rc1',
85-
),
78+
username: rcAdditionalUser1,
79+
password: rcAdditionalUser1Password,
80+
matrixUserId: `@${rcAdditionalUser1}:${rcDomain}`,
8681
},
8782
},
8883
hs1: {
89-
url: validateEnvVar('FEDERATION_SYNAPSE_URL', process.env.FEDERATION_SYNAPSE_URL, 'https://hs1'),
90-
adminMatrixUserId: validateEnvVar('FEDERATION_SYNAPSE_USER', process.env.FEDERATION_SYNAPSE_USER, '@admin:hs1'),
91-
password: validateEnvVar('FEDERATION_SYNAPSE_PASSWORD', process.env.FEDERATION_SYNAPSE_PASSWORD, 'admin'),
92-
homeserver: validateEnvVar('FEDERATION_SYNAPSE_HOMESERVER', process.env.FEDERATION_SYNAPSE_HOMESERVER, 'hs1'),
93-
adminUser: validateEnvVar('FEDERATION_SYNAPSE_ADMIN_USER', process.env.FEDERATION_SYNAPSE_ADMIN_USER, 'admin'),
94-
adminPassword: validateEnvVar('FEDERATION_SYNAPSE_ADMIN_PASSWORD', process.env.FEDERATION_SYNAPSE_ADMIN_PASSWORD, 'admin'),
84+
url: `https://${hs1Domain}`,
85+
domain: hs1Domain,
86+
adminUser: hs1AdminUser,
87+
adminMatrixUserId: `@${hs1AdminUser}:${hs1Domain}`,
88+
adminPassword: hs1AdminPassword,
9589
additionalUser1: {
96-
username: validateEnvVar('FEDERATION_SYNAPSE_ADDITIONAL_USER1', process.env.FEDERATION_SYNAPSE_ADDITIONAL_USER1, 'alice'),
97-
password: validateEnvVar(
98-
'FEDERATION_SYNAPSE_ADDITIONAL_USER1_PASSWORD',
99-
process.env.FEDERATION_SYNAPSE_ADDITIONAL_USER1_PASSWORD,
100-
'alice',
101-
),
102-
matrixUserId: validateEnvVar(
103-
'FEDERATION_SYNAPSE_ADDITIONAL_USER1_MATRIX_ID',
104-
process.env.FEDERATION_SYNAPSE_ADDITIONAL_USER1_MATRIX_ID,
105-
'@alice:hs1',
106-
),
90+
username: hs1AdditionalUser1,
91+
password: hs1AdditionalUser1Password,
92+
matrixUserId: `@${hs1AdditionalUser1}:${hs1Domain}`,
10793
},
10894
},
10995
};

ee/packages/federation-matrix/tests/scripts/run-integration-tests.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ cleanup() {
110110
echo "=========================================="
111111
echo "CONTAINER LOGS (Test Failed)"
112112
echo "=========================================="
113-
113+
114114
echo ""
115115
echo "ROCKET.CHAT (rc1) LOGS:"
116116
echo "----------------------------------------"
@@ -119,7 +119,7 @@ cleanup() {
119119
else
120120
echo " Rocket.Chat container not found or no logs"
121121
fi
122-
122+
123123
echo ""
124124
echo "SYNAPSE (hs1) LOGS:"
125125
echo "----------------------------------------"
@@ -128,11 +128,11 @@ cleanup() {
128128
else
129129
echo " Synapse container not found or no logs"
130130
fi
131-
131+
132132
echo ""
133133
echo "=========================================="
134134
fi
135-
135+
136136
if [ "$KEEP_RUNNING" = true ]; then
137137
log_info "Keeping Docker containers running (--keep-running flag set)"
138138
log_info "Services are available at:"
@@ -158,12 +158,12 @@ cleanup() {
158158
fi
159159
log_success "Cleanup completed"
160160
fi
161-
161+
162162
# Remove temporary build directory if it exists
163163
if [ -n "${BUILD_DIR:-}" ] && [ -d "$BUILD_DIR" ]; then
164164
rm -rf "$BUILD_DIR" || true
165165
fi
166-
166+
167167
# Exit with the test result code
168168
if [ -n "${TEST_EXIT_CODE:-}" ]; then
169169
exit $TEST_EXIT_CODE
@@ -186,21 +186,21 @@ fi
186186
if [ "$USE_PREBUILT_IMAGE" = false ]; then
187187
log_info "🚀 Building Rocket.Chat locally..."
188188
log_info "====================================="
189-
189+
190190
# Clean up any existing build
191191
log_info "Cleaning up previous build..."
192192
rm -rf "$BUILD_DIR"
193-
193+
194194
# Build the project
195195
log_info "Building packages from project root..."
196196
cd "$ROCKETCHAT_ROOT"
197197
yarn build
198-
198+
199199
# Build the Meteor bundle (must be run from the meteor directory)
200200
log_info "Building Meteor bundle..."
201201
cd "$ROCKETCHAT_ROOT/apps/meteor"
202202
METEOR_DISABLE_OPTIMISTIC_CACHING=1 meteor build --server-only --directory "$BUILD_DIR"
203-
203+
204204
log_success "Build completed!"
205205
else
206206
log_info "🚀 Using pre-built image: $PREBUILT_IMAGE"
@@ -289,7 +289,7 @@ wait_for_service() {
289289
# Capture curl output and error for debugging
290290
curl_output=$(curl -fsS --cacert "$ca_cert" --resolve "${host}:${port}:127.0.0.1" "$url" 2>&1)
291291
curl_exit_code=$?
292-
292+
293293
if [ $curl_exit_code -eq 0 ]; then
294294
log_success "$name is ready!"
295295
return 0
@@ -328,8 +328,8 @@ fi
328328
if [ "$NO_TEST" = false ]; then
329329
log_info "Running end-to-end tests..."
330330
cd "$PACKAGE_ROOT"
331-
332-
yarn testend-to-end
331+
332+
IS_EE=true NODE_EXTRA_CA_CERTS=$(pwd)/docker-compose/traefik/certs/ca/rootCA.crt yarn test:federation
333333
TEST_EXIT_CODE=$?
334334
else
335335
log_info "No-test mode: skipping test execution"

0 commit comments

Comments
 (0)