01 import org.apache.cactus.FilterTestCase;
02 import org.apache.cactus.WebRequest;
03 import org.apache.cactus.client.authentication.*;
04
05 public class TestSecurityFilter extends FilterTestCase {
06
07 private SecurityFilter filter;
08 private MyFilterChain myChain;
09
10 public TestSecurityFilter(String name) {
11 super(name);
12 }
13
14 public void setUp() {
15 this.filter = new SecurityFilter();
16 this.myChain = new MyFilterChain();
17 }
18 // nastavíme BASIC autentifikáciu
19 public void beginAuthenticatedUser(WebRequest webRequest) {
20 webRequest.setRedirectorName("SecureFilterRedirector");
21 webRequest.setAuthentication(new BasicAuthentication("user","pwd"));
22 }
23 // otestujeme situáciu, keď klient je autentifikovaný
24 public void testAuthenticatedUser() throws Exception {
25 this.myChain.setExpectedInvocation(true);
26 this.filter.doFilter(this.request,this.response,this.myChain);
27 this.myChain.verify();
28 }
29 // otestujeme situáciu, keď klient nie je autentifikovaný
30 public void testNonAuthenticatedUser() throws Exception {
31 this.myChain.setExpectedInvocation(false);
32 this.filter.doFilter(this.request,this.response,this.myChain);
33 this.myChain.verify();
34 }
35 }
|