Skip to content

Commit

Permalink
Trwalke/treat all warnings as errors (#537)
Browse files Browse the repository at this point in the history
* Integrated and enabled async analyzers from AsyncUsageAnalyzers.

* Resolving async errors.

* resolving errors.
Consolidated suppressions.

* Resolving Async Errors

* Resolving Async Errors

* Fixed spelling.

* Resolving build errors

* Fixing Async Errors

* Resolving Async Errors

* Fixing Async errors

* Fixed Async Errors

* Resolving Async errors.
Updating ruleset.

* Treating All warnings as errors

* Enabling for all platforms.
Resolving new errors.

* Converted anonymous method to local method.

* Updated name of callback to TaskCompletionCallback.

* Cleanup conflict errors.
  • Loading branch information
trwalke authored and jmprieur committed Mar 30, 2018
1 parent d19f4e9 commit e44ec08
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 52 deletions.
21 changes: 20 additions & 1 deletion GlobalSuppressions.cs
Expand Up @@ -3,9 +3,28 @@
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

//XForms
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~M:XForms.AcquirePage.OnAcquireClicked(System.Object,System.EventArgs)")]
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~M:XForms.AcquirePage.OnAcquireSilentlyClicked(System.Object,System.EventArgs)")]
[assembly: SuppressMessage("Microsoft.Security", "CA2140:TransparentMethodsMustNotReferenceCriticalCodeFxCopRule", Scope = "member", Target = "XForms.Droid.AcquirePageRenderer.#OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1<Xamarin.Forms.Page>)")]
[assembly: SuppressMessage("Microsoft.Security", "CA2140:TransparentMethodsMustNotReferenceCriticalCodeFxCopRule", Scope = "member", Target = "XForms.Droid.MainActivity.#OnCreate(Android.OS.Bundle)")]
[assembly: SuppressMessage("Microsoft.Security", "CA2140:TransparentMethodsMustNotReferenceCriticalCodeFxCopRule", Scope = "member", Target = "XForms.iOS.AppDelegate.#FinishedLaunching(UIKit.UIApplication,Foundation.NSDictionary)")]
[assembly: SuppressMessage("Microsoft.Security", "CA2140:TransparentMethodsMustNotReferenceCriticalCodeFxCopRule", Scope = "member", Target = "XForms.iOS.AcquirePageRenderer.#OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs)")]

//Desktop Test App
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~T:DesktopTestApp.MainForm(System.Object,System.EventArgs)")]

//Sample App
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~T:SampleApp.MainForm(System.Object,System.EventArgs)")]

//Microsoft.Identity.Client
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~M:Microsoft.Identity.Client.DispatcherTaskExtensions.RunTaskAsync``1(Windows.UI.Core.CoreDispatcher,System.Func{System.Threading.Tasks.Task{``0}},Windows.UI.Core.CoreDispatcherPriority)~System.Threading.Tasks.Task{``0}")]

//Automation
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "Reviewed", Scope = "member", Target = "~M:AutomationApp.AutomationUI.GoBtn_Click(System.Object,System.EventArgs)")]

//XForms
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "<Pending>", Scope = "member", Target = "~M:XForms.AcquirePage.OnAcquireClicked(System.Object,System.EventArgs)")]
[assembly: SuppressMessage("AsyncUsage.CSharp.Reliability", "AvoidAsyncVoid:Avoid async void", Justification = "<Pending>", Scope = "member", Target = "~M:XForms.AcquirePage.OnAcquireSilentlyClicked(System.Object,System.EventArgs)")]
Expand Down
4 changes: 2 additions & 2 deletions MSAL.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2020
VisualStudioVersion = 15.0.27130.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{34FFBC9F-C270-4B10-98C8-F6882606DDFE}"
EndProject
Expand Down Expand Up @@ -44,6 +44,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9F42F896-9CED-4B2E-B9F3-6CB54B532216}"
ProjectSection(SolutionItems) = preProject
ConfigureAwait.ruleset = ConfigureAwait.ruleset
GlobalSuppressions.cs = GlobalSuppressions.cs
EndProjectSection
EndProject
Global
Expand Down Expand Up @@ -106,7 +107,6 @@ Global
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|Win32.ActiveCfg = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|x64.ActiveCfg = Debug|Any CPU
{91E9E564-8A44-457B-A97C-E76C9F6275D6}.Debug|x64.Build.0 = Debug|Any CPU
Expand Down
1 change: 1 addition & 0 deletions samples/desktop/SampleApp/SampleApp.csproj
Expand Up @@ -11,6 +11,7 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
Expand Up @@ -48,6 +48,10 @@
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\ConfigureAwait.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net45|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<!-- This None is here so the conditionally included files show up in the Solution Explorer -->
<None Include="**\*.cs;**\*.xml;**\*.axml" Exclude="obj\**\*.*;bin\**\*.*" />
Expand Down
1 change: 1 addition & 0 deletions tests/AutomationApp/AutomationApp.csproj
Expand Up @@ -33,6 +33,7 @@
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>MSAL.snk</AssemblyOriginatorKeyFile>
Expand Down
4 changes: 2 additions & 2 deletions tests/AutomationApp/AutomationUI.cs
Expand Up @@ -57,13 +57,13 @@ public AutomationUI()

private void acquireToken_Click(object sender, EventArgs e)
{
_commandToRun = _tokenHandlerApp.AcquireToken;
_commandToRun = _tokenHandlerApp.AcquireTokenAsync;
pageControl1.SelectedTab = dataInputPage;
}

private void acquireTokenSilent_Click(object sender, EventArgs e)
{
_commandToRun = _tokenHandlerApp.AcquireTokenSilent;
_commandToRun = _tokenHandlerApp.AcquireTokenSilentAsync;
pageControl1.SelectedTab = dataInputPage;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/AutomationApp/TokenHandler.cs
Expand Up @@ -48,7 +48,7 @@ private void EnsurePublicClientApplication(Dictionary<string, string> input)
: new PublicClientApplication(input["client_id"]);
}

public async Task<AuthenticationResult> AcquireToken(Dictionary<string, string> input)
public async Task<AuthenticationResult> AcquireTokenAsync(Dictionary<string, string> input)
{
EnsurePublicClientApplication(input);

Expand All @@ -62,7 +62,7 @@ public async Task<AuthenticationResult> AcquireToken(Dictionary<string, string>
return result;
}

public async Task<AuthenticationResult> AcquireTokenSilent(Dictionary<string, string> input)
public async Task<AuthenticationResult> AcquireTokenSilentAsync(Dictionary<string, string> input)
{
EnsurePublicClientApplication(input);

Expand Down
1 change: 1 addition & 0 deletions tests/Test.MSAL.NET.Unit/Test.MSAL.NET.Unit.csproj
Expand Up @@ -100,6 +100,7 @@
</None>
</ItemGroup>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>..\..\ConfigureAwait.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/dev apps/DesktopTestApp/DesktopTestApp.csproj
Expand Up @@ -33,6 +33,7 @@
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>MSAL.snk</AssemblyOriginatorKeyFile>
Expand Down
7 changes: 4 additions & 3 deletions tests/dev apps/DesktopTestApp/MainForm.cs
Expand Up @@ -155,7 +155,8 @@ private async void acquireTokenInteractive_Click(object sender, EventArgs e)

try
{
AuthenticationResult authenticationResult = await _publicClientHandler.AcquireTokenInteractive(scopes.Text.AsArray(), GetUIBehavior(), _publicClientHandler.ExtraQueryParams, new UIParent()).ConfigureAwait(false);
AuthenticationResult authenticationResult = await _publicClientHandler.AcquireTokenInteractiveAsync(scopes.Text.AsArray(), GetUIBehavior(), _publicClientHandler.ExtraQueryParams, new UIParent()).ConfigureAwait(false);

SetResultPageInfo(authenticationResult);
RefreshUserList();
}
Expand All @@ -182,7 +183,7 @@ private async void acquireTokenSilent_Click(object sender, EventArgs e)
try
{
AuthenticationResult authenticationResult =
await _publicClientHandler.AcquireTokenSilent(scopes.Text.AsArray()).ConfigureAwait(false);
await _publicClientHandler.AcquireTokenSilentAsync(scopes.Text.AsArray()).ConfigureAwait(false);

SetResultPageInfo(authenticationResult);
}
Expand Down Expand Up @@ -210,7 +211,7 @@ private async void acquireTokenInteractiveAuthority_Click(object sender, EventAr

try
{
AuthenticationResult authenticationResult = await _publicClientHandler.AcquireTokenInteractiveWithAuthority(scopes.Text.AsArray(), GetUIBehavior(), _publicClientHandler.ExtraQueryParams, new UIParent()).ConfigureAwait(false);
AuthenticationResult authenticationResult = await _publicClientHandler.AcquireTokenInteractiveWithAuthorityAsync(scopes.Text.AsArray(), GetUIBehavior(), _publicClientHandler.ExtraQueryParams, new UIParent()).ConfigureAwait(false);

SetResultPageInfo(authenticationResult);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/dev apps/DesktopTestApp/PublicClientHandler.cs
Expand Up @@ -61,7 +61,7 @@ public PublicClientHandler(string clientId)

#endregion

public async Task<AuthenticationResult> AcquireTokenInteractive(string[] scopes, UIBehavior uiBehavior, string extraQueryParams, UIParent uiParent)
public async Task<AuthenticationResult> AcquireTokenInteractiveAsync(string[] scopes, UIBehavior uiBehavior, string extraQueryParams, UIParent uiParent)
{
CreatePublicClientApplication(InteractiveAuthority, ApplicationId);

Expand All @@ -84,7 +84,7 @@ public async Task<AuthenticationResult> AcquireTokenInteractive(string[] scopes,
return result;
}

public async Task<AuthenticationResult> AcquireTokenInteractiveWithAuthority(string[] scopes, UIBehavior uiBehavior, string extraQueryParams, UIParent uiParent)
public async Task<AuthenticationResult> AcquireTokenInteractiveWithAuthorityAsync(string[] scopes, UIBehavior uiBehavior, string extraQueryParams, UIParent uiParent)
{
CreatePublicClientApplication(InteractiveAuthority, ApplicationId);

Expand All @@ -107,7 +107,7 @@ public async Task<AuthenticationResult> AcquireTokenInteractiveWithAuthority(str
return result;
}

public async Task<AuthenticationResult> AcquireTokenSilent(string[] scopes)
public async Task<AuthenticationResult> AcquireTokenSilentAsync(string[] scopes)
{
return await PublicClientApplication.AcquireTokenSilentAsync(scopes, CurrentUser, AuthorityOverride,
false).ConfigureAwait(false);
Expand Down
1 change: 1 addition & 0 deletions tests/dev apps/NetCoreTestApp/NetCoreTestApp.csproj
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -117,7 +117,7 @@ private string GetCurrentUserId()
}

[HttpGet]
public async Task<string> Get()
public async Task<string> GetAsync()
{
await Semaphore.WaitAsync().ConfigureAwait(false);
try
Expand All @@ -136,7 +136,7 @@ public async Task<string> Get()
await GetConfidentialClient().AcquireTokenOnBehalfOfAsync(new[] {MsGraphUserReadScope},
userAssertion).ConfigureAwait(false);

result = await CallApi(MsGraphMeQuery, authResult.AccessToken).ConfigureAwait(false);
result = await CallApiAsync(MsGraphMeQuery, authResult.AccessToken).ConfigureAwait(false);
}
catch (MsalException ex)
{
Expand All @@ -155,7 +155,7 @@ public async Task<string> Get()
}
}

private static async Task<string> CallApi(string apiUrl, string accessToken)
private static async Task<string> CallApiAsync(string apiUrl, string accessToken)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
Expand Down
1 change: 1 addition & 0 deletions tests/dev apps/WebTestApp/WebApi/WebApi.csproj
Expand Up @@ -34,6 +34,7 @@
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\..\..\ConfigureAwait.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" />
Expand Down
Expand Up @@ -37,7 +37,7 @@ public class AccountController : Controller
{
// GET: /Account/Login
[HttpGet]
public async Task Login(string returnUrl = null)
public async Task LoginAsync(string returnUrl = null)
{
if (HttpContext.User == null || !HttpContext.User.Identity.IsAuthenticated)
{
Expand All @@ -48,7 +48,7 @@ public async Task Login(string returnUrl = null)

// GET: /Account/LogOff
[HttpGet]
public async Task LogOff()
public async Task LogOffAsync()
{
if (HttpContext.User.Identity.IsAuthenticated)
{
Expand All @@ -59,7 +59,7 @@ public async Task LogOff()
}
}

public async Task EndSession()
public async Task EndSessionAsync()
{
// If AAD sends a single sign-out message to the app, end the user's session, but don't redirect to AAD for sign out.
await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme).ConfigureAwait(false);
Expand Down
22 changes: 11 additions & 11 deletions tests/dev apps/WebTestApp/WebApp/Controllers/HomeController.cs
Expand Up @@ -108,7 +108,7 @@ private static string GetFormattedLog()

[Authorize]
[HttpGet]
public async Task<IActionResult> CallGraphMeQuery()
public async Task<IActionResult> CallGraphMeQueryAsync()
{
await semaphore.WaitAsync().ConfigureAwait(false);
try
Expand All @@ -124,7 +124,7 @@ public async Task<IActionResult> CallGraphMeQuery()
HttpContext.Session, ConfidentialClientUtils.CreateSecretClientCredential(),
GetCurrentUserId()).ConfigureAwait(false);

result = await CallApi(MsGraphMeQuery, authenticationResult.AccessToken).ConfigureAwait(false);
result = await CallApiAsync(MsGraphMeQuery, authenticationResult.AccessToken).ConfigureAwait(false);
}
catch (MsalException ex)
{
Expand Down Expand Up @@ -168,19 +168,19 @@ public ActionResult AdminConsent(string admin_consent, string tenant, string err

[Authorize]
[HttpGet]
public async Task<IActionResult> CallGraphUsersQueryBySecretClientCredential()
public async Task<IActionResult> CallGraphUsersQueryBySecretClientCredentialAsync()
{
return await CallGraphUsersQuery(ConfidentialClientUtils.CreateSecretClientCredential()).ConfigureAwait(false);
return await CallGraphUsersQueryAsync(ConfidentialClientUtils.CreateSecretClientCredential()).ConfigureAwait(false);
}

[Authorize]
[HttpGet]
public async Task<IActionResult> CallGraphUsersQueryByCertClientCredential()
public async Task<IActionResult> CallGraphUsersQueryByCertClientCredentialAsync()
{
return await CallGraphUsersQuery(ConfidentialClientUtils.CreateClientCertificateCredential()).ConfigureAwait(false);
return await CallGraphUsersQueryAsync(ConfidentialClientUtils.CreateClientCertificateCredential()).ConfigureAwait(false);
}

private async Task<IActionResult> CallGraphUsersQuery(ClientCredential clientCredential)
private async Task<IActionResult> CallGraphUsersQueryAsync(ClientCredential clientCredential)
{
await semaphore.WaitAsync().ConfigureAwait(false);
try
Expand All @@ -195,7 +195,7 @@ private async Task<IActionResult> CallGraphUsersQuery(ClientCredential clientCre
clientCredential,
GetCurrentUserId()).ConfigureAwait(false);

result = await CallApi(MsGraphUsersQuery, authenticationResult.AccessToken).ConfigureAwait(false);
result = await CallApiAsync(MsGraphUsersQuery, authenticationResult.AccessToken).ConfigureAwait(false);
}
catch (MsalException ex)
{
Expand All @@ -216,7 +216,7 @@ private async Task<IActionResult> CallGraphUsersQuery(ClientCredential clientCre

[Authorize]
[HttpGet]
public async Task<IActionResult> CallWebApiUserProfileQuery()
public async Task<IActionResult> CallWebApiUserProfileQueryAsync()
{
await semaphore.WaitAsync().ConfigureAwait(false);
try
Expand All @@ -232,7 +232,7 @@ public async Task<IActionResult> CallWebApiUserProfileQuery()
HttpContext.Session, ConfidentialClientUtils.CreateSecretClientCredential(),
GetCurrentUserId()).ConfigureAwait(false);

result = await CallApi(WebApiUserProfileQuery, authenticationResult.AccessToken).ConfigureAwait(false);
result = await CallApiAsync(WebApiUserProfileQuery, authenticationResult.AccessToken).ConfigureAwait(false);
}
catch (MsalException ex)
{
Expand All @@ -251,7 +251,7 @@ public async Task<IActionResult> CallWebApiUserProfileQuery()
}
}

private static async Task<string> CallApi(string apiUrl, string accessToken)
private static async Task<string> CallApiAsync(string apiUrl, string accessToken)
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, apiUrl);
Expand Down
8 changes: 4 additions & 4 deletions tests/dev apps/WebTestApp/WebApp/Startup.cs
Expand Up @@ -129,8 +129,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
GetClaimsFromUserInfoEndpoint = false,
Events = new OpenIdConnectEvents
{
OnRemoteFailure = OnAuthenticationFailed,
OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
OnRemoteFailure = OnAuthenticationFailedAsync,
OnAuthorizationCodeReceived = OnAuthorizationCodeReceivedAsync,
OnRedirectToIdentityProvider = context =>
{
foreach (var entry in ExtraParamsDictionary)
Expand Down Expand Up @@ -164,7 +164,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
});
}

private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
private async Task OnAuthorizationCodeReceivedAsync(AuthorizationCodeReceivedContext context)
{
string[] scopes = { "User.Read" };

Expand All @@ -179,7 +179,7 @@ private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext


// Handle sign-in errors differently than generic errors.
private Task OnAuthenticationFailed(FailureContext context)
private Task OnAuthenticationFailedAsync(FailureContext context)
{
context.HandleResponse();
context.Response.Redirect("/Home/Error?message=" + context.Failure.Message);
Expand Down
1 change: 1 addition & 0 deletions tests/dev apps/WebTestApp/WebApp/WebApp.csproj
Expand Up @@ -48,6 +48,7 @@
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\..\..\ConfigureAwait.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" />
Expand Down
2 changes: 2 additions & 0 deletions tests/dev apps/XForms/XForms.Android/AcquirePageRenderer.cs
Expand Up @@ -45,6 +45,7 @@

namespace XForms.Droid
{
#pragma warning disable CS0618
internal class AcquirePageRenderer : PageRenderer
{
AcquirePage _page;
Expand All @@ -60,4 +61,5 @@ protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
var activity = this.Context as Activity;
}
}
#pragma warning restore CS0618
}

0 comments on commit e44ec08

Please sign in to comment.