Skip to content

Commit

Permalink
PR feedback, polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-knize-sonarsource committed Jan 21, 2025
1 parent c988d92 commit 5ebeeaf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
5 changes: 5 additions & 0 deletions API_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Breaking changes

* 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
* 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.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer#getIssueTrackingService` and associated types. Tracking is managed by the backend.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer#getSecurityHotspotMatchingService` and associated types. Tracking is managed by the backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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 @@ -63,9 +62,6 @@ public <T> T withClientApiAndReturn(Function<ServerApi, T> serverApiConsumer) {
} catch (ForbiddenException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
} catch (UnauthorizedException e) {
state = ConnectionState.MISSING_PERMISSION;
notifyClientAboutWrongTokenIfNeeded();
}
return null;
}
Expand All @@ -78,9 +74,6 @@ public void withClientApi(Consumer<ServerApi> serverApiConsumer) {
} catch (ForbiddenException e) {
state = ConnectionState.INVALID_CREDENTIALS;
notifyClientAboutWrongTokenIfNeeded();
} catch (UnauthorizedException e) {
state = ConnectionState.MISSING_PERMISSION;
notifyClientAboutWrongTokenIfNeeded();
}
}

Expand Down
4 changes: 0 additions & 4 deletions backend/server-connection/src/main/proto/sonarlint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ message LastEventPolling {
int64 last_event_polling = 1;
}

message LastWebApiErrorNotification {
int64 last_wrong_token_notification = 1;
}

enum NewCodeDefinitionMode {
UNKNOWN = 0;
NUMBER_OF_DAYS = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.sonarsource.sonarlint.core.commons.RuleType;
import org.sonarsource.sonarlint.core.commons.api.TextRange;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.config.DidChangeCredentialsParams;
Expand Down Expand Up @@ -133,9 +131,9 @@ void it_should_sync_when_credentials_are_updated(SonarLintTestHarness harness) {
"Synchronizing project branches for project 'projectKey'"));
}

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

0 comments on commit 5ebeeaf

Please sign in to comment.