1. Project Clover database Tue Dec 20 2016 21:24:09 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 46 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.rendering.syntax.SyntaxFactory;
32    import org.xwiki.skin.Resource;
33    import org.xwiki.skin.Skin;
34    import org.xwiki.test.AllLogRule;
35   
36    import com.xpn.xwiki.XWikiContext;
37   
38    import static org.junit.Assert.*;
39    import static org.mockito.Mockito.*;
40   
41    /**
42    * Unit tests for {@link EnvironmentSkin}.
43    *
44    * @version $Id: f484bc8ad6601f678920c7653441bfc4f40227c5 $
45    */
 
46    public class EnvironmentSkinTest
47    {
48    @Rule
49    public AllLogRule allLogRule = new AllLogRule();
50   
51    private Skin skin;
52   
53    private Environment environment = mock(Environment.class);
54   
 
55  2 toggle @Before
56    public void setUp()
57    {
58  2 @SuppressWarnings("unchecked")
59    Provider<XWikiContext> xcontextProvider = mock(Provider.class);
60  2 XWikiContext xcontext = mock(XWikiContext.class);
61  2 when(xcontextProvider.get()).thenReturn(xcontext);
62   
63  2 this.skin =
64    new EnvironmentSkin("test", mock(InternalSkinManager.class), mock(InternalSkinConfiguration.class),
65    mock(Logger.class), mock(SyntaxFactory.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    }