checking if jira login is successful

This commit is contained in:
Dmitry Avdeev
2013-04-23 11:58:46 +04:00
parent 0a4e072ff0
commit ad3493d93c
2 changed files with 13 additions and 0 deletions
@@ -39,6 +39,8 @@ import java.util.List;
public class JiraRepository extends BaseRepositoryImpl {
private final static Logger LOG = Logger.getInstance("#com.intellij.tasks.jira.JiraRepository");
public static final String LOGIN_FAILED_CHECK_YOUR_PERMISSIONS = "Login failed. Check your permissions.";
private boolean myJira4 = true;
/**
@@ -160,6 +162,9 @@ public class JiraRepository extends BaseRepositoryImpl {
if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_MOVED_TEMPORARILY) {
throw new IOException("Can't login: " + statusCode + " (" + HttpStatus.getStatusText(statusCode) + ")");
}
if (statusCode == HttpStatus.SC_OK && new String(postMethod.getResponseBody(2000)).contains("\"loginSucceeded\":false")) {
throw new IOException(LOGIN_FAILED_CHECK_YOUR_PERMISSIONS);
}
return true;
}
@@ -38,6 +38,14 @@ public class JiraIntegrationTest extends TaskManagerTestCase {
assertFalse(issues[0].isClosed());
}
public void testLogin() throws Exception {
myRepository.setUsername("german");
myRepository.setUsername("wrong password");
Exception exception = myRepository.createCancellableConnection().call();
assertNotNull(exception);
assertEquals(JiraRepository.LOGIN_FAILED_CHECK_YOUR_PERMISSIONS, exception.getMessage());
}
@Override
public void setUp() throws Exception {
super.setUp();