-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeficiencyReport_191.java
60 lines (51 loc) · 2.17 KB
/
DeficiencyReport_191.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package unitn.sectest;
import net.sourceforge.jwebunit.api.IElement;
import net.sourceforge.jwebunit.htmlunit.HtmlUnitElementImpl;
import net.sourceforge.jwebunit.junit.WebTester;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.helpers.AttributesImpl;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.InputElementFactory;
public class DeficiencyReport_191 {
private WebTester tester;
@Before
public void prepare(){
tester = new WebTester();
tester.setBaseUrl("http://localhost/schoolmate");
tester.beginAt("/index.php");
tester.setTextField("username", "schoolmate");
tester.setTextField("password", "schoolmate");
tester.submit();
tester.assertTitleEquals("SchoolMate - School Name");
tester.clickLinkWithText("Students");
tester.assertMatch("Manage Students");
}
@Test
public void page(){
tester.setWorkingForm("students");
tester.setTextField("page", "1'> <a href =http://unitn.it>malicious link</a> <br'");
tester.selectOption("report", "Deficiency Report");
tester.assertMatch("Deficiency Report");
tester.assertLinkNotPresentWithText("malicious link");
}
@Test
public void page2(){
tester.setWorkingForm("students");
tester.setTextField("page2", "27'> <a href =http://unitn.it>malicious link</a> <br'");
addSubmitButton("//form[@name='students']");
tester.submit();
tester.assertMatch("Deficiency Report");
tester.assertLinkNotPresentWithText("malicious link");
}
private void addSubmitButton(String fromXpath){
IElement element = tester.getElementByXPath(fromXpath);
DomElement form= ((HtmlUnitElementImpl)element).getHtmlElement();
InputElementFactory factory = InputElementFactory.instance;
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "", "type", "", "submit");
HtmlElement submit = factory.createElement(form.getPage(), "input", attributes);
form.appendChild(submit);
}
}