Skip to content

Commit

Permalink
Add tests for SystemSubject
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Sep 19, 2024
1 parent 4f4d758 commit 6702707
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

package org.opensearch.identity;

import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.threadpool.TestThreadPool;
import org.opensearch.threadpool.ThreadPool;

public class SystemSubjectTests extends OpenSearchTestCase {
public void testSystemSubject() {
ThreadPool threadPool = new TestThreadPool(getTestName());
SystemSubject systemSubject = SystemSubject.getInstance();
assertEquals("system", systemSubject.getPrincipal().getName());
systemSubject.initialize(threadPool);
assertFalse(threadPool.getThreadContext().isSystemContext());
systemSubject.runAs(() -> {
assertTrue(threadPool.getThreadContext().isSystemContext());
return false;
});
terminate(threadPool);
}
}

0 comments on commit 6702707

Please sign in to comment.