Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.impl;

Expand Down Expand Up @@ -86,4 +86,11 @@ public String getPassword() {
public String getDatabase() {
return database;
}

// Override toString() to avoid printing the password in logs or error messages
@Override
public String toString() {
String db = (database != null) ? "/" + database : "";
return username + ":****@" + host + ":" + port + db;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
package com.marklogic.client.impl;

Expand Down Expand Up @@ -197,6 +197,18 @@ void nonNumericPortInConnectionString() {
assertEquals("Invalid value for connection string; port must be numeric, but was 'nonNumericPort'", ex.getMessage());
}

@Test
void toStringRedactsPassword() {
ConnectionString cs = new ConnectionString("user:secret@localhost:8000", "connection string");
assertEquals("user:****@localhost:8000", cs.toString());
}

@Test
void toStringRedactsPasswordWithDatabase() {
ConnectionString cs = new ConnectionString("user:secret@localhost:8000/Documents", "connection string");
assertEquals("user:****@localhost:8000/Documents", cs.toString());
}

@Test
void hostTakesPrecedence() {
props.put(PREFIX + "host", "somehost");
Expand Down
Loading