@Test
@JiraBuildNumberDependent(BN_JIRA_4_4)
public void testCreateAndRemoveComponentAsUnauthorizedUsers() {
final Iterable<BasicComponent> components = client.getProjectClient().getProject("TST", pm).getComponents();
assertEquals(2, Iterables.size(components));
final BasicComponent basicComponent = Iterables.get(components, 0);
final ComponentInput componentInput = new ComponentInput("my component", "a description", null, null);
setUser1();
final Response.Status expectedForbiddenErrorCode = (doesJiraReturnCorrectErrorCodeForForbiddenOperation()) ? Response.Status.FORBIDDEN : Response.Status.UNAUTHORIZED;
TestUtil.assertErrorCode(expectedForbiddenErrorCode, "The user wseliga does not have permission to complete this operation.", new Runnable() {
@Override
public void run() {
client.getComponentClient().removeComponent(basicComponent.getSelf(), null, pm);
}
});
TestUtil.assertErrorCode(expectedForbiddenErrorCode, "You cannot edit the configuration of this project.", new Runnable() {
@Override
public void run() {
client.getComponentClient().createComponent("TST", componentInput, pm);
}
});
setAnonymousMode();
TestUtil.assertErrorCode(Response.Status.NOT_FOUND, IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ?
"The component with id 10000 does not exist." : "This user does not have permission to complete this operation.", new Runnable() {
@Override
public void run() {
client.getComponentClient().removeComponent(basicComponent.getSelf(), null, pm);
}
});
if (IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER) {
TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "No project could be found with key 'TST'.", new Runnable() {
@Override
public void run() {
client.getComponentClient().createComponent("TST", componentInput, pm);
}
});
} else {
// IMO for anonymous access still Response.Status.UNAUTHORIZED should be returned - JRADEV-7671
TestUtil.assertErrorCode(expectedForbiddenErrorCode, "You cannot edit the configuration of this project.", new Runnable() {
@Override
public void run() {
client.getComponentClient().createComponent("TST", componentInput, pm);
}
});
}
setAdmin();
// now let's try to add a component with colliding name
final ComponentInput dupeComponentInput = new ComponentInput(basicComponent.getName(), "a description", null, null);
TestUtil.assertErrorCode(Response.Status.BAD_REQUEST, "A component with the name Component A already exists in this project.", new Runnable() {
@Override
public void run() {
client.getComponentClient().createComponent("TST", dupeComponentInput, pm);
}