Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CredentialsListener #5192

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Threading.Tasks;
using SonarLint.VisualStudio.SLCore.Core;
using SonarLint.VisualStudio.SLCore.Listener.Credentials;
using SonarLint.VisualStudio.TestInfrastructure;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Listener.Credentials;

[TestClass]
public class CredentialsListenerTests
{
[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<CredentialsListener, ISLCoreListener>();
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<CredentialsListener>();
}

[TestMethod]
public async Task GetCredentialsAsync_StubImpl_ReturnsNoCredentials()
{
var testSubject = CreateTestSubject();

var response = await testSubject.GetCredentialsAsync(new GetCredentialsParams($"randomstring-{Guid.NewGuid()}"));

response.Should().BeSameAs(GetCredentialsResponse.NoCredentials);
}

private CredentialsListener CreateTestSubject()
{
return new CredentialsListener();
}
}
32 changes: 32 additions & 0 deletions src/SLCore/Common/Models/TokenDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.SLCore.Common.Models
{
public class TokenDto
{
public TokenDto(string token)
{
this.token = token;
}

public string token { get; }
}
}
34 changes: 34 additions & 0 deletions src/SLCore/Common/Models/UsernamePasswordDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.SLCore.Common.Models
{
public class UsernamePasswordDto
{
public UsernamePasswordDto(string username, string password)
{
this.username = username;
this.password = password;
}

public string username { get; }
public string password { get; }
}
}
74 changes: 74 additions & 0 deletions src/SLCore/Listener/Credentials/CredentialsListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.ComponentModel.Composition;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SonarLint.VisualStudio.SLCore.Common.Models;
using SonarLint.VisualStudio.SLCore.Core;
using SonarLint.VisualStudio.SLCore.Protocol;

namespace SonarLint.VisualStudio.SLCore.Listener.Credentials
{
/// <summary>
/// Credentials provider for SLCore
/// </summary>
[Export(typeof(ISLCoreListener))]
[PartCreationPolicy(CreationPolicy.Shared)]
internal class CredentialsListener : ISLCoreListener
{
public Task<GetCredentialsResponse> GetCredentialsAsync(GetCredentialsParams parameters)
{
// stub implementation
return Task.FromResult(GetCredentialsResponse.NoCredentials);
}
}

internal class GetCredentialsParams
{
public GetCredentialsParams(string connectionId)
{
this.connectionId = connectionId;
}

public string connectionId { get; }
}

internal class GetCredentialsResponse
{
// credentials property is nullable on the SLCore side
public static GetCredentialsResponse NoCredentials = new GetCredentialsResponse();

private GetCredentialsResponse(){}

public GetCredentialsResponse(TokenDto token)
{
this.credentials = Either<TokenDto, UsernamePasswordDto>.CreateLeft(token);
}

public GetCredentialsResponse(UsernamePasswordDto usernamePassword)
{
this.credentials = Either<TokenDto, UsernamePasswordDto>.CreateRight(usernamePassword);
}

[JsonConverter(typeof(Either<TokenDto, UsernamePasswordDto>))]
public Either<TokenDto, UsernamePasswordDto> credentials { get; }
}
}
39 changes: 39 additions & 0 deletions src/SLCore/Listener/CredentialsListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using SonarLint.VisualStudio.SLCore.Core;

namespace SonarLint.VisualStudio.SLCore.Listener
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be here or some leftover?

{
internal class CredentialsListener : ISLCoreListener
{

}

internal class GetCredentialsParams
{
public GetCredentialsParams(string connectionId)
{
this.connectionId = connectionId;
}

public string connectionId { get; }
}
}
Loading