From 148582f04aa15717f359d1baa5f9e6ce9fb9e9d6 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:10:02 +0200 Subject: [PATCH 1/8] CI: Test registering with app.element.io --- .gitlab-ci.yml | 21 ++++++++-- tests/puppeteer/test-element-web.js | 65 +++++++++++++++++++++++++++++ tests/test-config.toml | 47 +++++++++++++++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 tests/puppeteer/test-element-web.js create mode 100644 tests/test-config.toml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92da543..ef3ccdf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - - test - build + - test - upload artifacts variables: @@ -8,8 +8,6 @@ variables: FF_USE_FASTZIP: 1 CACHE_COMPRESSION_LEVEL: fastest - - test:cargo: stage: "test" needs: [] @@ -34,6 +32,22 @@ test:cargo: - cargo test --workspace --verbose --locked - cargo clippy +test:register:element-release: + stage: "test" + needs: + - "build:cargo:x86_64-unknown-linux-gnu" + image: "buildkite/puppeteer:latest" + tags: ["docker"] + script: + - "CONDUIT_CONFIG=tests/test-config.toml ./conduit-x86_64-unknown-linux-gnu > conduit.log &&" + - "cd tests/puppeteer/" + - "npm install puppeteer" + - "node test-element-web.js" + - "killall conduit-x86_64-unknown-linux-gnu" + - "cd ../.." + - "cat conduit.log" + + # --------------------------------------------------------------------- # # Cargo: Compiling for different architectures # # --------------------------------------------------------------------- # @@ -76,6 +90,7 @@ build:cargo:x86_64-unknown-linux-gnu: extends: .build-cargo-shared-settings variables: TARGET: "x86_64-unknown-linux-gnu" + rules: [] build:cargo:armv7-unknown-linux-gnueabihf: extends: .build-cargo-shared-settings diff --git a/tests/puppeteer/test-element-web.js b/tests/puppeteer/test-element-web.js new file mode 100644 index 0000000..83a43c2 --- /dev/null +++ b/tests/puppeteer/test-element-web.js @@ -0,0 +1,65 @@ +const puppeteer = require('puppeteer'); + +run().then(() => console.log('Done')).catch(_error => process.exit(111)); + +async function run() { + + const username = "testuser" + String(Math.floor(Math.random()*100000)); + const password = "testpassword" + String(Math.floor(Math.random()*100000)); + console.debug("Testuser for this run:\n User: "+username+"\n Password: "+password); + + const browser = await puppeteer.launch({headless: true}); + + const page = await browser.newPage(); + await page.goto('https://app.element.io/'); + + console.debug("Click [Create Account] button"); + await page.waitForSelector('a.mx_ButtonCreateAccount'); + await page.click('a.mx_ButtonCreateAccount'); + + // The webapp should have loaded right now, if anything takes more than 5 seconds, something probably broke + page.setDefaultTimeout(5000); + + console.debug("Click [Edit] to switch homeserver"); + await page.waitForSelector('div.mx_ServerPicker_change'); + await page.click('div.mx_ServerPicker_change'); + + console.debug("Type in local homeserver url"); + await page.waitForSelector('input#mx_homeserverInput'); + await page.click('input#mx_homeserverInput'); + await page.click('input#mx_homeserverInput'); + await page.keyboard.type('http://localhost:6167'); + + console.debug("[Continue] with changed homeserver"); + await page.waitForSelector("div.mx_ServerPickerDialog_continue"); + await page.click('div.mx_ServerPickerDialog_continue'); + + console.debug("Type in username"); + await page.waitForSelector("input#mx_RegistrationForm_username"); + await page.click('input#mx_RegistrationForm_username'); + await page.keyboard.type(username); + + console.debug("Type in password"); + await page.waitForSelector("input#mx_RegistrationForm_password"); + await page.click('input#mx_RegistrationForm_password'); + await page.keyboard.type(password); + + console.debug("Type in password again"); + await page.waitForSelector("input#mx_RegistrationForm_passwordConfirm"); + await page.click('input#mx_RegistrationForm_passwordConfirm'); + await page.keyboard.type(password); + + console.debug("Click on [Register] to finish the account creation"); + await page.waitForSelector("input.mx_Login_submit"); + await page.click('input.mx_Login_submit'); + + console.debug("Wait for chat window to show up"); + await page.waitForSelector("div.mx_HomePage_default_buttons"); + console.debug("Apparently the registration worked."); + + // Wait 5 seconds + await new Promise(resolve => setTimeout(resolve, 5000)); + + // Close the browser and exit the script + await browser.close(); +} \ No newline at end of file diff --git a/tests/test-config.toml b/tests/test-config.toml new file mode 100644 index 0000000..26b0ee3 --- /dev/null +++ b/tests/test-config.toml @@ -0,0 +1,47 @@ +[global] +# The server_name is the name of this server. It is used as a suffix for user +# and room ids. Examples: matrix.org, conduit.rs +# The Conduit server needs to be reachable at https://your.server.name/ on port +# 443 (client-server) and 8448 (federation) OR you can create /.well-known +# files to redirect requests. See +# https://matrix.org/docs/spec/client_server/latest#get-well-known-matrix-client +# and https://matrix.org/docs/spec/server_server/r0.1.4#get-well-known-matrix-server +# for more information + +# YOU NEED TO EDIT THIS +server_name = "localhost" + +# This is the only directory where Conduit will save its data +database_path = "/home/jfowl/projects/conduit/_conduit_db" + +# The port Conduit will be running on. You need to set up a reverse proxy in +# your web server (e.g. apache or nginx), so all requests to /_matrix on port +# 443 and 8448 will be forwarded to the Conduit instance running on this port +port = 6167 + +# Max size for uploads +max_request_size = 20_000_000 # in bytes + +# Disable registration. No new users will be able to register on this server +allow_registration = true + +# Disable encryption, so no new encrypted rooms can be created +# Note: existing rooms will continue to work +#allow_encryption = false +#allow_federation = false + +# Enable jaeger to support monitoring and troubleshooting through jaeger +#allow_jaeger = false + +trusted_servers = ["matrix.org"] + +#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time +#log = "info,state_res=warn,rocket=off,_=off,sled=off" +#workers = 4 # default: cpu core count * 2 + +address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy + +proxy = "none" # more examples can be found at src/database/proxy.rs:6 + +# The total amount of memory that the database will use. +#db_cache_capacity_mb = 200 \ No newline at end of file From c9ff45a51b587290f90ac8933a099864411a4b43 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:14:32 +0200 Subject: [PATCH 2/8] Fix: Rules can't be empty: Just always run the build job --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef3ccdf..7337be7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -90,7 +90,8 @@ build:cargo:x86_64-unknown-linux-gnu: extends: .build-cargo-shared-settings variables: TARGET: "x86_64-unknown-linux-gnu" - rules: [] + rules: + - if: "$CI_COMMIT_BRANCH" build:cargo:armv7-unknown-linux-gnueabihf: extends: .build-cargo-shared-settings From 0fc49b7d5e9a6b92b64750895e8f937212b56459 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:21:29 +0200 Subject: [PATCH 3/8] Fix: Actually use a db path that the CI runner knows --- tests/test-config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-config.toml b/tests/test-config.toml index 26b0ee3..badc6eb 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -12,7 +12,7 @@ server_name = "localhost" # This is the only directory where Conduit will save its data -database_path = "/home/jfowl/projects/conduit/_conduit_db" +database_path = "/tmp" # The port Conduit will be running on. You need to set up a reverse proxy in # your web server (e.g. apache or nginx), so all requests to /_matrix on port From 1f754cab0eeb24b9b9a1bdb8ee9905b29b0af0de Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:31:00 +0200 Subject: [PATCH 4/8] Fix: Actually try to run conduit in the background --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7337be7..66ff3e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,7 +39,7 @@ test:register:element-release: image: "buildkite/puppeteer:latest" tags: ["docker"] script: - - "CONDUIT_CONFIG=tests/test-config.toml ./conduit-x86_64-unknown-linux-gnu > conduit.log &&" + - "CONDUIT_CONFIG=tests/test-config.toml ./conduit-x86_64-unknown-linux-gnu > conduit.log &" - "cd tests/puppeteer/" - "npm install puppeteer" - "node test-element-web.js" From 3cce7fc8ba30ab6afd2c89d00676d753430acb78 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:47:46 +0200 Subject: [PATCH 5/8] CI: Output debug artifacts --- .gitlab-ci.yml | 5 ++++ tests/puppeteer/test-element-web.js | 43 ++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 66ff3e8..e6e22cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,6 +46,11 @@ test:register:element-release: - "killall conduit-x86_64-unknown-linux-gnu" - "cd ../.." - "cat conduit.log" + artifacts: + paths: + - "tests/puppeteer/*.png" + - "conduit.log" + expire_in: 1 week # --------------------------------------------------------------------- # diff --git a/tests/puppeteer/test-element-web.js b/tests/puppeteer/test-element-web.js index 83a43c2..a3c3dae 100644 --- a/tests/puppeteer/test-element-web.js +++ b/tests/puppeteer/test-element-web.js @@ -1,22 +1,34 @@ const puppeteer = require('puppeteer'); -run().then(() => console.log('Done')).catch(_error => process.exit(111)); +run().then(() => console.log('Done')).catch(error => { + console.error("Registration test failed"); + console.error(error); + process.exit(111); +}); async function run() { - const username = "testuser" + String(Math.floor(Math.random()*100000)); - const password = "testpassword" + String(Math.floor(Math.random()*100000)); - console.debug("Testuser for this run:\n User: "+username+"\n Password: "+password); + const username = "testuser" + String(Math.floor(Math.random() * 100000)); + const password = "testpassword" + String(Math.floor(Math.random() * 100000)); + console.debug("Testuser for this run:\n User: " + username + "\n Password: " + password); - const browser = await puppeteer.launch({headless: true}); + const browser = await puppeteer.launch({ + headless: true, args: [ + "--no-sandbox" + ] + }); const page = await browser.newPage(); await page.goto('https://app.element.io/'); + await page.screenshot({ path: '01-element-web-started.png' }); + console.debug("Click [Create Account] button"); await page.waitForSelector('a.mx_ButtonCreateAccount'); await page.click('a.mx_ButtonCreateAccount'); + await page.screenshot({ path: '02-clicked-create-account-button.png' }); + // The webapp should have loaded right now, if anything takes more than 5 seconds, something probably broke page.setDefaultTimeout(5000); @@ -24,41 +36,58 @@ async function run() { await page.waitForSelector('div.mx_ServerPicker_change'); await page.click('div.mx_ServerPicker_change'); + await page.screenshot({ path: '03-clicked-edit-homeserver-button.png' }); + console.debug("Type in local homeserver url"); await page.waitForSelector('input#mx_homeserverInput'); await page.click('input#mx_homeserverInput'); await page.click('input#mx_homeserverInput'); await page.keyboard.type('http://localhost:6167'); + await page.screenshot({ path: '04-typed-in-homeserver.png' }); + console.debug("[Continue] with changed homeserver"); await page.waitForSelector("div.mx_ServerPickerDialog_continue"); await page.click('div.mx_ServerPickerDialog_continue'); + await page.screenshot({ path: '05-back-to-enter-user-credentials.png' }); + console.debug("Type in username"); await page.waitForSelector("input#mx_RegistrationForm_username"); await page.click('input#mx_RegistrationForm_username'); await page.keyboard.type(username); + await page.screenshot({ path: '06-typed-in-username.png' }); + console.debug("Type in password"); await page.waitForSelector("input#mx_RegistrationForm_password"); await page.click('input#mx_RegistrationForm_password'); await page.keyboard.type(password); + await page.screenshot({ path: '07-typed-in-password-once.png' }); + console.debug("Type in password again"); await page.waitForSelector("input#mx_RegistrationForm_passwordConfirm"); await page.click('input#mx_RegistrationForm_passwordConfirm'); await page.keyboard.type(password); + await page.screenshot({ path: '08-typed-in-password-twice.png' }); + console.debug("Click on [Register] to finish the account creation"); await page.waitForSelector("input.mx_Login_submit"); await page.click('input.mx_Login_submit'); + await page.screenshot({ path: '09-clicked-on-register-button.png' }); + + // Waiting for the app to login can take some time, so be patient. + page.setDefaultTimeout(10000); + console.debug("Wait for chat window to show up"); await page.waitForSelector("div.mx_HomePage_default_buttons"); console.debug("Apparently the registration worked."); - // Wait 5 seconds - await new Promise(resolve => setTimeout(resolve, 5000)); + await page.screenshot({ path: '10-logged-in-homescreen.png' }); + // Close the browser and exit the script await browser.close(); From 2c217b5369f41907e66582cb614f6c9b5f32a5f5 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 21:59:05 +0200 Subject: [PATCH 6/8] Fix: More robust CI job cleanup --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e6e22cc..5a2b6aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,14 +43,16 @@ test:register:element-release: - "cd tests/puppeteer/" - "npm install puppeteer" - "node test-element-web.js" - - "killall conduit-x86_64-unknown-linux-gnu" + - "killall --regexp \"conduit\"" - "cd ../.." - "cat conduit.log" artifacts: paths: - "tests/puppeteer/*.png" - - "conduit.log" + - "*.log" expire_in: 1 week + when: always + retry: 1 # --------------------------------------------------------------------- # From 72637de9a982b811e73f6d7fd6d95e31e97406ce Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Fri, 16 Jul 2021 22:18:54 +0200 Subject: [PATCH 7/8] Cleanup for MR --- .gitlab-ci.yml | 10 ++++++---- .../test-element-web-registration.js} | 15 +++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) rename tests/{puppeteer/test-element-web.js => client-element-web/test-element-web-registration.js} (85%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a2b6aa..cb7385a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,23 +32,25 @@ test:cargo: - cargo test --workspace --verbose --locked - cargo clippy -test:register:element-release: + +test:register:element-web-stable: stage: "test" needs: - "build:cargo:x86_64-unknown-linux-gnu" image: "buildkite/puppeteer:latest" tags: ["docker"] + interruptible: true script: - "CONDUIT_CONFIG=tests/test-config.toml ./conduit-x86_64-unknown-linux-gnu > conduit.log &" - - "cd tests/puppeteer/" + - "cd tests/client-element-web/" - "npm install puppeteer" - - "node test-element-web.js" + - "node test-element-web-registration.js \"https://app.element.io/\" \"http://localhost:6167\"" - "killall --regexp \"conduit\"" - "cd ../.." - "cat conduit.log" artifacts: paths: - - "tests/puppeteer/*.png" + - "tests/client-element-web/*.png" - "*.log" expire_in: 1 week when: always diff --git a/tests/puppeteer/test-element-web.js b/tests/client-element-web/test-element-web-registration.js similarity index 85% rename from tests/puppeteer/test-element-web.js rename to tests/client-element-web/test-element-web-registration.js index a3c3dae..8f2e7f0 100644 --- a/tests/puppeteer/test-element-web.js +++ b/tests/client-element-web/test-element-web-registration.js @@ -1,13 +1,20 @@ const puppeteer = require('puppeteer'); run().then(() => console.log('Done')).catch(error => { - console.error("Registration test failed"); + console.error("Registration test failed."); + console.error("There might be a screenshot of the failure in the artifacts.\n"); console.error(error); process.exit(111); }); async function run() { + const elementUrl = process.argv[process.argv.length - 2]; + console.debug("Testing registration with ElementWeb hosted at "+ elementUrl); + + const homeserverUrl = process.argv[process.argv.length - 1]; + console.debug("Homeserver url: "+ homeserverUrl); + const username = "testuser" + String(Math.floor(Math.random() * 100000)); const password = "testpassword" + String(Math.floor(Math.random() * 100000)); console.debug("Testuser for this run:\n User: " + username + "\n Password: " + password); @@ -19,9 +26,9 @@ async function run() { }); const page = await browser.newPage(); - await page.goto('https://app.element.io/'); + await page.goto(elementUrl); - await page.screenshot({ path: '01-element-web-started.png' }); + await page.screenshot({ path: '01-element-web-opened.png' }); console.debug("Click [Create Account] button"); await page.waitForSelector('a.mx_ButtonCreateAccount'); @@ -42,7 +49,7 @@ async function run() { await page.waitForSelector('input#mx_homeserverInput'); await page.click('input#mx_homeserverInput'); await page.click('input#mx_homeserverInput'); - await page.keyboard.type('http://localhost:6167'); + await page.keyboard.type(homeserverUrl); await page.screenshot({ path: '04-typed-in-homeserver.png' }); From 247b372ad6cc3fbcf7df368ab5b12442b08584b2 Mon Sep 17 00:00:00 2001 From: Jonas Zohren Date: Sun, 18 Jul 2021 22:20:17 +0200 Subject: [PATCH 8/8] Cleanup test-config.toml comments --- tests/test-config.toml | 44 ++++++------------------------------------ 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/tests/test-config.toml b/tests/test-config.toml index badc6eb..c466687 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -1,47 +1,15 @@ [global] -# The server_name is the name of this server. It is used as a suffix for user -# and room ids. Examples: matrix.org, conduit.rs -# The Conduit server needs to be reachable at https://your.server.name/ on port -# 443 (client-server) and 8448 (federation) OR you can create /.well-known -# files to redirect requests. See -# https://matrix.org/docs/spec/client_server/latest#get-well-known-matrix-client -# and https://matrix.org/docs/spec/server_server/r0.1.4#get-well-known-matrix-server -# for more information -# YOU NEED TO EDIT THIS +# Server runs in same container as tests do, so localhost is fine server_name = "localhost" -# This is the only directory where Conduit will save its data +# With a bit of luck /tmp is a RAM disk, so that the file system does not become the bottleneck while testing database_path = "/tmp" -# The port Conduit will be running on. You need to set up a reverse proxy in -# your web server (e.g. apache or nginx), so all requests to /_matrix on port -# 443 and 8448 will be forwarded to the Conduit instance running on this port +# All the other settings are left at their defaults: port = 6167 - -# Max size for uploads -max_request_size = 20_000_000 # in bytes - -# Disable registration. No new users will be able to register on this server +max_request_size = 20_000_000 allow_registration = true - -# Disable encryption, so no new encrypted rooms can be created -# Note: existing rooms will continue to work -#allow_encryption = false -#allow_federation = false - -# Enable jaeger to support monitoring and troubleshooting through jaeger -#allow_jaeger = false - trusted_servers = ["matrix.org"] - -#max_concurrent_requests = 100 # How many requests Conduit sends to other servers at the same time -#log = "info,state_res=warn,rocket=off,_=off,sled=off" -#workers = 4 # default: cpu core count * 2 - -address = "127.0.0.1" # This makes sure Conduit can only be reached using the reverse proxy - -proxy = "none" # more examples can be found at src/database/proxy.rs:6 - -# The total amount of memory that the database will use. -#db_cache_capacity_mb = 200 \ No newline at end of file +address = "127.0.0.1" +proxy = "none" \ No newline at end of file