use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class AlmSettingDaoTest method selectByUuid.
@Test
public void selectByUuid() {
when(uuidFactory.create()).thenReturn(A_UUID);
when(encryption.isEncrypted(any())).thenReturn(false);
AlmSettingDto almSettingDto = newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
assertThat(underTest.selectByUuid(dbSession, A_UUID).get()).extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt, s -> almSettingDto.getDecryptedPrivateKey(encryption), s -> almSettingDto.getDecryptedPersonalAccessToken(encryption), s -> almSettingDto.getDecryptedClientSecret(encryption)).containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(), almSettingDto.getAppId(), NOW, NOW, almSettingDto.getDecryptedPrivateKey(encryption), almSettingDto.getDecryptedPersonalAccessToken(encryption), almSettingDto.getDecryptedClientSecret(encryption));
assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class AlmSettingDaoTest method selectByKey.
@Test
public void selectByKey() {
when(uuidFactory.create()).thenReturn(A_UUID);
String decrypted = "decrypted";
when(encryption.isEncrypted(any())).thenReturn(true);
when(encryption.decrypt(any())).thenReturn(decrypted);
AlmSettingDto almSettingDto = AlmSettingsTesting.newGithubAlmSettingDto();
underTest.insert(dbSession, almSettingDto);
assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).get()).extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt, s -> almSettingDto.getDecryptedPrivateKey(encryption), s -> almSettingDto.getDecryptedPersonalAccessToken(encryption), s -> almSettingDto.getDecryptedClientSecret(encryption)).containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(), almSettingDto.getAppId(), NOW, NOW, almSettingDto.getDecryptedPrivateKey(encryption), null, almSettingDto.getDecryptedClientSecret(encryption));
assertThat(underTest.selectByKey(dbSession, "foo")).isNotPresent();
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class AlmSettingDaoTest method selectByKey_withEmptySecrets.
@Test
public void selectByKey_withEmptySecrets() {
when(uuidFactory.create()).thenReturn(A_UUID);
String decrypted = "decrypted";
when(encryption.isEncrypted(any())).thenReturn(true);
when(encryption.decrypt(any())).thenReturn(decrypted);
AlmSettingDto almSettingDto = AlmSettingsTesting.newAlmSettingDtoWithEmptySecrets();
underTest.insert(dbSession, almSettingDto);
assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).get()).extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt, s -> almSettingDto.getDecryptedPrivateKey(encryption), s -> almSettingDto.getDecryptedPersonalAccessToken(encryption), s -> almSettingDto.getDecryptedClientSecret(encryption)).containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(), almSettingDto.getAppId(), NOW, NOW, null, null, null);
assertThat(underTest.selectByKey(dbSession, "foo")).isNotPresent();
}
use of org.sonar.api.config.internal.Encryption in project sonarqube by SonarSource.
the class CreateGithubActionTest method remove_trailing_slash.
@Test
public void remove_trailing_slash() {
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 UpdateBitbucketCloudActionTest method update_with_new_key.
@Test
public void update_with_new_key() {
when(encryption.isEncrypted(any())).thenReturn(false);
UserDto user = db.users().insertUser();
userSession.logIn(user).setSystemAdministrator();
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("newKey", "Bitbucket Server - Infra Team").setParam("workspace", "workspace").setParam("clientId", "id").setParam("clientSecret", "secret").execute();
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption), AlmSettingDto::getAppId).containsOnly(tuple("Bitbucket Server - Infra Team", "id", "secret", "workspace"));
}
Aggregations