Skip to content

Commit

Permalink
SLVS-1654 Drop support for creating new connections with username-pas…
Browse files Browse the repository at this point in the history
…sword authentication
  • Loading branch information
georgii-borovinskikh-sonarsource committed Jan 10, 2025
1 parent ac3e2ca commit e12deaf
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,6 @@ public void TryAddConnection_TokenCredentialsModel_MapsCredentials()
.TryAdd(Arg.Is<ServerConnection.SonarQube>(sq => IsExpectedTokenCredentials(sq.Credentials, token)));
}

[TestMethod]
public void TryAddConnection_UsernamePasswordModel_MapsCredentials()
{
var sonarQube = CreateSonarQubeConnection();
var username = "username";
var password = "password";

testSubject.TryAddConnection(sonarQube, new UsernamePasswordModel(username, password.CreateSecureString()));

serverConnectionsRepository.Received(1)
.TryAdd(Arg.Is<ServerConnection.SonarQube>(sq => IsExpectedCredentials(sq.Credentials, username, password)));
}

[TestMethod]
public void TryAddConnection_NullCredentials_TriesAddingAConnectionWithNoCredentials()
{
Expand Down Expand Up @@ -261,19 +248,6 @@ public void TryUpdateCredentials_TokenCredentialsModel_MapsCredentials()
.TryUpdateCredentialsById(Arg.Any<string>(), Arg.Is<IConnectionCredentials>(x => IsExpectedTokenCredentials(x, token)));
}

[TestMethod]
public void TryUpdateCredentials_UserPasswordModel_MapsCredentials()
{
var sonarQube = CreateSonarQubeConnection();
const string username = "username";
const string password = "password";

testSubject.TryUpdateCredentials(sonarQube, new UsernamePasswordModel(username, password.CreateSecureString()));

serverConnectionsRepository.Received(1)
.TryUpdateCredentialsById(Arg.Any<string>(), Arg.Is<IConnectionCredentials>(x => IsExpectedCredentials(x, username, password)));
}

[TestMethod]
public void TryUpdateCredentials_SonarQube_MapsConnection()
{
Expand Down
35 changes: 0 additions & 35 deletions src/ConnectedMode.UnitTests/SlCoreConnectionAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ await connectionConfigurationSlCoreService.Received(1)
.ValidateConnectionAsync(Arg.Is<ValidateConnectionParams>(x => IsExpectedSonarQubeConnectionParams(x, token)));
}

[TestMethod]
public async Task ValidateConnectionAsync_ConnectionToSonarQubeWithCredentials_CallsValidateConnectionWithCorrectParams()
{
var username = "username";
var password = "password";

await testSubject.ValidateConnectionAsync(sonarQubeConnectionInfo, new UsernamePasswordModel(username, password.CreateSecureString()));

await connectionConfigurationSlCoreService.Received(1)
.ValidateConnectionAsync(Arg.Is<ValidateConnectionParams>(x => IsExpectedSonarQubeConnectionParams(x, username, password)));
}

[TestMethod]
public async Task ValidateConnectionAsync_ConnectionToSonarCloudWithToken_CallsValidateConnectionWithCorrectParams()
{
Expand All @@ -118,18 +106,6 @@ await connectionConfigurationSlCoreService.Received(1)
.ValidateConnectionAsync(Arg.Is<ValidateConnectionParams>(x => IsExpectedSonarCloudConnectionParams(x, token)));
}

[TestMethod]
public async Task ValidateConnectionAsync_ConnectionToSonarCloudWithCredentials_CallsValidateConnectionWithCorrectParams()
{
var username = "username";
var password = "password";

await testSubject.ValidateConnectionAsync(sonarCloudConnectionInfo, new UsernamePasswordModel(username, password.CreateSecureString()));

await connectionConfigurationSlCoreService.Received(1)
.ValidateConnectionAsync(Arg.Is<ValidateConnectionParams>(x => IsExpectedSonarCloudConnectionParams(x, username, password)));
}

[TestMethod]
[DataRow(true, "success")]
[DataRow(false, "failure")]
Expand Down Expand Up @@ -203,17 +179,6 @@ public async Task GetOrganizationsAsync_TokenIsProvided_CallsSlCoreListUserOrgan
await connectionConfigurationSlCoreService.Received(1).ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x=> IsExpectedCredentials(x.credentials, token)));
}

[TestMethod]
public async Task GetOrganizationsAsync_UsernameAndPasswordIsProvided_CallsSlCoreListUserOrganizationsWithUsernameAndPassword()
{
var username = "username";
var password = "password";

await testSubject.GetOrganizationsAsync(new UsernamePasswordModel(username, password.CreateSecureString()));

await connectionConfigurationSlCoreService.Received(1).ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => IsExpectedCredentials(x.credentials, username, password)));
}

[TestMethod]
public async Task GetOrganizationsAsync_CredentialsIsNull_ReturnsFailedResponseAndShouldLog()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,58 +49,8 @@ public void TestInitialize()
}

[TestMethod]
public void SelectedAuthenticationType_ShouldBeTokenByDefault()
public void IsConfirmationEnabled_TokenIsFilled_ReturnsTrue()
{
testSubject.SelectedAuthenticationType.Should().Be(UiResources.AuthenticationTypeOptionToken);
testSubject.IsTokenAuthentication.Should().BeTrue();
}

[TestMethod]
public void SelectedAuthenticationType_ClearsWarning()
{
testSubject.ProgressReporterViewModel.Warning = "credentials warning";

testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.ProgressReporterViewModel.Received(1).Warning = null;
}

[TestMethod]
public void IsTokenAuthentication_TokenIsSelected_ReturnsTrue()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.IsTokenAuthentication.Should().BeTrue();
}

[TestMethod] public void IsTokenAuthentication_CredentialsIsSelected_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.IsTokenAuthentication.Should().BeFalse();
}

[TestMethod]
public void IsCredentialsAuthentication_TokenIsSelected_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.IsCredentialsAuthentication.Should().BeFalse();
}

[TestMethod]
public void IsCredentialsAuthentication_CredentialsIsSelected_ReturnsTrue()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.IsCredentialsAuthentication.Should().BeTrue();
}

[TestMethod]
public void IsConfirmationEnabled_TokenIsSelectedAndTokenIsFilled_ReturnsTrue()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.Token = "dummy token".CreateSecureString();

testSubject.IsConfirmationEnabled.Should().BeTrue();
Expand All @@ -109,7 +59,6 @@ public void IsConfirmationEnabled_TokenIsSelectedAndTokenIsFilled_ReturnsTrue()
[TestMethod]
public void IsConfirmationEnabled_CorrectTokenIsProvidedAndValidationIsInProgress_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;
testSubject.Token = "dummy token".CreateSecureString();

testSubject.ProgressReporterViewModel.IsOperationInProgress.Returns(true);
Expand All @@ -121,142 +70,32 @@ public void IsConfirmationEnabled_CorrectTokenIsProvidedAndValidationIsInProgres
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void IsConfirmationEnabled_TokenIsSelectedAndTokenIsNotFilled_ReturnsFalse(string token)
public void IsConfirmationEnabled_TokenIsNotFilled_ReturnsFalse(string token)
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.Token = token.CreateSecureString();

testSubject.IsConfirmationEnabled.Should().BeFalse();
}

[TestMethod]
public void IsConfirmationEnabled_CredentialsIsSelectedAndUsernameAndPasswordAreFilled_ReturnsTrue()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.Username = "dummy username";
testSubject.Password = "dummy password".CreateSecureString();

testSubject.IsConfirmationEnabled.Should().BeTrue();
}

[TestMethod]
public void IsConfirmationEnabled_CorrectCredentialsProvidedAndValidationIsInProgress_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Username = "dummy username";
testSubject.Password = "dummy password".CreateSecureString();

testSubject.ProgressReporterViewModel.IsOperationInProgress.Returns(true);

testSubject.IsConfirmationEnabled.Should().BeFalse();
}

[TestMethod]
[DataRow(null, "pwd")]
[DataRow("", "pwd")]
[DataRow(" ", "pwd")]
[DataRow("username", null)]
[DataRow("username", "")]
[DataRow("username", " ")]
public void IsConfirmationEnabled_CredentialsIsSelectedAndUsernameOrPasswordAreNotFilled_ReturnsFalse(string username, string password)
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.Username = username;
testSubject.Password = password.CreateSecureString();

testSubject.IsConfirmationEnabled.Should().BeFalse();
}

[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldTokenBeFilled_TokenAuthenticationIsSelectedAndTokenIsEmpty_ReturnsTrue(string token)
public void ShouldTokenBeFilled_TokenIsEmpty_ReturnsTrue(string token)
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;
testSubject.Token = token.CreateSecureString();

testSubject.ShouldTokenBeFilled.Should().BeTrue();
}

[TestMethod]
public void ShouldTokenBeFilled_TokenAuthenticationIsSelectedAndTokenIsFilled_ReturnsFalse()
public void ShouldTokenBeFilled_TokenIsFilled_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;
testSubject.Token = "dummy token".CreateSecureString();

testSubject.ShouldTokenBeFilled.Should().BeFalse();
}

[TestMethod]
public void ShouldTokenBeFilled_CredentialsAuthenticationIsSelected_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

testSubject.ShouldTokenBeFilled.Should().BeFalse();
}

[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldUsernameBeFilled_CredentialsAuthenticationIsSelectedAndUsernameIsEmpty_ReturnsTrue(string username)
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Username = username;

testSubject.ShouldUsernameBeFilled.Should().BeTrue();
}

[TestMethod]
public void ShouldUsernameBeFilled_CredentialsAuthenticationIsSelectedAndUsernameIsFilled_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Username = "dummy username";

testSubject.ShouldUsernameBeFilled.Should().BeFalse();
}

[TestMethod]
public void ShouldUsernameBeFilled_TokenAuthenticationIsSelected_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.ShouldUsernameBeFilled.Should().BeFalse();
}

[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow(" ")]
public void ShouldPasswordBeFilled_CredentialsAuthenticationIsSelectedAndPasswordIsEmpty_ReturnsTrue(string password)
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Password = password.CreateSecureString();

testSubject.ShouldPasswordBeFilled.Should().BeTrue();
}

[TestMethod]
public void ShouldPasswordBeFilled_CredentialsAuthenticationIsSelectedAndPasswordIsFilled_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Password = "dummy password".CreateSecureString();

testSubject.ShouldPasswordBeFilled.Should().BeFalse();
}

[TestMethod]
public void ShouldPasswordBeFilled_TokenAuthenticationIsSelected_ReturnsFalse()
{
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

testSubject.ShouldPasswordBeFilled.Should().BeFalse();
}

[TestMethod]
public void AccountSecurityUrl_ConnectionIsSonarCloud_ReturnsSonarCloudUrl()
{
Expand All @@ -279,7 +118,6 @@ public void AccountSecurityUrl_ConnectionIsSonarQube_ReturnsSonarQubeUrl()
public async Task AdapterValidateConnectionAsync_TokenIsProvided_ShouldValidateConnectionWithToken()
{
MockAdapterValidateConnectionAsync();
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;
testSubject.Token = "dummyToken".CreateSecureString();

await testSubject.AdapterValidateConnectionAsync();
Expand All @@ -288,20 +126,6 @@ await slCoreConnectionAdapter.Received(1).ValidateConnectionAsync(testSubject.Co
Arg.Is<TokenCredentialsModel>(x => x.Token == testSubject.Token));
}

[TestMethod]
public async Task AdapterValidateConnectionAsync_CredentialsAreProvided_ShouldValidateConnectionWithToken()
{
MockAdapterValidateConnectionAsync();
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;
testSubject.Username = "username";
testSubject.Password = "password".CreateSecureString();

await testSubject.AdapterValidateConnectionAsync();

await slCoreConnectionAdapter.Received(1).ValidateConnectionAsync(testSubject.ConnectionInfo,
Arg.Is<UsernamePasswordModel>(x => x.Username == testSubject.Username && x.Password == testSubject.Password));
}

[TestMethod]
[DataRow(true)]
[DataRow(false)]
Expand Down Expand Up @@ -340,34 +164,16 @@ public void UpdateProgressStatus_RaisesEvents()
}

[TestMethod]
public void GetCredentialsModel_SelectedAuthenticationTypeIsToken_ReturnsModelWithToken()
public void GetCredentialsModel_ReturnsModelWithToken()
{
testSubject.Token = "token".CreateSecureString();
testSubject.Username = "username";
testSubject.Password = "password".CreateSecureString();
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionToken;

var credentialsModel = testSubject.GetCredentialsModel();

credentialsModel.Should().BeOfType<TokenCredentialsModel>();
((TokenCredentialsModel)credentialsModel).Token.Should().Be(testSubject.Token);
}

[TestMethod]
public void GetCredentialsModel_SelectedAuthenticationTypeIsCredentials_ReturnsModelWithUsernameAndPassword()
{
testSubject.Token = "token".CreateSecureString();
testSubject.Username = "username";
testSubject.Password = "password".CreateSecureString();
testSubject.SelectedAuthenticationType = UiResources.AuthenticationTypeOptionCredentials;

var credentialsModel = testSubject.GetCredentialsModel();

credentialsModel.Should().BeOfType<UsernamePasswordModel>();
((UsernamePasswordModel)credentialsModel).Username.Should().Be(testSubject.Username);
((UsernamePasswordModel)credentialsModel).Password.Should().Be(testSubject.Password);
}

private void MockAdapterValidateConnectionAsync(bool success = true)
{
slCoreConnectionAdapter.ValidateConnectionAsync(Arg.Any<ConnectionInfo>(), Arg.Any<ICredentialsModel>())
Expand Down
2 changes: 0 additions & 2 deletions src/ConnectedMode/ServerConnectionsRepositoryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ private static IConnectionCredentials MapCredentials(ICredentialsModel credentia
{
case TokenCredentialsModel tokenCredentialsModel:
return new TokenAuthCredentials(tokenCredentialsModel.Token);
case UsernamePasswordModel usernameCredentialsModel:
return new UsernameAndPasswordCredentials(usernameCredentialsModel.Username, usernameCredentialsModel.Password);
default:
return null;
}
Expand Down
Loading

0 comments on commit e12deaf

Please sign in to comment.