-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add password message to /dashboardsinfo endpoint Signed-off-by: Craig Perkins <[email protected]> * Update test names Signed-off-by: Craig Perkins <[email protected]> --------- Signed-off-by: Craig Perkins <[email protected]> (cherry picked from commit 47c4feb) Co-authored-by: Craig Perkins <[email protected]>
- Loading branch information
1 parent
b33e99f
commit 6d385f0
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/integrationTest/java/org/opensearch/security/api/DashboardsInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.api; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.apache.hc.core5.http.HttpStatus; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.TestSecurityConfig.Role; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
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.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
|
||
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class DashboardsInfoTest { | ||
|
||
protected final static TestSecurityConfig.User DASHBOARDS_USER = new TestSecurityConfig.User("dashboards_user").roles( | ||
new Role("dashboards_role").indexPermissions("read").on("*").clusterPermissions("cluster_composite_ops") | ||
); | ||
|
||
@ClassRule | ||
public static LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL) | ||
.users(DASHBOARDS_USER) | ||
.build(); | ||
|
||
@Test | ||
public void testDashboardsInfoValidationMessage() throws Exception { | ||
|
||
try (TestRestClient client = cluster.getRestClient(DASHBOARDS_USER)) { | ||
TestRestClient.HttpResponse response = client.get("_plugins/_security/dashboardsinfo"); | ||
assertThat(response.getStatusCode(), equalTo(HttpStatus.SC_OK)); | ||
assertThat(response.getBody(), containsString("password_validation_error_message")); | ||
assertThat(response.getBody(), containsString(DEFAULT_PASSWORD_MESSAGE)); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/integrationTest/java/org/opensearch/security/api/DashboardsInfoWithSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.api; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.apache.hc.core5.http.HttpStatus; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.opensearch.security.support.ConfigConstants; | ||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.TestSecurityConfig.Role; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
|
||
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class DashboardsInfoWithSettingsTest { | ||
|
||
protected final static TestSecurityConfig.User DASHBOARDS_USER = new TestSecurityConfig.User("dashboards_user").roles( | ||
new Role("dashboards_role").indexPermissions("read").on("*").clusterPermissions("cluster_composite_ops") | ||
); | ||
|
||
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."; | ||
|
||
@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,}", | ||
ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, | ||
CUSTOM_PASSWORD_MESSAGE | ||
) | ||
) | ||
.build(); | ||
|
||
@Test | ||
public void testDashboardsInfoValidationMessageWithCustomMessage() throws Exception { | ||
|
||
try (TestRestClient client = cluster.getRestClient(DASHBOARDS_USER)) { | ||
TestRestClient.HttpResponse response = client.get("_plugins/_security/dashboardsinfo"); | ||
assertThat(response.getStatusCode(), equalTo(HttpStatus.SC_OK)); | ||
assertThat(response.getBody(), containsString("password_validation_error_message")); | ||
assertThat(response.getBody(), containsString(CUSTOM_PASSWORD_MESSAGE)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters