Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include password regex for Dashboardsinfo to display to users #2999

Merged
merged 3 commits into from
Jul 18, 2023
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
Expand Up @@ -27,6 +27,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.opensearch.security.rest.DashboardsInfoAction.DEFAULT_PASSWORD_MESSAGE;
import static org.opensearch.security.rest.DashboardsInfoAction.DEFAULT_PASSWORD_REGEX;
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL;

@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
Expand All @@ -51,6 +52,8 @@ public void testDashboardsInfoValidationMessage() throws Exception {
assertThat(response.getStatusCode(), equalTo(HttpStatus.SC_OK));
assertThat(response.getBody(), containsString("password_validation_error_message"));
assertThat(response.getBody(), containsString(DEFAULT_PASSWORD_MESSAGE));
assertThat(response.getBody(), containsString("password_validation_regex"));
assertThat(response.getBody(), containsString(DEFAULT_PASSWORD_REGEX));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ public class DashboardsInfoWithSettingsTest {
private static final String CUSTOM_PASSWORD_MESSAGE =
"Password must be minimum 5 characters long and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.";

private static final String CUSTOM_PASSWORD_REGEX = "(?=.*[A-Z])(?=.*[^a-zA-Z\\d])(?=.*[0-9])(?=.*[a-z]).{5,}";

@ClassRule
public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS)
.authc(AUTHC_HTTPBASIC_INTERNAL)
.users(DASHBOARDS_USER)
.nodeSettings(
Map.of(
ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX,
"(?=.*[A-Z])(?=.*[^a-zA-Z\\d])(?=.*[0-9])(?=.*[a-z]).{5,}",
CUSTOM_PASSWORD_REGEX,
ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE,
CUSTOM_PASSWORD_MESSAGE
)
Expand All @@ -63,6 +65,8 @@ public void testDashboardsInfoValidationMessageWithCustomMessage() throws Except
assertThat(response.getStatusCode(), equalTo(HttpStatus.SC_OK));
assertThat(response.getBody(), containsString("password_validation_error_message"));
assertThat(response.getBody(), containsString(CUSTOM_PASSWORD_MESSAGE));
assertThat(response.getBody(), containsString("password_validation_regex"));
assertThat(response.getBody(), containsString(CUSTOM_PASSWORD_REGEX));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
public static final String DEFAULT_PASSWORD_MESSAGE = "Password should be at least 8 characters long and contain at least one "
+ "uppercase letter, one lowercase letter, one digit, and one special character.";

public static final String DEFAULT_PASSWORD_REGEX = "(?=.*[A-Z])(?=.*[^a-zA-Z\\d])(?=.*[0-9])(?=.*[a-z]).{8,}";

public DashboardsInfoAction(
final Settings settings,
final RestController controller,
Expand Down Expand Up @@ -110,6 +112,10 @@
"password_validation_error_message",
client.settings().get(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, DEFAULT_PASSWORD_MESSAGE)
);
builder.field(

Check warning on line 115 in src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java#L115

Added line #L115 was not covered by tests
"password_validation_regex",
client.settings().get(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, DEFAULT_PASSWORD_REGEX)

Check warning on line 117 in src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/security/rest/DashboardsInfoAction.java#L117

Added line #L117 was not covered by tests
);
builder.endObject();

response = new BytesRestResponse(RestStatus.OK, builder);
Expand Down
Loading