-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Derive security context information when security plugin fails to pop…
…ulate user info (#204) Signed-off-by: Sai Kumar <[email protected]>
- Loading branch information
1 parent
d44efe7
commit a9d9c6f
Showing
2 changed files
with
48 additions
and
1 deletion.
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
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/org/opensearch/replication/util/SecurityContextTests.kt
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,40 @@ | ||
package org.opensearch.replication.util | ||
|
||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.opensearch.common.settings.Settings | ||
import org.opensearch.common.util.concurrent.ThreadContext | ||
import org.opensearch.commons.authuser.User | ||
import org.opensearch.test.OpenSearchTestCase | ||
|
||
class SecurityContextTests: OpenSearchTestCase() { | ||
|
||
companion object { | ||
var threadContext: ThreadContext? = null | ||
} | ||
|
||
@Before | ||
fun setupContext() { | ||
threadContext = ThreadContext(Settings.EMPTY) | ||
} | ||
|
||
fun `test security context from ThreadContext with user Info`() { | ||
threadContext!!.putTransient("_opendistro_security_user_info", "admin||all_access") | ||
val expectedUser = User("admin", emptyList<String>(), listOf("all_access"), emptyList<String>()) | ||
val returnedUser = SecurityContext.fromSecurityThreadContext(threadContext!!) | ||
Assert.assertEquals(expectedUser, returnedUser) | ||
} | ||
|
||
fun `test security context from ThreadContext with user Info not present and user obj present`() { | ||
threadContext!!.putTransient("_opendistro_security_user_info", null) | ||
threadContext!!.putTransient("_opendistro_security_user", "") | ||
val expectedUser = User("adminDN", emptyList<String>(), emptyList<String>(), emptyList<String>()) | ||
val returnedUser = SecurityContext.fromSecurityThreadContext(threadContext!!) | ||
Assert.assertEquals(expectedUser, returnedUser) | ||
} | ||
|
||
fun `test security context from ThreadContext with user Info and user obj not present`() { | ||
val returnedUser = SecurityContext.fromSecurityThreadContext(threadContext!!) | ||
Assert.assertNull(returnedUser) | ||
} | ||
} |