File tree 3 files changed +16
-6
lines changed
spring-boot-sample-web-method-security/src/main/resources/templates
spring-boot-sample-web-secure/src
test/java/sample/ui/secure
3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 20
20
< p th:if ="${param.logout} " class ="alert "> You have been logged out</ p >
21
21
< p th:if ="${param.error} " class ="alert alert-error "> There was an error, please try again</ p >
22
22
< h2 > Login with Username and Password</ h2 >
23
- < form name ="form " action ="/login " method ="POST ">
23
+ < form name ="form " th:action =" @{/login} " action ="/login " method ="POST ">
24
24
< fieldset >
25
25
< input type ="text " name ="username " value ="" placeholder ="Username " />
26
26
< input type ="password " name ="password " placeholder ="Password " />
27
27
</ fieldset >
28
28
< input type ="submit " id ="login " value ="Login "
29
- class ="btn btn-primary " /> < input type ="hidden "
30
- th:name ="${_csrf.parameterName} " th:value ="${_csrf.token} " />
29
+ class ="btn btn-primary " />
31
30
</ form >
32
31
</ div >
33
32
</ div >
Original file line number Diff line number Diff line change 20
20
< p th:if ="${param.logout} " class ="alert "> You have been logged out</ p >
21
21
< p th:if ="${param.error} " class ="alert alert-error "> There was an error, please try again</ p >
22
22
< h2 > Login with Username and Password</ h2 >
23
- < form name ="form " action ="/login " method ="POST ">
23
+ < form name ="form " th:action =" @{/login} " action ="/login " method ="POST ">
24
24
< fieldset >
25
25
< input type ="text " name ="username " value ="" placeholder ="Username " />
26
26
< input type ="password " name ="password " placeholder ="Password " />
27
27
</ fieldset >
28
28
< input type ="submit " id ="login " value ="Login "
29
- class ="btn btn-primary " /> < input type ="hidden "
30
- th:name ="${_csrf.parameterName} " th:value ="${_csrf.token} "/>
29
+ class ="btn btn-primary " />
31
30
</ form >
32
31
</ div >
33
32
</ div >
Original file line number Diff line number Diff line change @@ -69,6 +69,18 @@ public void testHome() throws Exception {
69
69
entity .getHeaders ().getLocation ().toString ().endsWith (port + "/login" ));
70
70
}
71
71
72
+ @ Test
73
+ public void testLoginPage () throws Exception {
74
+ HttpHeaders headers = new HttpHeaders ();
75
+ headers .setAccept (Arrays .asList (MediaType .TEXT_HTML ));
76
+ ResponseEntity <String > entity = new TestRestTemplate ().exchange (
77
+ "http://localhost:" + this .port + "/login" , HttpMethod .GET , new HttpEntity <Void >(
78
+ headers ), String .class );
79
+ assertEquals (HttpStatus .OK , entity .getStatusCode ());
80
+ assertTrue ("Wrong content:\n " + entity .getBody (),
81
+ entity .getBody ().contains ("_csrf" ));
82
+ }
83
+
72
84
@ Test
73
85
public void testLogin () throws Exception {
74
86
HttpHeaders headers = getHeaders ();
You can’t perform that action at this time.
0 commit comments