-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParentViewStudents_90.java
59 lines (48 loc) · 2 KB
/
ParentViewStudents_90.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
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 ParentViewStudents_90 {
private WebTester tester;
@Before
public void setup(){
tester = new WebTester();
tester.setBaseUrl("http://localhost/schoolmate");
tester.beginAt("index.php");
tester.setTextField("username", "Mother");
tester.setTextField("password", "Mother");
tester.submit();
tester.assertMatch("Students of Nicoletta Riso");
tester.clickLinkWithText("Students");
}
@Test
public void page(){
tester.setWorkingForm("student");
tester.setTextField("page", "5'> <a href =http://unitn.it>malicious link</a> <br'");
tester.clickLinkWithExactText("Students");
tester.assertLinkNotPresentWithText("malicious link");
}
@Test
public void page2(){
tester.setWorkingForm("student");
tester.setTextField("page2", "0'> <a href =http://unitn.it>malicious link</a> <br'");
addSubmitButton("//form[@name='student']");
tester.submit();
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);
}
}