{"record":{"id":"38709c73fcefad4d","repo":"elastic/elasticsearch","slug":"basic-auth-user-has-been-set-but-no-password","errorCode":null,"errorMessage":"Basic Auth user [{}] has been set, but no password has been configured","messagePattern":"Basic Auth user \\[(.+?)\\] has been set, but no password has been configured","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/testclusters/WaitForHttpResource.java","lineNumber":150,"sourceCode":"        configureBasicAuth(connection);\n        connection.setRequestMethod(\"GET\");\n        return connection;\n    }\n\n    private void configureSslContext(HttpURLConnection connection, SSLContext ssl) {\n        if (ssl != null) {\n            if (connection instanceof HttpsURLConnection) {\n                ((HttpsURLConnection) connection).setSSLSocketFactory(ssl.getSocketFactory());\n            } else {\n                throw new IllegalStateException(\"SSL trust has been configured, but [\" + url + \"] is not a 'https' URL\");\n            }\n        }\n    }\n\n    private void configureBasicAuth(HttpURLConnection connection) {\n        if (username != null) {\n            if (password == null) {\n                throw new IllegalStateException(\"Basic Auth user [\" + username + \"] has been set, but no password has been configured\");\n            }\n            connection.setRequestProperty(\n                \"Authorization\",\n                \"Basic \" + Base64.getEncoder().encodeToString((username + \":\" + password).getBytes(StandardCharsets.UTF_8))\n            );\n        }\n    }\n}\n","sourceCodeStart":132,"sourceCodeEnd":159,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/WaitForHttpResource.java#L132-L159","documentation":"WaitForHttpResource.configureBasicAuth() throws when a `username` is set but `password` is null. Basic Auth requires both halves; a username alone is always wrong and would produce a malformed Authorization header, so the build fails fast rather than sending a half-empty credential.","triggerScenarios":"Calling `.credentials(username, null)` or setting `.username = 'x'` without a corresponding password on a WaitForHttpResource used to poll a secured cluster.","commonSituations":"Security enabled on the cluster (default dev creds `elastic-admin:elastic-password`) but only the username was wired; password sourced from a Provider/property that resolved to null (e.g. `project.findProperty('es.password')` with the property unset); refactoring that moved the password assignment but missed this resource.","solutions":["Set both username and password: `waitResource.username='elastic-admin'; waitResource.password='elastic-password'` (or use the credentials helper).","If the password comes from a gradle property, ensure the property is set (`-Pes.password=...`) or supply a default.","If the cluster has security disabled, clear the username too — no auth needed."],"exampleFix":"// before\nwaitResource.username = 'elastic-admin'\n// password forgotten\n// after\nwaitResource.username = 'elastic-admin'\nwaitResource.password = 'elastic-password'","handlingStrategy":"validation","validationCode":"if (username != null && password == null) {\n  throw new IllegalStateException(\n    \"Username \" + username + \" set without password; pass both or neither.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set username and password together, ideally via a single `credentials(u, p)` helper.","When sourcing the password from a gradle property, supply a default or fail fast if unset.","If security is off, clear the username too."],"tags":["gradle","testclusters","auth","configuration","build-tools"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}