@@ -56,6 +56,9 @@ export default function AzureForm(props: AzureFormProps) { | |||
{translate('settings.almintegration.form.url.azure.help2')} | |||
<br /> | |||
<em>https://dev.azure.com/your_organization</em> | |||
<br /> | |||
<br /> | |||
{translate('settings.almintegration.form.url.pat_warning')} | |||
</> | |||
} | |||
id="url.azure" |
@@ -26,6 +26,9 @@ exports[`should render correctly: create 1`] = ` | |||
<em> | |||
https://dev.azure.com/your_organization | |||
</em> | |||
<br /> | |||
<br /> | |||
settings.almintegration.form.url.pat_warning | |||
</React.Fragment> | |||
} | |||
id="url.azure" | |||
@@ -97,6 +100,9 @@ exports[`should render correctly: edit 1`] = ` | |||
<em> | |||
https://dev.azure.com/your_organization | |||
</em> | |||
<br /> | |||
<br /> | |||
settings.almintegration.form.url.pat_warning | |||
</React.Fragment> | |||
} | |||
id="url.azure" |
@@ -95,6 +95,8 @@ public class UpdateAzureAction implements AlmSettingsWsAction { | |||
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey); | |||
} | |||
almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat); | |||
if (isNotBlank(pat)) { | |||
almSettingDto.setPersonalAccessToken(pat); | |||
} |
@@ -85,6 +85,7 @@ public class UpdateBitbucketAction implements AlmSettingsWsAction { | |||
private void doHandle(Request request) { | |||
String key = request.mandatoryParam(PARAM_KEY); | |||
String newKey = request.param(PARAM_NEW_KEY); | |||
String url = request.mandatoryParam(PARAM_URL); | |||
String pat = request.param(PARAM_PERSONAL_ACCESS_TOKEN); | |||
try (DbSession dbSession = dbClient.openSession(false)) { | |||
@@ -93,7 +94,6 @@ public class UpdateBitbucketAction implements AlmSettingsWsAction { | |||
almSettingsSupport.checkAlmSettingDoesNotAlreadyExist(dbSession, newKey); | |||
} | |||
String url = request.mandatoryParam(PARAM_URL); | |||
almSettingsSupport.checkPatOnUrlUpdate(almSettingDto, url, pat); | |||
if (isNotBlank(pat)) { |
@@ -31,6 +31,7 @@ import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.TestRequest; | |||
import org.sonar.server.ws.WsActionTester; | |||
import static java.lang.String.format; | |||
@@ -90,7 +91,7 @@ public class UpdateAzureActionTest { | |||
} | |||
@Test | |||
public void update_without_pat() { | |||
public void update_with_url_change_needs_pat() { | |||
UserDto user = db.users().insertUser(); | |||
userSession.logIn(user).setSystemAdministrator(); | |||
@@ -99,10 +100,28 @@ public class UpdateAzureActionTest { | |||
ws.newRequest() | |||
.setParam("key", almSettingDto.getKey()) | |||
.setParam("url", AZURE_URL) | |||
.setParam("personalAccessToken", "0123456789") | |||
.execute(); | |||
assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())) | |||
.extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)) | |||
.containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, almSettingDto.getDecryptedPersonalAccessToken(encryption))); | |||
.containsOnly(tuple(almSettingDto.getKey(), AZURE_URL, "0123456789")); | |||
} | |||
@Test | |||
public void fail_when_update_url_without_pat() { | |||
UserDto user = db.users().insertUser(); | |||
userSession.logIn(user).setSystemAdministrator(); | |||
AlmSettingDto almSettingDto = db.almSettings().insertAzureAlmSetting(); | |||
TestRequest request = ws.newRequest() | |||
.setParam("key", almSettingDto.getKey()) | |||
.setParam("url", AZURE_URL); | |||
assertThatThrownBy(() -> request.execute()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Please provide the Personal Access Token to update the URL."); | |||
} | |||
@Test |
@@ -105,7 +105,7 @@ public class UpdateBitbucketActionTest { | |||
} | |||
@Test | |||
public void update_with_url_change_needs_path() { | |||
public void update_with_url_change_needs_pat() { | |||
UserDto user = db.users().insertUser(); | |||
userSession.logIn(user).setSystemAdministrator(); | |||