-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add SpringMockUserExtension to fake users #132
base: master
Are you sure you want to change the base?
Conversation
Hi everyone, I finally managed a working extension for the Spring mock user. |
Compatible with Spring 2 and Spring security 5.
80347a0
to
184322b
Compare
@SpringBootTest(classes = [SpringTestApplication::class]) | ||
@AutoConfigureWebTestClient | ||
class SpringMockUserExtensionIntegrationTest( | ||
@Autowired private val webTestClient: WebTestClient, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Autowired private val webTestClient: WebTestClient, | |
private val webTestClient: WebTestClient, |
Just a small FYI. The Kotest SpringAutowireConstructorExtension actually doesn't care for @Autowired
annotations, so they can be omitted :)
TestCase( | ||
descriptor = SpringMockUserExtensionTest::class.toDescriptor().append("aaa"), | ||
name = TestName("name"), | ||
spec = this@SpringMockUserExtensionTest, | ||
test = {}, | ||
source = sourceRef(), | ||
type = TestType.Test | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could perhaps be extracted, seems to be used in every test w/o any relevant differences?
init { | ||
describe("ADMIN") { | ||
extensions(SpringMockUserExtension(authorities = listOf("ADMIN"))) | ||
it("should provide mock authentication") { | ||
webTestClient | ||
.get() | ||
.uri("/secure") | ||
.exchange() | ||
.expectStatus() | ||
.isOk | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see an integration test 💯
private val username: String = "user", | ||
private val password: String = "password", | ||
private val roles: List<String> = listOf("USER"), | ||
private val authorities: List<String> = listOf() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these defaults used by Spring's own @WithMockUser
as well?
Compatible with Spring 2 and Spring security 5.