Skip to content

Commit 62919e8

Browse files
committed
SLCORE-1116: Token for SonarQube Cloud ITs
The option to log in with username/password will be removed from SonarQube Cloud in the future.
1 parent 94c5260 commit 62919e8

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ qa_task:
186186
SQ_VERSION: "SonarCloud"
187187
JDK_VERSION: "17"
188188
CATEGORY: "-Dgroups=SonarCloud"
189-
SONARCLOUD_IT_PASSWORD: VAULT[development/team/sonarlint/kv/data/sonarcloud-it data.password]
189+
SONARCLOUD_IT_TOKEN: VAULT[development/team/sonarlint/kv/data/sonarcloud-it data.token]
190190
QA_CATEGORY: SonarCloud
191191
- env:
192192
SQ_VERSION: "DEV"

its/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
1. Make sure your Developer Box is properly setup (see xtranet)
1111
2. Configure Orchestrator settings as described [here](https://github.com/SonarSource/orchestrator#configuration). The Artifactory API key and GitHub token are the only mandatory options. The GH token is a Personal Access Token (classic) with the `repo` scope permission, and SSO properly configured
12-
3. For SonarCloud ITs, make sure the `SONARCLOUD_IT_PASSWORD` env var is defined (you can find the value in our password management tool)
12+
3. For SonarCloud ITs, make sure the `SONARCLOUD_IT_TOKEN` env var is defined (you can find the value in our password management tool)
1313
4. Run `mvn clean install` a first time from this `its` folder so that test resources are built (like custom plugins)
1414

1515
# Running ITs from IntelliJ

its/tests/src/test/java/its/SonarCloudTests.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,12 @@ class SonarCloudTests extends AbstractConnectedTests {
130130
private static final URI SONARCLOUD_STAGING_URL = URI.create("https://sc-staging.io");
131131
private static final URI SONARCLOUD_WEBSOCKETS_STAGING_URL = URI.create("wss://events-api.sc-staging.io/");
132132
private static final String SONARCLOUD_ORGANIZATION = "sonarlint-it";
133-
private static final String SONARCLOUD_USER = "sonarlint-it";
134-
private static final String SONARCLOUD_PASSWORD = System.getenv("SONARCLOUD_IT_PASSWORD");
133+
private static final String SONARCLOUD_TOKEN = System.getenv("SONARCLOUD_IT_TOKEN");
135134

136135
private static final String TIMESTAMP = Long.toString(Instant.now().toEpochMilli());
137136
private static final String TOKEN_NAME = "SLCORE-IT-" + TIMESTAMP;
138137
private static final String PROJECT_KEY_JAVA = "sample-java";
139-
140-
138+
141139
public static final String CONNECTION_ID = "sonarcloud";
142140

143141
private static WsClient adminWsClient;
@@ -195,7 +193,7 @@ static void prepare() throws Exception {
195193
static void cleanup() throws Exception {
196194
adminWsClient.userTokens()
197195
.revoke(new RevokeRequest().setName(TOKEN_NAME));
198-
196+
199197
var request = new PostRequest("api/projects/bulk_delete");
200198
request.setParam("q", "-" + randomPositiveInt);
201199
request.setParam("organization", SONARCLOUD_ORGANIZATION);
@@ -277,7 +275,7 @@ void should_use_enterprise_csharp_analyzer_with_sonarcloud() {
277275
void getAllProjects() {
278276
provisionProject("foo-bar", "Foo");
279277
var getAllProjectsParams = new GetAllProjectsParams(new TransientSonarCloudConnectionDto(SONARCLOUD_ORGANIZATION,
280-
Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD))));
278+
Either.forLeft(new TokenDto(SONARCLOUD_TOKEN))));
281279

282280
waitAtMost(1, TimeUnit.MINUTES).untilAsserted(() -> assertThat(backend.getConnectionService().getAllProjects(getAllProjectsParams).get().getSonarProjects())
283281
.extracting(SonarProjectDto::getKey)
@@ -406,14 +404,14 @@ void analysisUseConfiguration() {
406404
@Test
407405
void downloadUserOrganizations() throws ExecutionException, InterruptedException {
408406
var response = backend.getConnectionService()
409-
.listUserOrganizations(new ListUserOrganizationsParams(Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD)))).get();
407+
.listUserOrganizations(new ListUserOrganizationsParams(Either.forLeft(new TokenDto(SONARCLOUD_TOKEN)))).get();
410408
assertThat(response.getUserOrganizations()).hasSize(1);
411409
}
412410

413411
@Test
414412
void getOrganization() throws ExecutionException, InterruptedException {
415413
var response = backend.getConnectionService()
416-
.getOrganization(new GetOrganizationParams(Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD)), SONARCLOUD_ORGANIZATION)).get();
414+
.getOrganization(new GetOrganizationParams(Either.forLeft(new TokenDto(SONARCLOUD_TOKEN)), SONARCLOUD_ORGANIZATION)).get();
417415
var org = response.getOrganization();
418416
assertThat(org).isNotNull();
419417
assertThat(org.getKey()).isEqualTo(SONARCLOUD_ORGANIZATION);
@@ -484,13 +482,13 @@ void analysisXml() {
484482
void testConnection() throws ExecutionException, InterruptedException {
485483
var successResponse = backend.getConnectionService()
486484
.validateConnection(
487-
new ValidateConnectionParams(new TransientSonarCloudConnectionDto(SONARCLOUD_ORGANIZATION, Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD)))))
485+
new ValidateConnectionParams(new TransientSonarCloudConnectionDto(SONARCLOUD_ORGANIZATION, Either.forLeft(new TokenDto(SONARCLOUD_TOKEN)))))
488486
.get();
489487
assertThat(successResponse.isSuccess()).isTrue();
490488
assertThat(successResponse.getMessage()).isEqualTo("Authentication successful");
491489

492490
var failIfWrongOrg = backend.getConnectionService().validateConnection(
493-
new ValidateConnectionParams(new TransientSonarCloudConnectionDto("not-exists", Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD))))).get();
491+
new ValidateConnectionParams(new TransientSonarCloudConnectionDto("not-exists", Either.forLeft(new TokenDto(SONARCLOUD_TOKEN))))).get();
494492
assertThat(failIfWrongOrg.isSuccess()).isFalse();
495493
assertThat(failIfWrongOrg.getMessage()).isEqualTo("No organizations found for key: not-exists");
496494

@@ -621,7 +619,7 @@ private void setSettingsMultiValue(@Nullable String moduleKey, String key, Strin
621619
public static WsClient newAdminWsClient() {
622620
return WsClientFactories.getDefault().newClient(HttpConnector.newBuilder()
623621
.url(SONARCLOUD_STAGING_URL.toString())
624-
.credentials(SONARCLOUD_USER, SONARCLOUD_PASSWORD)
622+
.token(SONARCLOUD_TOKEN)
625623
.build());
626624
}
627625

@@ -675,7 +673,7 @@ private static SonarLintRpcClientDelegate newDummySonarLintClient() {
675673
@Override
676674
public Either<TokenDto, UsernamePasswordDto> getCredentials(String connectionId) throws ConnectionNotFoundException {
677675
if (connectionId.equals(CONNECTION_ID)) {
678-
return Either.forRight(new UsernamePasswordDto(SONARCLOUD_USER, SONARCLOUD_PASSWORD));
676+
return Either.forLeft(new TokenDto(SONARCLOUD_TOKEN));
679677
}
680678
return super.getCredentials(connectionId);
681679
}

0 commit comments

Comments
 (0)