Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLCORE-1145 Notify client only on 401 response from server #1227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* Add new method `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient#invalidToken` to notify client that WebAPI calls to SQS/SQC fails due to wrong token
* Client can implement this method to offer user to change credentials for the connection to fix the problem
* For now notification is being sent only for 403 Forbidden HTTP response code since it's corresponds to malformed/wrong token and ignores 401 Unauthorized response code since it's a user permissions problem that has to be addressed on the server
* For now notification is being sent only for 401 Unauthorized HTTP response code since it's corresponds to malformed/wrong token and ignores 403 Forbidden response code since it's a user permissions problem that has to be addressed on the server
* Also once notification sent, backend doesn't attempt to send any requests to server anymore until credentials changed

* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient#didRaiseIssue` and associated types. See `raiseIssues` and `raiseHotspots` instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.rpc.protocol.client.sync.InvalidTokenParams;
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
import org.sonarsource.sonarlint.core.serverapi.exception.ForbiddenException;
import org.sonarsource.sonarlint.core.serverapi.exception.UnauthorizedException;

public class ServerConnection {

Expand Down Expand Up @@ -59,7 +59,7 @@ public <T> T withClientApiAndReturn(Function<ServerApi, T> serverApiConsumer) {
state = ConnectionState.ACTIVE;
lastNotificationTime = null;
return result;
} catch (ForbiddenException e) {
} catch (UnauthorizedException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
}
Expand All @@ -71,7 +71,7 @@ public void withClientApi(Consumer<ServerApi> serverApiConsumer) {
serverApiConsumer.accept(serverApi);
state = ConnectionState.ACTIVE;
lastNotificationTime = null;
} catch (ForbiddenException e) {
} catch (UnauthorizedException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.serverapi.EndpointParams;
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
import org.sonarsource.sonarlint.core.serverapi.exception.ForbiddenException;
import org.sonarsource.sonarlint.core.serverapi.exception.UnauthorizedException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -152,7 +152,7 @@ void should_log_invalid_connection() {

// switch connection to invalid state
spy.withValidConnection(connectionId, api -> {
throw new ForbiddenException("401");
throw new UnauthorizedException("401");
});
// attempt to get connection
spy.withValidConnection(connectionId, api -> {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void it_should_sync_when_credentials_are_updated(SonarLintTestHarness harness) {

@SonarLintTest
void it_should_notify_client_if_invalid_token() {
var status = 403;
var status = 401;
var client = newFakeClient()
.withCredentials(CONNECTION_ID, "user", "pw")
.build();
Expand Down