1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.csrf

File CSRFTokenInvalidatorTest.java

 

Code metrics

0
7
4
1
83
42
4
0.57
1.75
4
1

Classes

Class Line # Actions
CSRFTokenInvalidatorTest 44 7 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Tests for the {@link CSRFTokenInvalidator} component.
39    *
40    * @version $Id: 7bb4f43fd8a74defbef3f604a5fe9263d730f32f $
41    * @since 4.0M1
42    */
43    @MockingRequirement(CSRFTokenInvalidator.class)
 
44    public class CSRFTokenInvalidatorTest extends AbstractMockingComponentTestCase
45    {
46    /** Tested component. */
47    private EventListener invalidator;
48   
 
49  2 toggle @Before
50    public void configure() throws Exception
51    {
52  2 this.invalidator = getComponentManager().getInstance(EventListener.class, "csrf-token-invalidator");
53    }
54   
55    /**
56    * Test that the list of monitored events contains an ActionExecutingEvent for the /logout/ action.
57    */
 
58  1 toggle @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    * Tests that the token will get invalidated when a logout event occurs.
68    *
69    * @throws Exception
70    */
 
71  1 toggle @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    {
 
77  1 toggle {
78  1 one(mockCSRFTokenManager).clearToken();
79    }
80    });
81  1 this.invalidator.onEvent(new ActionExecutingEvent("logout"), null, null);
82    }
83    }