提交 872bc1cc 编写于 作者: J Jesse Glick

JUnit 4.

上级 14282571
......@@ -5,26 +5,31 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.Item;
import java.net.HttpURLConnection;
import org.jvnet.hudson.test.HudsonTestCase;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;
/**
*
* @author dty
*/
public class ExtendedReadPermissionTest extends HudsonTestCase {
private boolean enabled;
public class ExtendedReadPermissionTest {
@Override
protected void setUp() throws Exception {
super.setUp();
@Rule public JenkinsRule r = new JenkinsRule();
private static boolean enabled;
@BeforeClass public static void saveEnabled() {
// TODO potential race condition since other test suites might be running concurrently
enabled = Item.EXTENDED_READ.getEnabled();
}
@Override
protected void tearDown() throws Exception {
@AfterClass public static void restoreEnabled() {
Item.EXTENDED_READ.setEnabled(enabled);
super.tearDown();
}
/**
......@@ -39,65 +44,47 @@ public class ExtendedReadPermissionTest extends HudsonTestCase {
@LocalData
public void testReadOnlyConfigAccessWithPermissionEnabled() throws Exception {
@Test public void readOnlyConfigAccessWithPermissionEnabled() throws Exception {
setPermissionEnabled(true);
AuthorizationStrategy as = jenkins.getAuthorizationStrategy();
AuthorizationStrategy as = r.jenkins.getAuthorizationStrategy();
assertTrue("Expecting GlobalMatrixAuthorizationStrategy", (as instanceof GlobalMatrixAuthorizationStrategy));
GlobalMatrixAuthorizationStrategy gas = (GlobalMatrixAuthorizationStrategy)as;
assertTrue("Charlie should have extended read for this test", gas.hasExplicitPermission("charlie",Item.EXTENDED_READ));
WebClient wc = new WebClient().login("charlie","charlie");
JenkinsRule.WebClient wc = r.createWebClient().login("charlie","charlie");
HtmlPage page = wc.goTo("job/a/configure");
HtmlForm form = page.getFormByName("config");
HtmlButton saveButton = getButtonByCaption(form,"Save");
HtmlButton saveButton = r.getButtonByCaption(form,"Save");
assertNull(saveButton);
}
@LocalData
public void testReadOnlyConfigAccessWithPermissionDisabled() throws Exception {
@Test public void readOnlyConfigAccessWithPermissionDisabled() throws Exception {
setPermissionEnabled(false);
AuthorizationStrategy as = jenkins.getAuthorizationStrategy();
AuthorizationStrategy as = r.jenkins.getAuthorizationStrategy();
assertTrue("Expecting GlobalMatrixAuthorizationStrategy", (as instanceof GlobalMatrixAuthorizationStrategy));
GlobalMatrixAuthorizationStrategy gas = (GlobalMatrixAuthorizationStrategy)as;
assertFalse("Charlie should not have extended read for this test", gas.hasExplicitPermission("charlie",Item.EXTENDED_READ));
WebClient wc = new WebClient().login("charlie","charlie");
JenkinsRule.WebClient wc = r.createWebClient().login("charlie","charlie");
wc.assertFails("job/a/configure", HttpURLConnection.HTTP_FORBIDDEN);
}
@LocalData
public void testNoConfigAccessWithPermissionEnabled() throws Exception {
@Test public void noConfigAccessWithPermissionEnabled() throws Exception {
setPermissionEnabled(true);
AuthorizationStrategy as = jenkins.getAuthorizationStrategy();
AuthorizationStrategy as = r.jenkins.getAuthorizationStrategy();
assertTrue("Expecting GlobalMatrixAuthorizationStrategy", (as instanceof GlobalMatrixAuthorizationStrategy));
GlobalMatrixAuthorizationStrategy gas = (GlobalMatrixAuthorizationStrategy)as;
assertFalse("Bob should not have extended read for this test", gas.hasExplicitPermission("bob",Item.EXTENDED_READ));
WebClient wc = new WebClient().login("bob","bob");
JenkinsRule.WebClient wc = r.createWebClient().login("bob","bob");
wc.assertFails("job/a/configure", HttpURLConnection.HTTP_FORBIDDEN);
}
/*
@LocalData
public void testConfigureLink() throws Exception {
}
@LocalData
public void testViewConfigurationLink() throws Exception {
// TODO configureLink; viewConfigurationLink; matrixWithPermissionEnabled; matrixWithPermissionDisabled
}
@LocalData
public void testMatrixWithPermissionEnabled() throws Exception {
}
@LocalData
public void testMatrixWithPermissionDisabled() throws Exception {
}
*/
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册