add more test
This commit is contained in:
parent
e92843493f
commit
4e4d11574a
@ -1,20 +1,29 @@
|
|||||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||||
pageEncoding="ISO-8859-1"%>
|
pageEncoding="ISO-8859-1"%>
|
||||||
<%@ taglib prefix="security"
|
<%@ taglib prefix="sec"
|
||||||
uri="http://www.springframework.org/security/tags" %>
|
uri="http://www.springframework.org/security/tags"%>
|
||||||
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||||
|
<sec:csrfMetaTags />
|
||||||
<title>Home Page</title>
|
<title>Home Page</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<security:authorize access="isAuthenticated()">
|
<sec:authorize access="isAuthenticated()">
|
||||||
AUTHENTICATED
|
AUTHENTICATED
|
||||||
</security:authorize>
|
</sec:authorize>
|
||||||
<security:authorize access="hasRole('ADMIN')">
|
<sec:authorize access="hasRole('ADMIN')">
|
||||||
ADMIN ROLE
|
ADMIN ROLE
|
||||||
</security:authorize>
|
</sec:authorize>
|
||||||
|
|
||||||
|
<h2>principal.username: <sec:authentication property="principal.username" /> </h2>
|
||||||
|
|
||||||
|
<form method="post" action="/do/something">
|
||||||
|
<sec:csrfInput />
|
||||||
|
Text Field:<br /> <input type="text" name="textField" />
|
||||||
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -19,9 +19,24 @@ public class HomeControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void home() throws Exception {
|
public void home() throws Exception {
|
||||||
String body = this.restTemplate.withBasicAuth("ADMIN", SecurityConfig.DEFAULT_PASSWORD).getForEntity("/", String.class).getBody();
|
String body = this.restTemplate.withBasicAuth("ADMIN", SecurityConfig.DEFAULT_PASSWORD)
|
||||||
|
.getForEntity("/", String.class)
|
||||||
|
.getBody();
|
||||||
System.out.println(body);
|
System.out.println(body);
|
||||||
|
|
||||||
|
// test <sec:authorize access="isAuthenticated()">
|
||||||
assertTrue(body.contains("AUTHENTICATED"));
|
assertTrue(body.contains("AUTHENTICATED"));
|
||||||
|
|
||||||
|
// test <sec:authorize access="hasRole('ADMIN')">
|
||||||
assertTrue(body.contains("ADMIN ROLE"));
|
assertTrue(body.contains("ADMIN ROLE"));
|
||||||
|
|
||||||
|
// test <sec:authentication property="principal.username" />
|
||||||
|
assertTrue(body.contains("principal.username: ADMIN"));
|
||||||
|
|
||||||
|
// test <sec:csrfInput />
|
||||||
|
assertTrue(body.contains("<input type=\"hidden\" name=\"_csrf\" value=\""));
|
||||||
|
|
||||||
|
// test <sec:csrfMetaTags />
|
||||||
|
assertTrue(body.contains("<meta name=\"_csrf_parameter\" content=\"_csrf\" />"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user