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

File UsersAndGroupsTest.java

 

Code metrics

0
22
7
1
140
81
7
0.32
3.14
7
1

Classes

Class Line # Actions
UsersAndGroupsTest 38 22 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 5 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.test.escaping;
21   
22    import java.util.Map;
23   
24    import org.junit.AfterClass;
25    import org.junit.BeforeClass;
26    import org.junit.Test;
27    import org.xwiki.test.escaping.framework.AbstractEscapingTest;
28    import org.xwiki.test.escaping.framework.AbstractManualTest;
29    import org.xwiki.test.escaping.framework.XMLEscapingValidator;
30   
31   
32    /**
33    * Manual tests for user and group name escaping. Creates a test group and user for the test run.
34    *
35    * @version $Id: ccde1e3ef194c10e4cecea773bd8bfd26b4f9506 $
36    * @since 2.5M1
37    */
 
38    public class UsersAndGroupsTest extends AbstractManualTest
39    {
40    /** Name of the test user. */
41    private static final String TEST_USER = "User" + XMLEscapingValidator.getTestString();
42   
43    /** Name of the test group. */
44    private static final String TEST_GROUP = "Group" + XMLEscapingValidator.getTestString();
45   
46    /**
47    * Set up the tests. Creates a test group and adds a test user to that group.
48    * @throws InterruptedException
49    */
 
50  1 toggle @BeforeClass
51    public static void init() throws InterruptedException
52    {
53    // create a test group
54  1 AbstractEscapingTest.getUrlContent(createUrl("save", "XWiki", TEST_GROUP,
55    params(kv("template", "XWiki.XWikiGroupTemplate"))));
56    // create a test user
57  1 AbstractEscapingTest.getUrlContent(createUrl("register", "XWiki", "XWikiPreferences",
58    params(template("registerinline"), kv("xwikiname", "TEST_USER"),
59    test("register_first_name"), test("register_last_name"), kv("register_email", ""),
60    test("register_password"), test("register2_password"),
61    kv("template", "XWiki.XWikiUserTemplate"), kv("xredirect", ""))));
62    // create an even more evil user by renaming the user page
63  1 AbstractEscapingTest.getUrlContent(createUrl("view", "XWiki", "TEST_USER",
64    params(template("rename"), kv("step", "2"), kv("newSpaceName", "XWiki"), kv("newPageName", TEST_USER))));
65    // add the test user to the test group
66  1 AbstractEscapingTest.getUrlContent(createUrl("view", "XWiki", TEST_GROUP,
67    params(template("adduorg"), kv("uorg", "user"), kv("name", "XWiki." + TEST_USER))));
68    }
69   
70    /**
71    * Clean up after the tests.
72    */
 
73  1 toggle @AfterClass
74    public static void shutdown()
75    {
76    // remove the test user from the test group
77  1 AbstractEscapingTest.getUrlContent(createUrl("view", "XWiki", TEST_GROUP,
78    params(template("deletegroupmember"), kv("fullname", "XWiki." + TEST_USER))));
79    // delete the test user
80  1 AbstractEscapingTest.getUrlContent(createUrl("admin", "XWiki", "XWikiPreferences",
81    params(template("deleteuorg"), kv("docname", "XWiki." + TEST_USER))));
82    // delete the test group
83  1 AbstractEscapingTest.getUrlContent(createUrl("admin", "XWiki", "XWikiPreferences",
84    params(template("deleteuorg"), kv("docname", "XWiki." + TEST_GROUP))));
85    }
86   
 
87  1 toggle @Test
88    public void testGetUsers()
89    {
90  1 skipIfIgnored("templates/getusers.vm");
91  1 Map<String, String> parameters = params(template("getusers"),
92    test("offset"), test("limit"), test("wiki"), test("reqNo"), test("sort"), test("dir"));
93    // language=en is seen as a filter, don't add it
94  1 checkUnderEscaping(createUrl("view", null, null, parameters, false), "XWIKI-5244 (get users)");
95    }
96   
 
97  1 toggle @Test
98    public void testGetGroups()
99    {
100  1 skipIfIgnored("templates/getgroups.vm");
101  1 Map<String, String> parameters = params(template("getgroups"),
102    test("offset"), test("limit"), test("wiki"), test("reqNo"), test("sort"), test("dir"));
103    // language=en is seen as a filter, don't add it
104  1 checkUnderEscaping(createUrl("view", null, null, parameters, false), "XWIKI-5244 (get groups)");
105    }
106   
 
107  1 toggle @Test
108    public void testGetUsersAndGroups()
109    {
110  1 skipIfIgnored("templates/getusersandgroups.vm");
111  1 Map<String, String> parameters = params(template("getusersandgroups"),
112    test("offset"), test("limit"), test("wiki"), test("reqNo"), test("sort"), test("dir"),
113    test("clsname"), test("space"), test("uorg"));
114    // language=en is seen as a filter, don't add it
115  1 checkUnderEscaping(createUrl("view", null, null, parameters, false), "XWIKI-5244 (get users and groups)");
116    }
117   
 
118  1 toggle @Test
119    public void testGetUsersAndGroupsUsers()
120    {
121  1 skipIfIgnored("templates/getusersandgroups.vm");
122  1 Map<String, String> parameters = params(template("getusersandgroups"),
123    test("offset"), test("limit"), test("wiki"), test("reqNo"), test("sort"), test("dir"),
124    test("clsname"), test("space"), kv("uorg", "users"));
125    // language=en is seen as a filter, don't add it
126  1 checkUnderEscaping(createUrl("view", null, null, parameters, false), "XWIKI-5244 (get users and groups: uorg=users)");
127    }
128   
 
129  1 toggle @Test
130    public void testGetUsersAndGroupsGroups()
131    {
132  1 skipIfIgnored("templates/getusersandgroups.vm");
133  1 Map<String, String> parameters = params(template("getusersandgroups"),
134    test("offset"), test("limit"), test("wiki"), test("reqNo"), test("sort"), test("dir"),
135    test("clsname"), test("space"), kv("uorg", "groups"));
136    // language=en is seen as a filter, don't add it
137  1 checkUnderEscaping(createUrl("view", null, null, parameters, false), "XWIKI-5244 (get users and groups: uorg=groups)");
138    }
139    }
140