1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.27 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
55 |
2 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
68 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
79 |
1 |
@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 |
|
} |