Skip to content

Commit 5dd289d

Browse files
a-schildclaude
andcommitted
test: disable password_policy in the test container so user-creation tests pass
On a fresh Nextcloud the default password_policy app rejects the fixed simple passwords used by the tests, so createUser returned false and every user-dependent test (and the sharing tests, whose setUp creates a user) cascaded into failure. Disable the app after the container starts via occ (run as www-data) so the test environment is deterministic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fbf57b7 commit 5dd289d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/test/java/org/aarboard/nextcloud/api/NextcloudTestContainer.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
*/
1717
package org.aarboard.nextcloud.api;
1818

19+
import java.io.IOException;
1920
import java.time.Duration;
2021

2122
import org.testcontainers.DockerClientFactory;
23+
import org.testcontainers.containers.Container.ExecResult;
24+
import org.testcontainers.containers.ExecConfig;
2225
import org.testcontainers.containers.GenericContainer;
2326
import org.testcontainers.containers.wait.strategy.Wait;
2427
import org.testcontainers.utility.DockerImageName;
@@ -107,10 +110,36 @@ public static synchronized void ensureStarted() {
107110
.forResponsePredicate(body -> body.contains("\"installed\":true"))
108111
.withStartupTimeout(Duration.ofMinutes(5)));
109112
container.start();
113+
disablePasswordPolicy();
110114

111115
System.setProperty("nextcloud.api.test.servername", container.getHost());
112116
System.setProperty("nextcloud.api.test.serverport", String.valueOf(container.getMappedPort(80)));
113117
System.setProperty("nextcloud.api.test.username", ADMIN_USER);
114118
System.setProperty("nextcloud.api.test.password", ADMIN_PASSWORD);
115119
}
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+
}
116145
}

0 commit comments

Comments
 (0)