Hi everyone, I work on the SpringMockUser extensio...
# kotest-contributors
r
Hi everyone, I work on the SpringMockUser extension (see here https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1730801202068429) and I was hoping somebody could tell me if my approach to testing the whole thing is correct. This is how I currently test:
Copy code
class SpringMockUserExtensionTest : FunSpec() {

   override fun extensions() = listOf(SpringExtension)

   init {
      test("should set user before any in Spring security context") {
         SpringMockUserExtension().beforeAny(
            TestCase(
               descriptor = SpringMockUserExtensionTest::class.toDescriptor().append("aaa"),
               name = TestName("name"),
               spec = this@SpringMockUserExtensionTest,
               test = {},
               source = sourceRef(),
               type = TestType.Test
            )
         )

         SecurityContextHolder.getContext().authentication shouldBeEqual UsernamePasswordAuthenticationToken("", "")
      }
Basically, within the test, I directly call the lifecycle functions and check my expectation. Is this the correct way to test my extension?
e
Hey Ronny, did you work something out?
r
Hey @Emil Kantis, actually yes. It wasn't as easy as I had hoped for, but it works. Since I had some problems finding the correct Spring, Spring Security and Spring Security Test versions I first wanted to update the versions to latest Spring: https://github.com/kotest/kotest-extensions-spring/pull/131 If you could merge this that would be great. Then I can follow with the PR for the mock user. The code is ready.
Ping @Emil Kantis
👍 1
e
I'm a bit unsure if this can create issues.. upgrading to latest versions of everything might break backwards compatibility. Ideally we want to use a version that is as old as possible while still supporting our use case.. I realize it might be a bit tedious to try to figure out exactly what version that would be, but perhaps you have some clue already?
r
Ok, I understand. I'll see what I can do
Sooo, I finally managed to get something working @Emil Kantis. The PR is open: https://github.com/kotest/kotest-extensions-spring/pull/132 I'm well aware that some adjustments might be needed. Feel free to suggest any changes.
Any feedback @Emil Kantis?
e
Will have a look today 🤞
Looking good. I sent an approval and some optional feedback 🙂
👍 1