testcontainers/testcontainers-java · error · IllegalArgumentException

Password must contain characters from three of the…

Error message

Password must contain characters from three of the following four categories:
 - Latin uppercase letters (A through Z)
 - Latin lowercase letters (a through z)
 - Base 10 digits (0 through 9)
 - Non-alphanumeric characters such as: exclamation point (!), dollar sign ($), number sign (#), or percent (%).

What it means

SQL Server requires the sa password to include characters from at least three of four categories: uppercase, lowercase, digits, and non-alphanumeric symbols. testcontainers pre-validates this with regex patterns in checkPasswordStrength() so misconfiguration fails fast instead of at container startup.

Solutions

  1. Add characters from a third category (e.g. append "!" or mix case and digits)
  2. Use a known-good password like "yourStrong(!)Password"
  3. Pre-validate the password against the 3-of-4 category rule in test setup

Example fix

// before
container.withPassword("abcdefgh"); // only lowercase
// after
container.withPassword("Abcdefg1!"); // upper + lower + digit + symbol
Defensive patterns

Strategy: validation

Validate before calling

boolean strong = password != null
    && password.matches(".*[A-Z].*")
    && password.matches(".*[a-z].*")
    && password.matches(".*[0-9].*")
    && password.matches(".*[^A-Za-z0-9].*");
if (!strong) throw new IllegalArgumentException("Password needs 3 of 4 character categories");

Try / catch

try { container.withPassword(pw); } catch (IllegalArgumentException e) { throw new IllegalStateException("SA password fails SQL Server complexity policy: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: Calling withPassword() with an 8+ character password composed of fewer than three character categories, e.g. "abcdefgh" or "12345678".

Common situations: Using alphabetic-only or digit-only test passwords; secrets generated with limited character sets; users unaware SQL Server enforces complexity policy.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/a10efe42c12db69a. Report an issue: GitHub.

Appendix: source

Thrown at modules/mssqlserver/src/main/java/org/testcontainers/containers/MSSQLServerContainer.java:159

        if (password == null) {
            throw new IllegalArgumentException("Null password is not allowed");
        }

        if (password.length() < 8) {
            throw new IllegalArgumentException("Password should be at least 8 characters long");
        }

        if (password.length() > 128) {
            throw new IllegalArgumentException("Password can be up to 128 characters long");
        }

        long satisfiedCategories = Stream
            .of(PASSWORD_CATEGORY_VALIDATION_PATTERNS)
            .filter(p -> p.matcher(password).find())
            .count();

        if (satisfiedCategories < 3) {
            throw new IllegalArgumentException(
                "Password must contain characters from three of the following four categories:\n" +
                " - Latin uppercase letters (A through Z)\n" +
                " - Latin lowercase letters (a through z)\n" +
                " - Base 10 digits (0 through 9)\n" +
                " - Non-alphanumeric characters such as: exclamation point (!), dollar sign ($), number sign (#), " +
                "or percent (%)."
            );
        }
    }
}

View on GitHub (pinned to 8e549514e3)