All Questions
38
questions
0
votes
1
answer
1k
views
How to write Integration Test with the usage of Bearer Token in Spring Boot (throw An Authentication object was not found in the SecurityContext)
I have a problem to write Integration Test in my Spring Boot example.
In my UserController class, every methods are defined with @PreAuthorize with roles.
Here is my code snippets shown below
Here is ...
0
votes
0
answers
381
views
Junit tests run locally (commandline+maven) but not on jenkins; Failed to load ApplicationContext IllegalArgumentException: InputStream cannot be null
I am working on an app and in parallel we set up the ci/cd environment. The app has 3 basic junit tests at the moment.
coordinates: java 17, spring boot2, h2 db, saml, vaadin, maven 3.9.1, jenkins was ...
0
votes
2
answers
801
views
How to implement login service test based on Spring Security in Spring Boot?
I have a problem implementing login service test based on Spring Security in Spring Boot. I tried to implement login method in AuthService and then wrote its service method but I got the issue.
Here ...
0
votes
0
answers
87
views
How to implement Spring Security in integration test through JUnit in Spring Boot
Here is the register method of AuthController shown below
public ResponseEntity<AuthResponse> register(@RequestBody RegisterRequest registerRequest) {
var registeredUser = authService....
0
votes
1
answer
2k
views
Spring Integration Test -> Security throws 403 Forbidden even if it is defined to allow in SecurityChain
I have a problem to test register through Integration Test in Spring Boot.
I use Spring Boot 3.
Here is the SecurityFilterChain bean defined in Security Config
@Bean
public SecurityFilterChain ...
0
votes
1
answer
467
views
How can I mock Spring Security in JUnit
I have a problem to mock some parts regarding Spring Security in JUnit.
I tried to write a service test regarding user registration but I couldn't handle with mock part.
Here is the relevant part in ...
2
votes
2
answers
1k
views
Spring Boot Microservices - Spring Security - ServiceTest and ControllerTest for JUnit throwing java.lang.StackOverflowError
I have a problem in running any test method in service test and controller test in one of the spring boot microservices (order service).
After I completed service and controller , I tried to write ...
0
votes
0
answers
719
views
Spring Boot Microservices (Spring Cloud) , 403 Forbidden among services (Controller and ControllerTest)
I have a communication problem in my spring boot microservices.
I created some services as well as eureka server, api gateway and config server.
I defined auth service connecting to api gateway for ...
1
vote
2
answers
798
views
Spring Boot Microservice JUnit Test - How to write a test method with adding the option of @PreAuthorize
I just want to add a @PreAuthorize("hasAuthority('ROLE_ADMIN')") and @PreAuthorize("hasAuthority('ROLE_USER')") in the methods of order controller and I also revise the controller ...
1
vote
1
answer
1k
views
How to mock spring security cookies session in spring boot unit Test?
I have added Http cookie Authentication using authentication manager to my Spring Boot REST API
I have a controller that exposes a rest service allowing authentication to /api/auth/signin resource via ...
0
votes
1
answer
309
views
JUnit Security Test Error for Service Test of Spring Boot
I have to write a test function for findInContextUser based on JUnit Mock in Spring Boot but I have no idea how to write it.
How can I write findInContextUser for Junit Test?
Here are my code defined ...
-1
votes
1
answer
217
views
Spring boot Junit with spring security Authentication
Below is my code for junit test
MvcResult mvcResult = (MvcResult) mvc.perform(MockMvcRequestBuilders.put(uri).headers(headers)
.contentType(MediaType.APPLICATION_JSON).content(json))....
0
votes
0
answers
550
views
Springboot Unit Tesiting with Jwt spring security
I am a Newbie to Unit Testing/ Integration Testing
I am getting some errors while testing the rest api which is secured with Jwt Token authentication by spring security.
userControllerTest
@ExtendWith(...
0
votes
1
answer
2k
views
Mock JwtDecoder in Spring Security
This is the code in my service class method to get the JWT token based on the auth token passed.
NimbusJwtDecoder decoder = (NimbusJwtDecoder) JwtDecoders.fromOidcIssuerLocation(userTokenUrl);
...
1
vote
0
answers
831
views
Getting error in unit tests after implement Spring Security to project
I'm creating a project with Spring Boot and Spring Data Rest. I create unit tests for endpoints and after run everything pass. Then I implement Spring Security to my project: configuration, implement ...