1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.administration.test.po.GlobalRightsAdministrationSectionPage; |
26 |
|
import org.xwiki.test.ui.browser.IgnoreBrowser; |
27 |
|
import org.xwiki.test.ui.browser.IgnoreBrowsers; |
28 |
|
import org.xwiki.test.ui.po.LoginPage; |
29 |
|
import org.xwiki.test.ui.po.ResubmissionPage; |
30 |
|
import org.xwiki.test.ui.po.ViewPage; |
31 |
|
import org.xwiki.test.ui.po.editor.WikiEditPage; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 84.3% |
Uncovered Elements: 13 (83) |
Complexity: 11 |
Complexity Density: 0.16 |
|
39 |
|
public class LoginTest extends AbstractTest |
40 |
|
{ |
41 |
|
private ViewPage vp; |
42 |
|
|
43 |
|
private String nonExistentPageURL; |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
45 |
7 |
@Before... |
46 |
|
public void setUp() |
47 |
|
{ |
48 |
|
|
49 |
7 |
getUtil().forceGuestUser(); |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
7 |
getUtil().gotoPage("NonExistentSpace", "NonExistentPage", "view", "spaceRedirect=false"); |
55 |
7 |
this.vp = new ViewPage(); |
56 |
7 |
this.nonExistentPageURL = getDriver().getCurrentUrl(); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
3FAIL
|
|
59 |
0 |
@Test... |
60 |
|
@IgnoreBrowsers({ |
61 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
62 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
63 |
|
}) |
64 |
|
public void testLoginLogoutAsAdmin() |
65 |
|
{ |
66 |
0 |
LoginPage loginPage = this.vp.login(); |
67 |
0 |
loginPage.loginAsAdmin(); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
0 |
Assert.assertEquals(this.nonExistentPageURL, getDriver().getCurrentUrl()); |
72 |
|
|
73 |
0 |
Assert.assertTrue(this.vp.isAuthenticated()); |
74 |
0 |
Assert.assertEquals("Administrator", this.vp.getCurrentUser()); |
75 |
|
|
76 |
|
|
77 |
0 |
this.vp.logout(); |
78 |
0 |
Assert.assertFalse(this.vp.isAuthenticated()); |
79 |
0 |
Assert.assertEquals(this.nonExistentPageURL, getDriver().getCurrentUrl()); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
@IgnoreBrowsers({ |
84 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
85 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
86 |
|
}) |
87 |
|
public void testLoginWithInvalidCredentials() |
88 |
|
{ |
89 |
1 |
LoginPage loginPage = this.vp.login(); |
90 |
1 |
loginPage.loginAs("Admin", "wrong password"); |
91 |
1 |
Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage()); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
@IgnoreBrowsers({ |
96 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
97 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
98 |
|
}) |
99 |
|
public void testLoginWithInvalidUsername() |
100 |
|
{ |
101 |
1 |
LoginPage loginPage = this.vp.login(); |
102 |
1 |
loginPage.loginAs("non existent user", "admin"); |
103 |
1 |
Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage()); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
public void testRedirectBackAfterLogin() |
112 |
|
{ |
113 |
1 |
try { |
114 |
|
|
115 |
|
|
116 |
1 |
GlobalRightsAdministrationSectionPage grasp = new GlobalRightsAdministrationSectionPage(); |
117 |
1 |
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL())); |
118 |
1 |
getUtil().recacheSecretToken(); |
119 |
1 |
getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS); |
120 |
1 |
grasp.forceAuthenticatedView(); |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
ViewPage page = getUtil().gotoPage("SomeSpace", "SomePage"); |
125 |
1 |
page.logout(); |
126 |
|
|
127 |
1 |
LoginPage loginPage = new LoginPage(); |
128 |
|
|
129 |
1 |
getDriver().manage().deleteAllCookies(); |
130 |
1 |
loginPage.loginAsAdmin(); |
131 |
|
|
132 |
|
|
133 |
1 |
Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL("SomeSpace", "SomePage"))); |
134 |
|
} finally { |
135 |
1 |
GlobalRightsAdministrationSectionPage grasp = GlobalRightsAdministrationSectionPage.gotoPage(); |
136 |
1 |
if (!grasp.isAuthenticated()) { |
137 |
0 |
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL())); |
138 |
|
} |
139 |
1 |
grasp.unforceAuthenticatedView(); |
140 |
|
} |
141 |
|
} |
142 |
|
|
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 2 |
Complexity Density: 0.11 |
1PASS
|
|
143 |
1 |
@Test... |
144 |
|
@IgnoreBrowsers({ |
145 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
146 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
147 |
|
}) |
148 |
|
public void testRedirectPreservesPOSTParameters() |
149 |
|
{ |
150 |
1 |
String test = "Test string " + System.currentTimeMillis(); |
151 |
1 |
final String space = "Main"; |
152 |
1 |
final String page = "POSTTest"; |
153 |
1 |
LoginPage loginPage = this.vp.login(); |
154 |
1 |
loginPage.loginAsAdmin(); |
155 |
|
|
156 |
1 |
WikiEditPage editPage = WikiEditPage.gotoPage(space, page); |
157 |
1 |
editPage.setTitle(test); |
158 |
1 |
editPage.setContent(test); |
159 |
|
|
160 |
1 |
getDriver().manage().deleteAllCookies(); |
161 |
|
|
162 |
1 |
editPage.clickSaveAndView(); |
163 |
|
|
164 |
1 |
String wantUrl = getUtil().getURL("XWiki", "XWikiLogin", "login"); |
165 |
1 |
if (wantUrl.indexOf('?') > 0) { |
166 |
|
|
167 |
1 |
wantUrl = wantUrl.substring(0, wantUrl.indexOf('?')); |
168 |
|
} |
169 |
1 |
Assert.assertTrue(getDriver().getCurrentUrl().startsWith(wantUrl)); |
170 |
1 |
loginPage.loginAsAdmin(); |
171 |
|
|
172 |
1 |
Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL(space, page))); |
173 |
1 |
editPage = WikiEditPage.gotoPage(space, page); |
174 |
1 |
Assert.assertEquals(test, editPage.getTitle()); |
175 |
1 |
Assert.assertEquals(test, editPage.getContent()); |
176 |
|
} |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
178 |
1 |
@Test... |
179 |
|
@IgnoreBrowsers({ |
180 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
181 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
182 |
|
}) |
183 |
|
public void testCorrectUrlIsAccessedAfterLogin() |
184 |
|
{ |
185 |
|
|
186 |
|
|
187 |
1 |
getUtil().gotoPage("Scheduler", "WebHome"); |
188 |
1 |
LoginPage loginPage = new LoginPage(); |
189 |
1 |
Assert.assertFalse(loginPage.isAuthenticated()); |
190 |
1 |
loginPage.loginAsAdmin(); |
191 |
|
|
192 |
1 |
Assert.assertTrue(getDriver().getCurrentUrl().contains("/xwiki/bin/view/Scheduler/WebHome")); |
193 |
1 |
Assert.assertTrue(getDriver().getTitle().contains("Job Scheduler")); |
194 |
|
} |
195 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
1PASS
|
|
196 |
1 |
@Test... |
197 |
|
@IgnoreBrowsers({ |
198 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
199 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
200 |
|
}) |
201 |
|
public void testDataIsPreservedAfterLogin() |
202 |
|
{ |
203 |
1 |
getUtil().gotoPage("Test", "TestData", "save", "content=this+should+not+be+saved"); |
204 |
1 |
getUtil().gotoPage("Test", "TestData", "save", "content=this+should+be+saved+instead&parent=Main.WebHome"); |
205 |
1 |
LoginPage loginPage = new LoginPage(); |
206 |
1 |
loginPage.loginAsAdmin(); |
207 |
|
|
208 |
1 |
ResubmissionPage resubmissionPage = new ResubmissionPage(); |
209 |
1 |
if (resubmissionPage.isOnResubmissionPage()) { |
210 |
1 |
resubmissionPage.resubmit(); |
211 |
|
} |
212 |
1 |
Assert.assertTrue(getDriver().getCurrentUrl().contains("/xwiki/bin/view/Test/TestData")); |
213 |
1 |
ViewPage viewPage = new ViewPage(); |
214 |
1 |
Assert.assertEquals("this should be saved instead", viewPage.getContent()); |
215 |
|
} |
216 |
|
} |