Skip to content

Commit

Permalink
Merge branch 'opensearch-project:main' into replace-bouncycastle-blake2b
Browse files Browse the repository at this point in the history
  • Loading branch information
terryquigleysas authored Apr 19, 2024
2 parents 8522d92 + b214255 commit 0a3f6c2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugin-security.policy
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ grant {
permission java.security.SecurityPermission "putProviderProperty.BC";
permission java.security.SecurityPermission "insertProvider.BC";
permission java.security.SecurityPermission "removeProviderProperty.BC";
permission java.security.SecurityPermission "getProperty.org.bouncycastle.ec.max_f2m_field_size";
permission java.security.SecurityPermission "getProperty.org.bouncycastle.pkcs12.default";
permission java.security.SecurityPermission "getProperty.org.bouncycastle.rsa.max_size";
permission java.security.SecurityPermission "getProperty.org.bouncycastle.rsa.max_mr_tests";
permission java.security.SecurityPermission "getProperty.org.bouncycastle.pkcs12.default";

permission java.lang.RuntimePermission "accessUserInformation";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
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.equalTo;
import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL;
import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS;
Expand Down Expand Up @@ -127,11 +129,13 @@ private void runResourceTest(
final var requests = AsyncActions.generate(() -> {
final HttpPost post = new HttpPost(client.getHttpServerUri() + requestPath);
post.setEntity(new ByteArrayEntity(compressedRequestBody, ContentType.APPLICATION_JSON));
return client.executeRequest(post);
TestRestClient.HttpResponse response = client.executeRequest(post);
return response.getStatusCode();
}, parrallelism, totalNumberOfRequests);

AsyncActions.getAll(requests, 2, TimeUnit.MINUTES)
.forEach((response) -> { response.assertStatusCode(HttpStatus.SC_UNAUTHORIZED); });
AsyncActions.getAll(requests, 2, TimeUnit.MINUTES).forEach((responseCode) -> {
assertThat(responseCode, equalTo(HttpStatus.SC_UNAUTHORIZED));
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ public void testBrowserShouldRequestForCredentials() {
}
}

@Test
public void shouldRespondWithChallengeWhenNoCredentialsArePresent() {
try (TestRestClient client = cluster.getRestClient()) {
HttpResponse response = client.getAuthInfo();

assertThat(response, is(notNullValue()));
response.assertStatusCode(SC_UNAUTHORIZED);
assertThat(response.getHeader("WWW-Authenticate"), is(notNullValue()));
assertThat(response.getHeader("WWW-Authenticate").getValue(), equalTo("Basic realm=\"OpenSearch Security\""));
assertThat(response.getBody(), equalTo("Unauthorized"));
}
}

@Test
public void testUserShouldNotHaveAssignedCustomAttributes() {
try (TestRestClient client = cluster.getRestClient(TEST_USER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public AuthCredentials extractCredentials(final SecurityRequest request, final T
@Override
public Optional<SecurityResponse> reRequestAuthentication(final SecurityRequest request, AuthCredentials creds) {
return Optional.of(
new SecurityResponse(HttpStatus.SC_UNAUTHORIZED, Map.of("WWW-Authenticate", "Basic realm=\"OpenSearch Security\""), "")
new SecurityResponse(
HttpStatus.SC_UNAUTHORIZED,
Map.of("WWW-Authenticate", "Basic realm=\"OpenSearch Security\""),
"Unauthorized"
)
);
}

Expand Down

0 comments on commit 0a3f6c2

Please sign in to comment.