In the post Read the Error Message - Problem Solving Skills, we mentioned that the first step of troubleshooting is to read and understand the error message.
During reading the error message/log, it's important to keep alert of unusual things/messages and guess possible causes.
Scenario 1 - In Memory Test User not work in Rest-Assured
After developed the feature Spring Security: Integrate In-Memory Authentication for Test Automation, another developer is using it to write automation test - using Rest-Assured and reusing the session filter.
I was told that it didn't work and asked to help troubleshoot it.
First step: reproduce the problem
If we run the code that uses rest assured with the test user and session filter, it failed.
But I can use the test user to login admin ui in the browser. - This is weird, I should pay more attention to this unusual thing and think about possible causes, but I didn't at that time.
Then I found the following message in the log:
-- This is wired, as I am using the test user - spring should use the in-memory DaoAuthenticationProvider to verify it; it should only call ActiveDirectoryLdapAuthenticationProvider if it's not the in-memory user.
INFO 144038 [http-nio-0.0.0.0-8080-exec-10] org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider - Active Directory authentication failed: Supplied password was invalid
Now I check the code more carefully and found out that it uses wrong username: uses 'admin-123' instead of 'admin_123'. admin-123 is not in-memory user, so it calls ActiveDirectoryLdapAuthenticationProvider for authentication and it failed obviously.
Actually if I read rest-assured logs more carefully, I should have found the root cause early.
00:05:05.553 [main] DEBUG org.apache.http.headers - >> POST /xapp/j_spring_security_check HTTP/1.1
00:05:24.564 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 302 Found[\r][\n]"
00:05:24.568 [main] DEBUG org.apache.http.wire - << "Set-Cookie: JSESSIONID=9C03D491F56D6CDC007FA931898F5504; Path=/xapp/; HttpOnly[\r][\n]"
00:05:24.568 [main] DEBUG org.apache.http.wire - << "Location: http://localhost:8080/xapp/loginerror;jsessionid=9C03D491F56D6CDC007FA931898F5504[\r][\n]"
During reading the error message/log, it's important to keep alert of unusual things/messages and guess possible causes.
Scenario 1 - In Memory Test User not work in Rest-Assured
After developed the feature Spring Security: Integrate In-Memory Authentication for Test Automation, another developer is using it to write automation test - using Rest-Assured and reusing the session filter.
I was told that it didn't work and asked to help troubleshoot it.
First step: reproduce the problem
If we run the code that uses rest assured with the test user and session filter, it failed.
But I can use the test user to login admin ui in the browser. - This is weird, I should pay more attention to this unusual thing and think about possible causes, but I didn't at that time.
Then I found the following message in the log:
-- This is wired, as I am using the test user - spring should use the in-memory DaoAuthenticationProvider to verify it; it should only call ActiveDirectoryLdapAuthenticationProvider if it's not the in-memory user.
INFO 144038 [http-nio-0.0.0.0-8080-exec-10] org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider - Active Directory authentication failed: Supplied password was invalid
Actually if I read rest-assured logs more carefully, I should have found the root cause early.
00:05:05.553 [main] DEBUG org.apache.http.headers - >> POST /xapp/j_spring_security_check HTTP/1.1
00:05:24.564 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 302 Found[\r][\n]"
00:05:24.568 [main] DEBUG org.apache.http.wire - << "Set-Cookie: JSESSIONID=9C03D491F56D6CDC007FA931898F5504; Path=/xapp/; HttpOnly[\r][\n]"
00:05:24.568 [main] DEBUG org.apache.http.wire - << "Location: http://localhost:8080/xapp/loginerror;jsessionid=9C03D491F56D6CDC007FA931898F5504[\r][\n]"