1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.skin

File EnvironmentSkinTest.java

 

Code metrics

0
11
3
1
86
49
3
0.27
3.67
3
1

Classes

Class Line # Actions
EnvironmentSkinTest 47 11 0% 3 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 com.xpn.xwiki.internal.skin;
21   
22    import java.net.URL;
23   
24    import javax.inject.Provider;
25   
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.slf4j.Logger;
30    import org.xwiki.environment.Environment;
31    import org.xwiki.skin.Resource;
32    import org.xwiki.skin.Skin;
33    import org.xwiki.test.AllLogRule;
34   
35    import com.xpn.xwiki.XWikiContext;
36   
37    import static org.junit.Assert.assertEquals;
38    import static org.junit.Assert.assertNull;
39    import static org.mockito.Mockito.mock;
40    import static org.mockito.Mockito.when;
41   
42    /**
43    * Unit tests for {@link EnvironmentSkin}.
44    *
45    * @version $Id: d5f706650bdb41578d029a1cade81a8ea1465606 $
46    */
 
47    public class EnvironmentSkinTest
48    {
49    @Rule
50    public AllLogRule allLogRule = new AllLogRule();
51   
52    private Skin skin;
53   
54    private Environment environment = mock(Environment.class);
55   
 
56  2 toggle @Before
57    public void setUp()
58    {
59  2 @SuppressWarnings("unchecked")
60    Provider<XWikiContext> xcontextProvider = mock(Provider.class);
61  2 XWikiContext xcontext = mock(XWikiContext.class);
62  2 when(xcontextProvider.get()).thenReturn(xcontext);
63   
64  2 this.skin = new EnvironmentSkin("test", mock(InternalSkinManager.class), mock(InternalSkinConfiguration.class),
65    mock(Logger.class), this.environment, xcontextProvider);
66    }
67   
 
68  1 toggle @Test
69    public void getLocalResource() throws Exception
70    {
71  1 String relativePath = "o;ne/t?w&o/../t=hr#e e";
72  1 String fullPath = "/skins/test/" + relativePath;
73  1 when(this.environment.getResource(fullPath)).thenReturn(new URL("http://resourceURL"));
74   
75  1 Resource<?> resource = skin.getLocalResource(relativePath);
76  1 assertEquals(fullPath, resource.getPath());
77    }
78   
 
79  1 toggle @Test
80    public void getLocalResourceWithBreakInAttempt() throws Exception
81    {
82  1 assertNull(skin.getLocalResource("one/../../two"));
83  1 assertEquals("Direct access to template file [/skins/two] refused. Possible break-in attempt!",
84    allLogRule.getMessage(0));
85    }
86    }