forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prabhas Kurapati <prabhask@berkeley.edu>
- Loading branch information
Showing
4 changed files
with
77 additions
and
63 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
src/integrationTest/java/org/opensearch/security/api/FlushCacheApiIntegrationTest.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,57 @@ | ||
/* | ||
* 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 org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class FlushCacheApiIntegrationTest extends AbstractApiIntegrationTest { | ||
private final static String TEST_USER = "testuser"; | ||
|
||
private String cachePath() { | ||
return super.apiPath("cache"); | ||
} | ||
|
||
private String cachePath(String user) { | ||
return super.apiPath("cache", "user", user); | ||
} | ||
|
||
@Test | ||
public void testFlushCache() throws Exception { | ||
withUser(NEW_USER, client -> { | ||
forbidden(() -> client.get(cachePath())); | ||
forbidden(() -> client.postJson(cachePath(), EMPTY_BODY)); | ||
forbidden(() -> client.putJson(cachePath(), EMPTY_BODY)); | ||
forbidden(() -> client.delete(cachePath())); | ||
forbidden(() -> client.delete(cachePath(TEST_USER))); | ||
}); | ||
withUser(ADMIN_USER_NAME, localCluster.getAdminCertificate(), client -> { | ||
notImplemented(() -> client.get(cachePath())); | ||
notImplemented(() -> client.postJson(cachePath(), EMPTY_BODY)); | ||
notImplemented(() -> client.putJson(cachePath(), EMPTY_BODY)); | ||
final var deleteAllCacheResponse = ok(() -> client.delete(cachePath())); | ||
assertThat( | ||
deleteAllCacheResponse.getBody(), | ||
deleteAllCacheResponse.getTextFromJsonBody("/message"), | ||
is("Cache flushed successfully.") | ||
); | ||
final var deleteUserCacheResponse = ok(() -> client.delete(cachePath(TEST_USER))); | ||
assertThat( | ||
deleteUserCacheResponse.getBody(), | ||
deleteAllCacheResponse.getTextFromJsonBody("/message"), | ||
is("Cache invalidated for user: " + TEST_USER) | ||
); | ||
}); | ||
} | ||
} |
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
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