Search in sources :

Example 1 with KeyedMessage

use of com.atlassian.stash.i18n.KeyedMessage in project stashbot by palantir.

the class JenkinsConfigurationServletTest method getTestWhenNotSysAdmin.

@Test
public void getTestWhenNotSysAdmin() throws Exception {
    when(req.getRemoteUser()).thenReturn("nonAdminStashUser");
    doThrow(new AuthorisationException(new KeyedMessage("testException", "testException", "testException"))).when(pvs).validateForGlobal(Permission.SYS_ADMIN);
    jcs.doGet(req, res);
    verify(res).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED), any(String.class));
}
Also used : AuthorisationException(com.atlassian.stash.exception.AuthorisationException) KeyedMessage(com.atlassian.stash.i18n.KeyedMessage) Test(org.junit.Test)

Example 2 with KeyedMessage

use of com.atlassian.stash.i18n.KeyedMessage in project stashbot by palantir.

the class RepoConfigurationServletTest method getTestWhenNotRepoAdmin.

@Test
public void getTestWhenNotRepoAdmin() throws Exception {
    doThrow(new AuthorisationException(new KeyedMessage("testException", "testException", "testException"))).when(pvs).validateForRepository(Mockito.any(Repository.class), eq(Permission.REPO_ADMIN));
    rcs.doGet(req, res);
    verify(res).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED), Mockito.any(String.class));
}
Also used : Repository(com.atlassian.stash.repository.Repository) AuthorisationException(com.atlassian.stash.exception.AuthorisationException) KeyedMessage(com.atlassian.stash.i18n.KeyedMessage) Test(org.junit.Test)

Example 3 with KeyedMessage

use of com.atlassian.stash.i18n.KeyedMessage in project stashbot by palantir.

the class RepoConfigurationServletTest method postTestWhenLockedDst.

@Test
public void postTestWhenLockedDst() throws Exception {
    when(jsc.getLocked()).thenReturn(false);
    when(jsc2.getLocked()).thenReturn(true);
    Exception permissionException = new AuthorisationException(new KeyedMessage("permission exceptionz", null, null));
    Mockito.doThrow(permissionException).when(pvs).validateForGlobal(Permission.SYS_ADMIN);
    when(req.getParameter("jenkinsServerName")).thenReturn("default2");
    when(cpm.getRepositoryConfigurationForRepository(mockRepo)).thenReturn(rc);
    rcs.doPost(req, res);
    verify(res).sendError(Mockito.anyInt(), Mockito.anyString());
}
Also used : AuthorisationException(com.atlassian.stash.exception.AuthorisationException) KeyedMessage(com.atlassian.stash.i18n.KeyedMessage) AuthorisationException(com.atlassian.stash.exception.AuthorisationException) Test(org.junit.Test)

Example 4 with KeyedMessage

use of com.atlassian.stash.i18n.KeyedMessage in project stash-codesearch-plugin by palantir.

the class GlobalSettingsServletTest method getTestWhenNotLoggedIn.

@Test
public void getTestWhenNotLoggedIn() throws Exception {
    Mockito.doThrow(new AuthorisationException(new KeyedMessage("testException", "testException", "testException"))).when(pvs).validateAuthenticated();
    servlet.doGet(req, res);
    Mockito.verify(res).sendRedirect(Mockito.anyString());
    Mockito.verify(res, Mockito.never()).getWriter();
}
Also used : AuthorisationException(com.atlassian.stash.exception.AuthorisationException) KeyedMessage(com.atlassian.stash.i18n.KeyedMessage) Test(org.junit.Test)

Example 5 with KeyedMessage

use of com.atlassian.stash.i18n.KeyedMessage in project stashbot by palantir.

the class JenkinsConfigurationServletTest method getTestWhenNotLoggedIn.

@Test
public void getTestWhenNotLoggedIn() throws Exception {
    when(req.getRemoteUser()).thenReturn(null);
    doThrow(new AuthorisationException(new KeyedMessage("testException", "testException", "testException"))).when(pvs).validateAuthenticated();
    jcs.doGet(req, res);
    verify(res).sendRedirect(Mockito.anyString());
    verify(res, Mockito.never()).getWriter();
}
Also used : AuthorisationException(com.atlassian.stash.exception.AuthorisationException) KeyedMessage(com.atlassian.stash.i18n.KeyedMessage) Test(org.junit.Test)

Aggregations

AuthorisationException (com.atlassian.stash.exception.AuthorisationException)7 KeyedMessage (com.atlassian.stash.i18n.KeyedMessage)7 Test (org.junit.Test)7 Repository (com.atlassian.stash.repository.Repository)1