-
Notifications
You must be signed in to change notification settings - Fork 76
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
georgii-borovinskikh-sonarsource
merged 4 commits into
feature/sloop-rule-meta-data
from
gb/credentials-listener
Jan 25, 2024
Merged
Add CredentialsListener #5192
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9726f0f
Add CredentialsListener
georgii-borovinskikh-sonarsource 142ba39
Move class to separate file
georgii-borovinskikh-sonarsource 185383a
Delete file
georgii-borovinskikh-sonarsource b69d698
Add tests & fix bugs
georgii-borovinskikh-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/SLCore.UnitTests/Listener/Credentials/CredentialsListenerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
internal class CredentialsListener : ISLCoreListener | ||
{ | ||
|
||
} | ||
|
||
internal class GetCredentialsParams | ||
{ | ||
public GetCredentialsParams(string connectionId) | ||
{ | ||
this.connectionId = connectionId; | ||
} | ||
|
||
public string connectionId { get; } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?