use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class EncryptAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkIsSystemAdministrator();
String value = request.mandatoryParam(PARAM_VALUE);
Encryption encryption = settings.getEncryption();
checkRequest(encryption.hasSecretKey(), "No secret key available");
String encryptedValue = encryption.encrypt(value);
writeProtobuf(toEncryptWsResponse(encryptedValue), request, response);
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class CreateBitbucketActionTest method create.
@Test
public void create() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest().setParam("key", "Bitbucket Server - Dev Team").setParam("url", "https://bitbucket.enterprise.com").setParam("personalAccessToken", "98765432100").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple("Bitbucket Server - Dev Team", "https://bitbucket.enterprise.com", "98765432100"));
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class CreateGithubActionTest method create.
@Test
public void create() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest().setParam("key", "GitHub Server - Dev Team").setParam("url", "https://github.enterprise.com").setParam("appId", "12345").setParam("privateKey", "678910").setParam("clientId", "client_1234").setParam("clientSecret", "client_so_secret").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption)).containsOnly(tuple("GitHub Server - Dev Team", "https://github.enterprise.com", "12345", "678910", "client_1234", "client_so_secret"));
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class ListGithubOrganizationsActionTest method return_organizations_overriding_existing_personal_access_token.
@Test
public void return_organizations_overriding_existing_personal_access_token() {
AlmSettingDto githubAlmSettings = setupAlm();
// old pat
AlmPatDto pat = db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSettings.getUuid()).setUserUuid(userSession.getUuid()));
// new pat
UserAccessToken accessToken = new UserAccessToken("token_for_abc");
when(appClient.createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getDecryptedClientSecret(encryption), "abc")).thenReturn(accessToken);
setupGhOrganizations(githubAlmSettings, accessToken.getValue());
ListGithubOrganizationsWsResponse response = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSettings.getKey()).setParam(PARAM_TOKEN, "abc").executeProtobuf(ListGithubOrganizationsWsResponse.class);
assertThat(response.getPaging()).extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal).containsOnly(1, 100, 2);
assertThat(response.getOrganizationsList()).extracting(GithubOrganization::getKey, GithubOrganization::getName).containsOnly(tuple("github", "github"), tuple("octacat", "octacat"));
verify(appClient).createUserAccessToken(githubAlmSettings.getUrl(), githubAlmSettings.getClientId(), githubAlmSettings.getDecryptedClientSecret(encryption), "abc");
verify(appClient).listOrganizations(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(accessToken.getValue())), eq(1), eq(100));
Mockito.verifyNoMoreInteractions(appClient);
assertThat(db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), userSession.getUuid(), githubAlmSettings).get().getPersonalAccessToken()).isEqualTo(accessToken.getValue());
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class CreateAzureActionTest method create.
@Test
public void create() {
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
ws.newRequest().setParam("key", "Azure Server - Dev Team").setParam("personalAccessToken", "98765432100").setParam("url", "https://ado.sonarqube.com/").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, s -> s.getDecryptedPersonalAccessToken(encryption), AlmSettingDto::getUrl).containsOnly(tuple("Azure Server - Dev Team", "98765432100", "https://ado.sonarqube.com/"));
}
Aggregations