diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 3bae0de743e1a1e4665e4da0202606a31061a21f..0fd77870096b1ce979aeb6e084a471cbf156a63b 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -43,6 +43,7 @@ import hudson.model.ParameterDefinition.ParameterDescriptor; import hudson.model.Project; import hudson.model.Run; import hudson.model.TopLevelItem; +import hudson.model.User; import hudson.model.View; import hudson.model.JDK; import hudson.search.SearchableModelObject; diff --git a/core/src/main/resources/hudson/model/Hudson/loginError.jelly b/core/src/main/resources/hudson/model/Hudson/loginError.jelly index 7b2ad99ef4964298cdd7e7eb6b391deb4ffd425c..577cbddfa71a360a13d4383417888d946b004a72 100644 --- a/core/src/main/resources/hudson/model/Hudson/loginError.jelly +++ b/core/src/main/resources/hudson/model/Hudson/loginError.jelly @@ -24,20 +24,32 @@ THE SOFTWARE. - - - - -
- ${%Invalid login information. Please try again.} -
- ${%Try again} -
-
-
- ${%If you are a system administrator and suspect this to be a configuration problem, see the server console output for more details.} -
-
-
-
+ + + + + + + + +
+ ${%Invalid login information. Please try again.} +
+ ${%Try again} +
+
+
+ ${%If you are a system administrator and suspect this to be a configuration problem, see the server console output for more details.} +
+
+
+
+
+ + + +
\ No newline at end of file diff --git a/test/src/test/java/hudson/security/LoginTest.java b/test/src/test/java/hudson/security/LoginTest.java new file mode 100644 index 0000000000000000000000000000000000000000..88ef8168198d2cacd423e8fc7d89984117afae7d --- /dev/null +++ b/test/src/test/java/hudson/security/LoginTest.java @@ -0,0 +1,53 @@ +package hudson.security; + +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.recipes.PresetData; +import org.jvnet.hudson.test.recipes.PresetData.DataSet; +import org.xml.sax.SAXException; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URL; + +import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; + +/** + * @author Kohsuke Kawaguchi + */ +public class LoginTest extends HudsonTestCase { + /** + * Requesting a loginError page directly should result in a redirect, + * on a non-secured Hudson. + */ + public void testLoginErrorRedirect() throws Exception { + verifyNotError(createWebClient()); + } + + private void verifyNotError(WebClient wc) throws IOException, SAXException { + HtmlPage p = wc.goTo("loginError"); + URL url = p.getWebResponse().getUrl(); + System.out.println(url); + assertFalse(url.toExternalForm().contains("login")); + } + + /** + * Same as {@link #testLoginErrorRedirect()} if the user has already successfully authenticated. + */ + @PresetData(DataSet.ANONYMOUS_READONLY) + public void testLoginErrorRedirect2() throws Exception { + // in a secured Hudson, the error page should render. + WebClient wc = createWebClient(); + try { + wc.goTo("loginError"); + fail("Expecting a 401 error"); + } catch (FailingHttpStatusCodeException e) { + e.printStackTrace(); + assertEquals(SC_UNAUTHORIZED,e.getStatusCode()); + } + + // but not once the user logs in. + verifyNotError(wc.login("alice")); + } +}