~james-page/ubuntu/precise/jenkins/954960-1.424.6

« back to all changes in this revision

Viewing changes to test/src/test/java/hudson/security/LoginTest.java

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Damien Raude-Morvan
  • Date: 2012-01-14 18:41:37 UTC
  • mfrom: (1.1.3) (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120114184137-1pxuj76htdqukbia
Tags: 1.409.3+dfsg-2
[ James Page ]
* http://www.cloudbees.com/jenkins-advisory/jenkins-security-advisory-2012-01-10.cb
  - Rebuild to pickup new versions of jenkins-winstone (>= 0.9.10-jenkins-31)
    and jenkins-executable-war (>= 1.25) to fix Hash DoS vulnerability in
    jenkins when running standalone.

[ Damien Raude-Morvan ]
* Add DM-Upload-Allowed flag for James Page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package hudson.security;
2
 
 
3
 
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
4
 
import com.gargoylesoftware.htmlunit.html.HtmlPage;
5
 
import org.jvnet.hudson.test.HudsonTestCase;
6
 
import org.jvnet.hudson.test.recipes.PresetData;
7
 
import org.jvnet.hudson.test.recipes.PresetData.DataSet;
8
 
import org.xml.sax.SAXException;
9
 
 
10
 
import java.io.IOException;
11
 
import java.net.URL;
12
 
 
13
 
import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
14
 
 
15
 
/**
16
 
 * @author Kohsuke Kawaguchi
17
 
 */
18
 
public class LoginTest extends HudsonTestCase {
19
 
    /**
20
 
     * Requesting a loginError page directly should result in a redirect,
21
 
     * on a non-secured Hudson.
22
 
     */
23
 
    public void testLoginErrorRedirect() throws Exception {
24
 
        verifyNotError(createWebClient());
25
 
    }
26
 
 
27
 
    private void verifyNotError(WebClient wc) throws IOException, SAXException {
28
 
        HtmlPage p = wc.goTo("loginError");
29
 
        URL url = p.getWebResponse().getUrl();
30
 
        System.out.println(url);
31
 
        assertFalse(url.toExternalForm().contains("login"));
32
 
    }
33
 
 
34
 
    /**
35
 
     * Same as {@link #testLoginErrorRedirect()} if the user has already successfully authenticated.
36
 
     */
37
 
    @PresetData(DataSet.ANONYMOUS_READONLY)
38
 
    public void testLoginErrorRedirect2() throws Exception {
39
 
        // in a secured Hudson, the error page should render.
40
 
        WebClient wc = createWebClient();
41
 
        try {
42
 
            wc.goTo("loginError");
43
 
            fail("Expecting a 401 error");
44
 
        } catch (FailingHttpStatusCodeException e) {
45
 
            e.printStackTrace();
46
 
            assertEquals(SC_UNAUTHORIZED,e.getStatusCode());
47
 
        }
48
 
 
49
 
        // but not once the user logs in.
50
 
        verifyNotError(wc.login("alice"));
51
 
    }
52
 
}