1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.csrf; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
|
26 |
|
import org.jmock.Expectations; |
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.bridge.event.ActionExecutingEvent; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.csrf.internal.CSRFTokenInvalidator; |
32 |
|
import org.xwiki.observation.EventListener; |
33 |
|
import org.xwiki.observation.event.Event; |
34 |
|
import org.xwiki.test.jmock.AbstractMockingComponentTestCase; |
35 |
|
import org.xwiki.test.jmock.annotation.MockingRequirement; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@MockingRequirement(CSRFTokenInvalidator.class) |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
44 |
|
public class CSRFTokenInvalidatorTest extends AbstractMockingComponentTestCase |
45 |
|
{ |
46 |
|
|
47 |
|
private EventListener invalidator; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
2 |
@Before... |
50 |
|
public void configure() throws Exception |
51 |
|
{ |
52 |
2 |
this.invalidator = getComponentManager().getInstance(EventListener.class, "csrf-token-invalidator"); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
public void testEvents() |
60 |
|
{ |
61 |
1 |
List<Event> events = this.invalidator.getEvents(); |
62 |
1 |
Assert.assertTrue("Invalidator doesn't listen to /logout/ events", |
63 |
|
events.contains(new ActionExecutingEvent("logout"))); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@throws |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testInvalidationOnLogout() throws ComponentLookupException, Exception |
73 |
|
{ |
74 |
1 |
final CSRFToken mockCSRFTokenManager = getComponentManager().getInstance(CSRFToken.class); |
75 |
1 |
getMockery().checking(new Expectations() |
76 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
1 |
{... |
78 |
1 |
one(mockCSRFTokenManager).clearToken(); |
79 |
|
} |
80 |
|
}); |
81 |
1 |
this.invalidator.onEvent(new ActionExecutingEvent("logout"), null, null); |
82 |
|
} |
83 |
|
} |