From 9d57fab5b4187c238d6aeca8abd7977de685112f Mon Sep 17 00:00:00 2001 From: jld3103 Date: Mon, 3 Oct 2022 15:23:04 +0200 Subject: [PATCH] tool,nextcloud,neon: Disable password policy and use easier passwords --- .../integration_test/screenshot_test.dart | 6 ++--- packages/nextcloud/test/core_test.dart | 4 +--- packages/nextcloud/test/helper.dart | 17 ++++++++------ packages/nextcloud/test/news_test.dart | 4 +--- packages/nextcloud/test/notes_test.dart | 4 +--- .../nextcloud/test/notifications_test.dart | 9 ++++---- .../nextcloud/test/provisioning_api_test.dart | 14 +++++------- packages/nextcloud/test/user_status_test.dart | 22 +++++++++---------- packages/nextcloud/test/webdav_test.dart | 4 +--- tool/Dockerfile.dev | 18 +++++++++------ tool/build-dev-container-image.sh | 2 +- tool/common.sh | 5 ----- tool/generate-screenshots.sh | 2 -- tool/run-dev-instance.sh | 9 +++----- 14 files changed, 53 insertions(+), 67 deletions(-) delete mode 100755 tool/common.sh diff --git a/packages/neon/integration_test/screenshot_test.dart b/packages/neon/integration_test/screenshot_test.dart index 97dd1c30..caa6ca32 100644 --- a/packages/neon/integration_test/screenshot_test.dart +++ b/packages/neon/integration_test/screenshot_test.dart @@ -218,8 +218,8 @@ Future main() async { final account = Account( serverURL: 'http://10.0.2.2', - username: 'test', - password: 'supersafepasswordtocircumventpasswordpolicies', + username: 'user1', + password: 'user1', ); setUpAll(() async { @@ -541,7 +541,7 @@ Future main() async { await binding.takeScreenshot('settings_accounts'); // Go to account settings - await tester.tap(find.text('test@10.0.2.2:80')); + await tester.tap(find.text('user1@10.0.2.2:80')); await tester.pumpAndSettle(); await tester.tap(find.text('Automatic')); await tester.pumpAndSettle(); diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index d1f08a90..6a06fe62 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -13,9 +13,7 @@ Future main() async { group('core', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); test('Is supported', () async { diff --git a/packages/nextcloud/test/helper.dart b/packages/nextcloud/test/helper.dart index acf4ec97..94534ade 100644 --- a/packages/nextcloud/test/helper.dart +++ b/packages/nextcloud/test/helper.dart @@ -9,8 +9,8 @@ import 'package:process_run/cmd_run.dart'; import 'package:test/test.dart'; const String nextcloudVersion = '24.0.5'; -const String defaultUsername = 'test'; -const String defaultPassword = 'supersafepasswordtocircumventpasswordpolicies'; +const String defaultUsername = 'user1'; +const String defaultPassword = 'user1'; class TestNextcloudClient extends NextcloudClient { TestNextcloudClient( @@ -223,11 +223,13 @@ class TestHelper { class TestNextcloudUser { TestNextcloudUser( - this.username, { + this.username, + this.password, { this.displayName, }); final String username; + final String password; final String? displayName; } @@ -245,8 +247,8 @@ class TestDockerHelper { 'WORKDIR /usr/src/nextcloud', 'RUN chown -R www-data:www-data .', 'USER www-data', - 'RUN ./occ maintenance:install --admin-user admin --admin-pass $defaultPassword --admin-email admin@example.com', - // Required to workaround restrictions for localhost and http only push proxies + 'RUN ./occ maintenance:install --admin-pass admin --admin-email admin@example.com', + 'RUN ./occ app:disable password_policy', 'RUN ./occ config:system:set allow_local_remote_servers --value=true', 'RUN sed -i "s/localhost/host.docker.internal/" /usr/src/nextcloud/apps/notifications/lib/Controller/PushController.php', 'ADD overlay /usr/src/nextcloud/', @@ -275,12 +277,13 @@ class TestDockerHelper { static String generateCreateTestUserInstruction() => generateCreateUserInstruction( TestNextcloudUser( defaultUsername, - displayName: 'Test', + defaultPassword, + displayName: 'User One', ), ); static String generateCreateUserInstruction(final TestNextcloudUser user) => - 'RUN OC_PASS="$defaultPassword" ./occ user:add --password-from-env ${user.displayName != null ? '--display-name="${user.displayName}"' : ''} ${user.username}'; + 'RUN OC_PASS="${user.password}" ./occ user:add --password-from-env ${user.displayName != null ? '--display-name="${user.displayName}"' : ''} ${user.username}'; static String generateInstallAppInstruction( final String appName, diff --git a/packages/nextcloud/test/news_test.dart b/packages/nextcloud/test/news_test.dart index 196f1a41..f8a65e52 100644 --- a/packages/nextcloud/test/news_test.dart +++ b/packages/nextcloud/test/news_test.dart @@ -11,9 +11,7 @@ Future main() async { group('news', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); Future addWikipediaFeed([final int? folderID]) => client.news.addFeed( diff --git a/packages/nextcloud/test/notes_test.dart b/packages/nextcloud/test/notes_test.dart index f3f1b0d9..9cf4145d 100644 --- a/packages/nextcloud/test/notes_test.dart +++ b/packages/nextcloud/test/notes_test.dart @@ -8,9 +8,7 @@ Future main() async { group('notes', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); test('Is supported', () async { diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index 10a525d9..d176f1c0 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/packages/nextcloud/test/notifications_test.dart @@ -12,12 +12,13 @@ Future main() async { group('notifications', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient( + setUp( + () async => client = await TestHelper.getPreparedClient( dockerImageName, username: 'admin', - ); - }); + password: 'admin', + ), + ); tearDown(() => client.destroy()); Future sendTestNotification() async { diff --git a/packages/nextcloud/test/provisioning_api_test.dart b/packages/nextcloud/test/provisioning_api_test.dart index 902703b5..6fc1f109 100644 --- a/packages/nextcloud/test/provisioning_api_test.dart +++ b/packages/nextcloud/test/provisioning_api_test.dart @@ -8,23 +8,21 @@ Future main() async { group('provisioning_api', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); test('Get current user', () async { final user = await client.provisioningApi.getCurrentUser(); - expect(user.ocs!.data!.id, 'test'); - expect(user.ocs!.data!.getDisplayName(), 'Test'); + expect(user.ocs!.data!.id, 'user1'); + expect(user.ocs!.data!.getDisplayName(), 'User One'); expect(user.ocs!.data!.displaynameScope, 'v2-federated'); expect(user.ocs!.data!.language, 'en'); }); test('Get user by username', () async { - final user = await client.provisioningApi.getUser(userId: 'test'); - expect(user.ocs!.data!.id, 'test'); - expect(user.ocs!.data!.getDisplayName(), 'Test'); + final user = await client.provisioningApi.getUser(userId: 'user1'); + expect(user.ocs!.data!.id, 'user1'); + expect(user.ocs!.data!.getDisplayName(), 'User One'); expect(user.ocs!.data!.displaynameScope, 'v2-federated'); expect(user.ocs!.data!.language, 'en'); }); diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index 54f4cf06..458165c7 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/packages/nextcloud/test/user_status_test.dart @@ -8,9 +8,7 @@ Future main() async { group('user_status', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); test('Find all predefined statuses', () async { @@ -47,7 +45,7 @@ Future main() async { test('Set status', () async { final response = await client.userStatus.setStatus(statusType: UserStatusType.online); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, null); expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); @@ -63,7 +61,7 @@ Future main() async { await client.userStatus.setStatus(statusType: UserStatusType.online); final response = await client.userStatus.getStatus(); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, null); expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); @@ -81,7 +79,7 @@ Future main() async { response = await client.userStatus.findAllStatuses(); expect(response.ocs!.data, hasLength(1)); - expect(response.ocs!.data![0].userId, 'test'); + expect(response.ocs!.data![0].userId, 'user1'); expect(response.ocs!.data![0].message, null); expect(response.ocs!.data![0].icon, null); expect(response.ocs!.data![0].clearAt, null); @@ -92,8 +90,8 @@ Future main() async { // Same as getting status await client.userStatus.setStatus(statusType: UserStatusType.online); - final response = await client.userStatus.findStatus(userId: 'test'); - expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'test'); + final response = await client.userStatus.findStatus(userId: 'user1'); + expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatusPublicUserStatus!.message, null); expect(response.ocs!.data!.userStatusPublicUserStatus!.icon, null); expect(response.ocs!.data!.userStatusPublicUserStatus!.clearAt, null); @@ -106,7 +104,7 @@ Future main() async { messageId: 'meeting', clearAt: clearAt, ); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, null); expect(response.ocs!.data!.userStatus!.messageId, 'meeting'); expect(response.ocs!.data!.userStatus!.messageIsPredefined, true); @@ -123,7 +121,7 @@ Future main() async { message: 'bla', clearAt: clearAt, ); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, 'bla'); expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); @@ -143,7 +141,7 @@ Future main() async { await client.userStatus.clearMessage(); final response = await client.userStatus.getStatus(); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, null); expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); @@ -157,7 +155,7 @@ Future main() async { await client.userStatus.heartbeat(status: UserStatusType.online); final response = await client.userStatus.getStatus(); - expect(response.ocs!.data!.userStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatus!.userId, 'user1'); expect(response.ocs!.data!.userStatus!.message, null); expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index b06453f8..addbbbb0 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -12,9 +12,7 @@ Future main() async { group('webdav', () { late TestNextcloudClient client; - setUp(() async { - client = await TestHelper.getPreparedClient(dockerImageName); - }); + setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName)); tearDown(() => client.destroy()); test('Fail without username', () async { diff --git a/tool/Dockerfile.dev b/tool/Dockerfile.dev index bfed0e77..c7038ad7 100644 --- a/tool/Dockerfile.dev +++ b/tool/Dockerfile.dev @@ -2,13 +2,17 @@ FROM nextcloud:24.0.5 WORKDIR /usr/src/nextcloud RUN chown -R www-data:www-data . USER www-data -ARG username -ARG password -RUN ./occ maintenance:install --admin-user admin --admin-pass "$password" --admin-email admin@example.com -RUN OC_PASS="$password" ./occ user:add --password-from-env --group admin "$username" -RUN ./occ app:install news -RUN ./occ app:install notes -RUN ./occ config:system:set trusted_domains 1 --value=10.0.2.2 + +RUN ./occ maintenance:install --admin-pass admin --admin-email admin@example.com +RUN ./occ app:disable password_policy RUN ./occ config:system:set allow_local_remote_servers --value=true +RUN ./occ config:system:set trusted_domains 1 --value=10.0.2.2 + RUN sed -i "s/localhost/host.docker.internal/" /usr/src/nextcloud/apps/notifications/lib/Controller/PushController.php ADD overlay /usr/src/nextcloud/ + +RUN OC_PASS="user1" ./occ user:add --password-from-env --display-name "User One" user1 +RUN OC_PASS="user2" ./occ user:add --password-from-env --display-name "User Two" user2 + +RUN ./occ app:install news +RUN ./occ app:install notes diff --git a/tool/build-dev-container-image.sh b/tool/build-dev-container-image.sh index 7c92902c..77665c13 100755 --- a/tool/build-dev-container-image.sh +++ b/tool/build-dev-container-image.sh @@ -2,4 +2,4 @@ set -euxo pipefail cd "$(dirname "$0")/.." -docker build -t nextcloud-neon-dev --build-arg "username=$username" --build-arg "password=$password" -f - ./packages/nextcloud/test < tool/Dockerfile.dev +docker build -t nextcloud-neon-dev -f - ./packages/nextcloud/test < tool/Dockerfile.dev diff --git a/tool/common.sh b/tool/common.sh deleted file mode 100755 index 98a51666..00000000 --- a/tool/common.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -export username="test" -export password="supersafepasswordtocircumventpasswordpolicies" diff --git a/tool/generate-screenshots.sh b/tool/generate-screenshots.sh index e130f936..92672b9a 100755 --- a/tool/generate-screenshots.sh +++ b/tool/generate-screenshots.sh @@ -2,8 +2,6 @@ set -euxo pipefail cd "$(dirname "$0")/.." -source tool/common.sh - ./tool/build-dev-container-image.sh container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)" function cleanup() { diff --git a/tool/run-dev-instance.sh b/tool/run-dev-instance.sh index 1cd1a46e..6d7880c7 100755 --- a/tool/run-dev-instance.sh +++ b/tool/run-dev-instance.sh @@ -15,13 +15,11 @@ else exit 1 fi -source tool/common.sh - ./tool/build-dev-container-image.sh echo "TEST_HOST=$ip -TEST_USER=$username -TEST_PASSWORD=$password" > packages/neon/assets/.env +TEST_USER=user1 +TEST_PASSWORD=user1" > packages/neon/assets/.env ( cd packages/nextcloud_push_proxy fvm dart run bin/unified_push.dart ./tmp/devices.json @@ -31,5 +29,4 @@ function cleanup() { rm packages/neon/assets/.env } trap cleanup EXIT -# The multiple ports are used to let the app think we are talking to two different servers when in fact it's only one -docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -p "80:80" -p "81:80" --add-host host.docker.internal:host-gateway nextcloud-neon-dev +docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -p "80:80" --add-host host.docker.internal:host-gateway nextcloud-neon-dev