package swsec;

import net.sourceforge.jwebunit.junit.WebTester;
import org.junit.Before;
import org.junit.Test;

public class AttackITest {

	private WebTester tester;

	@Before
	public void prepare() {
		tester = new WebTester();
		tester.setBaseUrl("http://127.0.0.1:8080/");
	}

	private void sqlInjection(String hackcode) {
		tester.beginAt("login.jsp");
		tester.setTextField("username", "hackerMalo");
		tester.setTextField("password", hackcode);
		tester.submit();
		tester.assertTextPresent("Usuario: " + "hackerMalo");
		tester.clickLink("exit");
	}

	@Test
	public void sqlInjection1() {
		sqlInjection("' or 1=1;-- ");
	}

	@Test
	public void sqlInjection2() {
		sqlInjection("' or '1'='1");
	}
}

@@ -57,16 +57,41 @@
 bTester;
+%0A%0Aimport org.junit.After;
 %0Aimport 
@@ -551,36 +551,8 @@
 %22);%0A
-%09%09tester.clickLink(%22exit%22);%0A
 %09%7D%0A%0A
@@ -696,11 +696,74 @@
 '1%22);%0A%09%7D
+%0A%0A%09@After%0A%09public void close() %7B%0A%09%09tester.clickLink(%22exit%22);%0A%09%7D
 %0A%7D%0A

Test improvements