ktisha / Crucible4IDEA

Crucible plugin for IntelliJ IDEA
MIT License
59 stars 26 forks source link

Test connection failed with "Reason: Unknown error" #92

Closed fedorov-s-n closed 5 years ago

fedorov-s-n commented 6 years ago

I filled up settings in Other Settings > Code Review and pressed "Test Connection" button. Actual result is error with message "Reason: Unknown error" I try to connect to company internal bitbucket server behind https, port is standard (443). There are no messages in both Event Log and in console where idea process was launched. There is a stacktrace in idea.log that relates to this issue:

java.lang.Throwable: Malformed Json
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
    at com.jetbrains.crucible.connection.CrucibleSessionImpl.buildJsonResponse(CrucibleSessionImpl.java:160)
    at com.jetbrains.crucible.connection.CrucibleSessionImpl.login(CrucibleSessionImpl.java:92)
    at com.jetbrains.crucible.connection.CrucibleTestConnector.testConnect(CrucibleTestConnector.java:70)
    at com.jetbrains.crucible.connection.CrucibleTestConnector.run(CrucibleTestConnector.java:37)
    at com.jetbrains.crucible.connection.CrucibleTestConnectionTask.run(CrucibleTestConnectionTask.java:32)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:736)
    at com.intellij.openapi.progress.impl.CoreProgressManager$5.run(CoreProgressManager.java:434)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.application.impl.ApplicationImpl.lambda$null$10(ApplicationImpl.java:574)
    at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Stack trace says that response cannot be parsed. The reason is that response is html page, not a JSON. The reason of that in turn is bitbucket actually refuses login request. The reason of (again) that is plugin tries to login by simple formula loginUrlPrefix + "?userName=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8");. Such authentication is not secure because password is transmitted unencrypted. So that's not surprising bitbucket server is configured to deny such requests. Actually it's plugin security issue. In my individual case proper authorization is Oauth2.

There are several enchantments that can be done because of that.

  1. Improve error description
  2. Add better authorization methods like Oauth2
  3. Use personal access tokens (see /plugins/servlet/access-tokens/manage)