未验证 提交 f86cf08e 编写于 作者: J Jesse Glick

Adapt some tests to newer Jetty.

上级 a2918a48
...@@ -167,7 +167,7 @@ THE SOFTWARE. ...@@ -167,7 +167,7 @@ THE SOFTWARE.
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId> <artifactId>hamcrest-core</artifactId>
<version>1.3</version> <version>2.2</version>
</dependency> </dependency>
<dependency> <dependency>
<!-- for testing JNLP launch. --> <!-- for testing JNLP launch. -->
......
...@@ -4,8 +4,13 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; ...@@ -4,8 +4,13 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import static org.hamcrest.Matchers.*;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -13,15 +18,6 @@ import org.jvnet.hudson.test.Issue; ...@@ -13,15 +18,6 @@ import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy; import org.jvnet.hudson.test.MockAuthorizationStrategy;
import java.net.HttpURLConnection;
import java.net.URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
//TODO merge back to DefaultCrumbIssuerTest //TODO merge back to DefaultCrumbIssuerTest
public class DefaultCrumbIssuerSEC1491Test { public class DefaultCrumbIssuerSEC1491Test {
...@@ -72,7 +68,8 @@ public class DefaultCrumbIssuerSEC1491Test { ...@@ -72,7 +68,8 @@ public class DefaultCrumbIssuerSEC1491Test {
r.createWebClient().getPage(request1); r.createWebClient().getPage(request1);
fail(); fail();
} catch (FailingHttpStatusCodeException e) { } catch (FailingHttpStatusCodeException e) {
assertTrue(e.getMessage().contains("No valid crumb")); assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getStatusCode());
assertThat(e.getResponse().getContentAsString(), containsString("No valid crumb"));
} }
// cannot create new job due to missing crumb // cannot create new job due to missing crumb
assertNull(r.jenkins.getItem(jobName1)); assertNull(r.jenkins.getItem(jobName1));
......
...@@ -10,6 +10,9 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; ...@@ -10,6 +10,9 @@ import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.User; import hudson.model.User;
import javax.servlet.http.HttpServletResponse;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -17,10 +20,6 @@ import org.jvnet.hudson.test.Issue; ...@@ -17,10 +20,6 @@ import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient; import org.jvnet.hudson.test.JenkinsRule.WebClient;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* @author dty * @author dty
*/ */
...@@ -74,7 +73,8 @@ public class DefaultCrumbIssuerSEC626Test { //TODO merge back to DefaultCrumbIss ...@@ -74,7 +73,8 @@ public class DefaultCrumbIssuerSEC626Test { //TODO merge back to DefaultCrumbIss
r.submit(p.getFormByName("config")); r.submit(p.getFormByName("config"));
fail(); fail();
} catch (FailingHttpStatusCodeException e) { } catch (FailingHttpStatusCodeException e) {
assertTrue(e.getMessage().contains("No valid crumb")); assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getStatusCode());
assertThat(e.getResponse().getContentAsString(), containsString("No valid crumb"));
} }
} }
} }
......
...@@ -10,6 +10,7 @@ import hudson.model.Item; ...@@ -10,6 +10,7 @@ import hudson.model.Item;
import hudson.model.UnprotectedRootAction; import hudson.model.UnprotectedRootAction;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration; import jenkins.model.JenkinsLocationConfiguration;
import static org.hamcrest.Matchers.*;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -176,7 +177,7 @@ public class ResourceDomainTest { ...@@ -176,7 +177,7 @@ public class ResourceDomainTest {
String modifiedUrl = resourceResponseUrl.replaceAll("static[-]files[/]....", "static-files/aaaa"); String modifiedUrl = resourceResponseUrl.replaceAll("static[-]files[/]....", "static-files/aaaa");
Page page = webClient.getPage(modifiedUrl); Page page = webClient.getPage(modifiedUrl);
Assert.assertEquals("resource not found", 404, page.getWebResponse().getStatusCode()); Assert.assertEquals("resource not found", 404, page.getWebResponse().getStatusCode());
Assert.assertEquals("resource not found", ResourceDomainFilter.ERROR_RESPONSE, page.getWebResponse().getStatusMessage()); Assert.assertThat("resource not found", page.getWebResponse().getContentAsString(), containsString(ResourceDomainFilter.ERROR_RESPONSE));
} }
...@@ -219,7 +220,7 @@ public class ResourceDomainTest { ...@@ -219,7 +220,7 @@ public class ResourceDomainTest {
// and we get a 403 response // and we get a 403 response
page = webClient.getPage(anonUrl); page = webClient.getPage(anonUrl);
Assert.assertEquals("page is not found", 403, page.getWebResponse().getStatusCode()); Assert.assertEquals("page is not found", 403, page.getWebResponse().getStatusCode());
Assert.assertTrue("Response mentions workspace permission", page.getWebResponse().getStatusMessage().contains("Failed permission check: anonymous is missing the Job/Workspace permission")); Assert.assertThat("Response mentions workspace permission", page.getWebResponse().getContentAsString(), containsString("Failed permission check: anonymous is missing the Job/Workspace permission"));
// now remove Job/Read permission from all users (but grant Discover) // now remove Job/Read permission from all users (but grant Discover)
a = new MockAuthorizationStrategy(); a = new MockAuthorizationStrategy();
...@@ -230,7 +231,7 @@ public class ResourceDomainTest { ...@@ -230,7 +231,7 @@ public class ResourceDomainTest {
// and we get a 403 response asking to log in (Job/Discover is basically meant to be granted to anonymous only) // and we get a 403 response asking to log in (Job/Discover is basically meant to be granted to anonymous only)
page = webClient.getPage(anonUrl); page = webClient.getPage(anonUrl);
Assert.assertEquals("page is not found", 403, page.getWebResponse().getStatusCode()); Assert.assertEquals("page is not found", 403, page.getWebResponse().getStatusCode());
Assert.assertTrue("Response mentions workspace permission", page.getWebResponse().getStatusMessage().contains("Failed permission check: Please login to access job")); Assert.assertThat("Response mentions workspace permission", page.getWebResponse().getContentAsString(), containsString("Failed permission check: Please login to access job"));
} }
@Test @Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册