|
16 | 16 | */ |
17 | 17 | package org.aarboard.nextcloud.api; |
18 | 18 |
|
| 19 | +import java.io.IOException; |
19 | 20 | import java.time.Duration; |
20 | 21 |
|
21 | 22 | import org.testcontainers.DockerClientFactory; |
| 23 | +import org.testcontainers.containers.Container.ExecResult; |
| 24 | +import org.testcontainers.containers.ExecConfig; |
22 | 25 | import org.testcontainers.containers.GenericContainer; |
23 | 26 | import org.testcontainers.containers.wait.strategy.Wait; |
24 | 27 | import org.testcontainers.utility.DockerImageName; |
@@ -107,10 +110,36 @@ public static synchronized void ensureStarted() { |
107 | 110 | .forResponsePredicate(body -> body.contains("\"installed\":true")) |
108 | 111 | .withStartupTimeout(Duration.ofMinutes(5))); |
109 | 112 | container.start(); |
| 113 | + disablePasswordPolicy(); |
110 | 114 |
|
111 | 115 | System.setProperty("nextcloud.api.test.servername", container.getHost()); |
112 | 116 | System.setProperty("nextcloud.api.test.serverport", String.valueOf(container.getMappedPort(80))); |
113 | 117 | System.setProperty("nextcloud.api.test.username", ADMIN_USER); |
114 | 118 | System.setProperty("nextcloud.api.test.password", ADMIN_PASSWORD); |
115 | 119 | } |
| 120 | + |
| 121 | + /** |
| 122 | + * Disables the {@code password_policy} app so the tests, which create users |
| 123 | + * with fixed simple passwords, are not rejected by Nextcloud's default |
| 124 | + * password/complexity/breach checks. Best-effort: a failure here is logged |
| 125 | + * but does not abort the suite. occ must run as the {@code www-data} user |
| 126 | + * (it refuses to run as root). |
| 127 | + */ |
| 128 | + private static void disablePasswordPolicy() { |
| 129 | + try { |
| 130 | + ExecResult result = container.execInContainer(ExecConfig.builder() |
| 131 | + .user("www-data") |
| 132 | + .command(new String[] {"php", "occ", "app:disable", "password_policy"}) |
| 133 | + .build()); |
| 134 | + if (result.getExitCode() != 0) { |
| 135 | + System.err.println("Could not disable password_policy app: " |
| 136 | + + result.getStdout() + result.getStderr()); |
| 137 | + } |
| 138 | + } catch (IOException | InterruptedException e) { |
| 139 | + System.err.println("Could not disable password_policy app: " + e.getMessage()); |
| 140 | + if (e instanceof InterruptedException) { |
| 141 | + Thread.currentThread().interrupt(); |
| 142 | + } |
| 143 | + } |
| 144 | + } |
116 | 145 | } |
0 commit comments