Browse Source

tool,nextcloud,neon: Disable password policy and use easier passwords

pull/77/head
jld3103 2 years ago
parent
commit
9d57fab5b4
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 6
      packages/neon/integration_test/screenshot_test.dart
  2. 4
      packages/nextcloud/test/core_test.dart
  3. 17
      packages/nextcloud/test/helper.dart
  4. 4
      packages/nextcloud/test/news_test.dart
  5. 4
      packages/nextcloud/test/notes_test.dart
  6. 9
      packages/nextcloud/test/notifications_test.dart
  7. 14
      packages/nextcloud/test/provisioning_api_test.dart
  8. 22
      packages/nextcloud/test/user_status_test.dart
  9. 4
      packages/nextcloud/test/webdav_test.dart
  10. 18
      tool/Dockerfile.dev
  11. 2
      tool/build-dev-container-image.sh
  12. 5
      tool/common.sh
  13. 2
      tool/generate-screenshots.sh
  14. 9
      tool/run-dev-instance.sh

6
packages/neon/integration_test/screenshot_test.dart

@ -218,8 +218,8 @@ Future main() async {
final account = Account( final account = Account(
serverURL: 'http://10.0.2.2', serverURL: 'http://10.0.2.2',
username: 'test', username: 'user1',
password: 'supersafepasswordtocircumventpasswordpolicies', password: 'user1',
); );
setUpAll(() async { setUpAll(() async {
@ -541,7 +541,7 @@ Future main() async {
await binding.takeScreenshot('settings_accounts'); await binding.takeScreenshot('settings_accounts');
// Go to account settings // 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.pumpAndSettle();
await tester.tap(find.text('Automatic')); await tester.tap(find.text('Automatic'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();

4
packages/nextcloud/test/core_test.dart

@ -13,9 +13,7 @@ Future main() async {
group('core', () { group('core', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Is supported', () async { test('Is supported', () async {

17
packages/nextcloud/test/helper.dart

@ -9,8 +9,8 @@ import 'package:process_run/cmd_run.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
const String nextcloudVersion = '24.0.5'; const String nextcloudVersion = '24.0.5';
const String defaultUsername = 'test'; const String defaultUsername = 'user1';
const String defaultPassword = 'supersafepasswordtocircumventpasswordpolicies'; const String defaultPassword = 'user1';
class TestNextcloudClient extends NextcloudClient { class TestNextcloudClient extends NextcloudClient {
TestNextcloudClient( TestNextcloudClient(
@ -223,11 +223,13 @@ class TestHelper {
class TestNextcloudUser { class TestNextcloudUser {
TestNextcloudUser( TestNextcloudUser(
this.username, { this.username,
this.password, {
this.displayName, this.displayName,
}); });
final String username; final String username;
final String password;
final String? displayName; final String? displayName;
} }
@ -245,8 +247,8 @@ class TestDockerHelper {
'WORKDIR /usr/src/nextcloud', 'WORKDIR /usr/src/nextcloud',
'RUN chown -R www-data:www-data .', 'RUN chown -R www-data:www-data .',
'USER www-data', 'USER www-data',
'RUN ./occ maintenance:install --admin-user admin --admin-pass $defaultPassword --admin-email admin@example.com', 'RUN ./occ maintenance:install --admin-pass admin --admin-email admin@example.com',
// Required to workaround restrictions for localhost and http only push proxies 'RUN ./occ app:disable password_policy',
'RUN ./occ config:system:set allow_local_remote_servers --value=true', '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', 'RUN sed -i "s/localhost/host.docker.internal/" /usr/src/nextcloud/apps/notifications/lib/Controller/PushController.php',
'ADD overlay /usr/src/nextcloud/', 'ADD overlay /usr/src/nextcloud/',
@ -275,12 +277,13 @@ class TestDockerHelper {
static String generateCreateTestUserInstruction() => generateCreateUserInstruction( static String generateCreateTestUserInstruction() => generateCreateUserInstruction(
TestNextcloudUser( TestNextcloudUser(
defaultUsername, defaultUsername,
displayName: 'Test', defaultPassword,
displayName: 'User One',
), ),
); );
static String generateCreateUserInstruction(final TestNextcloudUser user) => 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( static String generateInstallAppInstruction(
final String appName, final String appName,

4
packages/nextcloud/test/news_test.dart

@ -11,9 +11,7 @@ Future main() async {
group('news', () { group('news', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
Future<NewsListFeeds> addWikipediaFeed([final int? folderID]) => client.news.addFeed( Future<NewsListFeeds> addWikipediaFeed([final int? folderID]) => client.news.addFeed(

4
packages/nextcloud/test/notes_test.dart

@ -8,9 +8,7 @@ Future main() async {
group('notes', () { group('notes', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Is supported', () async { test('Is supported', () async {

9
packages/nextcloud/test/notifications_test.dart

@ -12,12 +12,13 @@ Future main() async {
group('notifications', () { group('notifications', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(
client = await TestHelper.getPreparedClient( () async => client = await TestHelper.getPreparedClient(
dockerImageName, dockerImageName,
username: 'admin', username: 'admin',
); password: 'admin',
}); ),
);
tearDown(() => client.destroy()); tearDown(() => client.destroy());
Future sendTestNotification() async { Future sendTestNotification() async {

14
packages/nextcloud/test/provisioning_api_test.dart

@ -8,23 +8,21 @@ Future main() async {
group('provisioning_api', () { group('provisioning_api', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Get current user', () async { test('Get current user', () async {
final user = await client.provisioningApi.getCurrentUser(); final user = await client.provisioningApi.getCurrentUser();
expect(user.ocs!.data!.id, 'test'); expect(user.ocs!.data!.id, 'user1');
expect(user.ocs!.data!.getDisplayName(), 'Test'); expect(user.ocs!.data!.getDisplayName(), 'User One');
expect(user.ocs!.data!.displaynameScope, 'v2-federated'); expect(user.ocs!.data!.displaynameScope, 'v2-federated');
expect(user.ocs!.data!.language, 'en'); expect(user.ocs!.data!.language, 'en');
}); });
test('Get user by username', () async { test('Get user by username', () async {
final user = await client.provisioningApi.getUser(userId: 'test'); final user = await client.provisioningApi.getUser(userId: 'user1');
expect(user.ocs!.data!.id, 'test'); expect(user.ocs!.data!.id, 'user1');
expect(user.ocs!.data!.getDisplayName(), 'Test'); expect(user.ocs!.data!.getDisplayName(), 'User One');
expect(user.ocs!.data!.displaynameScope, 'v2-federated'); expect(user.ocs!.data!.displaynameScope, 'v2-federated');
expect(user.ocs!.data!.language, 'en'); expect(user.ocs!.data!.language, 'en');
}); });

22
packages/nextcloud/test/user_status_test.dart

@ -8,9 +8,7 @@ Future main() async {
group('user_status', () { group('user_status', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Find all predefined statuses', () async { test('Find all predefined statuses', () async {
@ -47,7 +45,7 @@ Future main() async {
test('Set status', () async { test('Set status', () async {
final response = await client.userStatus.setStatus(statusType: UserStatusType.online); 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!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
@ -63,7 +61,7 @@ Future main() async {
await client.userStatus.setStatus(statusType: UserStatusType.online); await client.userStatus.setStatus(statusType: UserStatusType.online);
final response = await client.userStatus.getStatus(); 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!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
@ -81,7 +79,7 @@ Future main() async {
response = await client.userStatus.findAllStatuses(); response = await client.userStatus.findAllStatuses();
expect(response.ocs!.data, hasLength(1)); 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].message, null);
expect(response.ocs!.data![0].icon, null); expect(response.ocs!.data![0].icon, null);
expect(response.ocs!.data![0].clearAt, null); expect(response.ocs!.data![0].clearAt, null);
@ -92,8 +90,8 @@ Future main() async {
// Same as getting status // Same as getting status
await client.userStatus.setStatus(statusType: UserStatusType.online); await client.userStatus.setStatus(statusType: UserStatusType.online);
final response = await client.userStatus.findStatus(userId: 'test'); final response = await client.userStatus.findStatus(userId: 'user1');
expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'test'); expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'user1');
expect(response.ocs!.data!.userStatusPublicUserStatus!.message, null); expect(response.ocs!.data!.userStatusPublicUserStatus!.message, null);
expect(response.ocs!.data!.userStatusPublicUserStatus!.icon, null); expect(response.ocs!.data!.userStatusPublicUserStatus!.icon, null);
expect(response.ocs!.data!.userStatusPublicUserStatus!.clearAt, null); expect(response.ocs!.data!.userStatusPublicUserStatus!.clearAt, null);
@ -106,7 +104,7 @@ Future main() async {
messageId: 'meeting', messageId: 'meeting',
clearAt: clearAt, 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!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, 'meeting'); expect(response.ocs!.data!.userStatus!.messageId, 'meeting');
expect(response.ocs!.data!.userStatus!.messageIsPredefined, true); expect(response.ocs!.data!.userStatus!.messageIsPredefined, true);
@ -123,7 +121,7 @@ Future main() async {
message: 'bla', message: 'bla',
clearAt: clearAt, 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!.message, 'bla');
expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
@ -143,7 +141,7 @@ Future main() async {
await client.userStatus.clearMessage(); await client.userStatus.clearMessage();
final response = await client.userStatus.getStatus(); 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!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);
@ -157,7 +155,7 @@ Future main() async {
await client.userStatus.heartbeat(status: UserStatusType.online); await client.userStatus.heartbeat(status: UserStatusType.online);
final response = await client.userStatus.getStatus(); 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!.message, null);
expect(response.ocs!.data!.userStatus!.messageId, null); expect(response.ocs!.data!.userStatus!.messageId, null);
expect(response.ocs!.data!.userStatus!.messageIsPredefined, false); expect(response.ocs!.data!.userStatus!.messageIsPredefined, false);

4
packages/nextcloud/test/webdav_test.dart

@ -12,9 +12,7 @@ Future main() async {
group('webdav', () { group('webdav', () {
late TestNextcloudClient client; late TestNextcloudClient client;
setUp(() async { setUp(() async => client = await TestHelper.getPreparedClient(dockerImageName));
client = await TestHelper.getPreparedClient(dockerImageName);
});
tearDown(() => client.destroy()); tearDown(() => client.destroy());
test('Fail without username', () async { test('Fail without username', () async {

18
tool/Dockerfile.dev

@ -2,13 +2,17 @@ FROM nextcloud:24.0.5
WORKDIR /usr/src/nextcloud WORKDIR /usr/src/nextcloud
RUN chown -R www-data:www-data . RUN chown -R www-data:www-data .
USER www-data USER www-data
ARG username
ARG password RUN ./occ maintenance:install --admin-pass admin --admin-email admin@example.com
RUN ./occ maintenance:install --admin-user admin --admin-pass "$password" --admin-email admin@example.com RUN ./occ app:disable password_policy
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 config:system:set allow_local_remote_servers --value=true 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 RUN sed -i "s/localhost/host.docker.internal/" /usr/src/nextcloud/apps/notifications/lib/Controller/PushController.php
ADD overlay /usr/src/nextcloud/ 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

2
tool/build-dev-container-image.sh

@ -2,4 +2,4 @@
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." 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

5
tool/common.sh

@ -1,5 +0,0 @@
#!/bin/bash
set -euxo pipefail
export username="test"
export password="supersafepasswordtocircumventpasswordpolicies"

2
tool/generate-screenshots.sh

@ -2,8 +2,6 @@
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
source tool/common.sh
./tool/build-dev-container-image.sh ./tool/build-dev-container-image.sh
container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)" container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)"
function cleanup() { function cleanup() {

9
tool/run-dev-instance.sh

@ -15,13 +15,11 @@ else
exit 1 exit 1
fi fi
source tool/common.sh
./tool/build-dev-container-image.sh ./tool/build-dev-container-image.sh
echo "TEST_HOST=$ip echo "TEST_HOST=$ip
TEST_USER=$username TEST_USER=user1
TEST_PASSWORD=$password" > packages/neon/assets/.env TEST_PASSWORD=user1" > packages/neon/assets/.env
( (
cd packages/nextcloud_push_proxy cd packages/nextcloud_push_proxy
fvm dart run bin/unified_push.dart ./tmp/devices.json fvm dart run bin/unified_push.dart ./tmp/devices.json
@ -31,5 +29,4 @@ function cleanup() {
rm packages/neon/assets/.env rm packages/neon/assets/.env
} }
trap cleanup EXIT 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" --add-host host.docker.internal:host-gateway nextcloud-neon-dev
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

Loading…
Cancel
Save