From c8a6c3d2723bfc75286350f3f84e0ff082b8abeb Mon Sep 17 00:00:00 2001 From: Bogdan Gavril Date: Sun, 5 Jan 2025 13:33:29 +0000 Subject: [PATCH] Fix all warnings and treat warnings as errors (#5041) * Fix all warnings and treat warnings as errors * ignore cs3009 on android * Update template-build-and-prep-automation.yaml * Add Any CPU build configurations to solution. * Update NetCoreWinFormsWam path in YAML * test fixes * fix * move * 2 * 2 * more * 3 * fix * fix * fix * fix --------- Co-authored-by: Gladwin Johnson <90415114+gladjohn@users.noreply.github.com> Co-authored-by: Gladwin Johnson --- Directory.Build.props | 1 + Directory.Packages.props | 4 +- LibsAndSamples.sln | 40 +-- build/platform_and_feature_flags.props | 5 +- src/Directory.Build.props | 1 + .../Microsoft.Identity.Client.Broker.csproj | 4 - .../MsalCachePersistenceException.cs | 1 + .../Microsoft.Identity.Client.csproj | 1 + .../Broker/AndroidAccountManagerBroker.cs | 2 + .../Android/Broker/AndroidBrokerHelper.cs | 2 + .../AuthenticationAgentActivity.cs | 2 + .../Platforms/iOS/Broker/iOSBroker.cs | 1 + .../Platforms/iOS/CoreCustomUrlProtocol.cs | 4 +- .../iOS/EmbeddedWebview/EmbeddedWebUI.cs | 4 +- .../WKWebNavigationDelegate.cs | 2 + ...cationPresentationContextProviderWindow.cs | 2 + .../iOS/SystemWebview/SystemWebUI.cs | 4 + .../iOS/iOSLegacyCachePersistance.cs | 4 + .../Platforms/iOS/iOSTokenCacheAccessor.cs | 2 + .../PublicApi/net462/PublicAPI.Shipped.txt | 2 - .../PublicApi/net472/PublicAPI.Shipped.txt | 2 - .../net8.0-android/PublicAPI.Shipped.txt | 2 - .../net8.0-ios/PublicAPI.Shipped.txt | 2 - .../PublicApi/net8.0/PublicAPI.Shipped.txt | 2 - .../netstandard2.0/PublicAPI.Shipped.txt | 2 - .../json/.editorconfig | 3 +- .../json/JsonException.cs | 4 +- .../json/Serialization/FormatterConverter.cs | 4 +- .../Serialization/JsonFormatterConverter.cs | 4 +- .../json/Serialization/JsonObjectContract.cs | 4 +- .../JsonSerializerInternalReader.cs | 2 + .../JsonSerializerInternalWriter.cs | 4 +- .../json/Serialization/JsonTypeReflector.cs | 4 + .../Core/Mocks/MockHttpMessageHandler.cs | 9 +- .../ApiConfigTests/AuthorityAliasesTests.cs | 188 +++++----- .../BrokerTests/BrokerRequestTests.cs | 18 +- .../CacheFallbackOperationsTests.cs | 5 - .../AuthenticationOperationTests.cs | 2 - .../ClientCredentialWithRegionTests.cs | 327 +++++++++--------- .../InteractiveRequestOrchestrationTests.cs | 47 +-- .../TelemetryTests/HttpTelemetryTests.cs | 10 +- tests/devapps/Directory.Packages.props | 2 + .../AzureFunction/AquireToken.cs | 2 +- .../AzureFunction/GetEnvironmentVariables.cs | 4 +- .../WAMMauiApp/WAMMauiApp/AppShell.xaml.cs | 5 +- .../WAMMauiApp/WAMMauiApp/WAMMauiApp.csproj | 4 +- tests/devapps/WebApi/Misc/TestSize.cs | 68 ---- 47 files changed, 380 insertions(+), 438 deletions(-) delete mode 100644 tests/devapps/WebApi/Misc/TestSize.cs diff --git a/Directory.Build.props b/Directory.Build.props index 3e88500497..a26b191823 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,6 +10,7 @@ true false + true diff --git a/Directory.Packages.props b/Directory.Packages.props index d523737aa9..dfb0f023f4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -56,8 +56,8 @@ - - + + diff --git a/LibsAndSamples.sln b/LibsAndSamples.sln index a968596645..fbc61c55eb 100644 --- a/LibsAndSamples.sln +++ b/LibsAndSamples.sln @@ -554,7 +554,7 @@ Global {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug + MobileApps|x86.ActiveCfg = Debug + MobileApps|Any CPU {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug + MobileApps|x86.Build.0 = Debug + MobileApps|Any CPU {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|Any CPU.Build.0 = Debug|Any CPU {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|ARM.ActiveCfg = Debug|Any CPU {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|ARM.Build.0 = Debug|Any CPU {24D2AF71-A01E-4450-8C3F-B9923A81134B}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -609,7 +609,7 @@ Global {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Debug|x86.ActiveCfg = Debug|Any CPU {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Debug|x86.Build.0 = Debug|Any CPU {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|Any CPU.ActiveCfg = Release|Any CPU - {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|Any CPU.Build.0 = Release|Any CPU + {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|Any CPU.Build.0 = Release|Any CPU {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|ARM.ActiveCfg = Release|Any CPU {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|ARM.Build.0 = Release|Any CPU {959A47D9-07E7-4BF3-A0F7-6D9CD42A2C46}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -721,7 +721,7 @@ Global {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug + MobileApps|x86.ActiveCfg = Debug + MobileApps|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug + MobileApps|x86.Build.0 = Debug + MobileApps|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|ARM.ActiveCfg = Debug|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|ARM.Build.0 = Debug|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -735,7 +735,7 @@ Global {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|x86.ActiveCfg = Debug|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Debug|x86.Build.0 = Debug|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|Any CPU.Build.0 = Release|Any CPU + {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|Any CPU.Build.0 = Release|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|ARM.ActiveCfg = Release|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|ARM.Build.0 = Release|Any CPU {E7EB3226-D0F5-4A93-87DC-FAAC9A24D684}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -763,7 +763,7 @@ Global {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug + MobileApps|x86.ActiveCfg = Debug + MobileApps|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug + MobileApps|x86.Build.0 = Debug + MobileApps|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|Any CPU.Build.0 = Debug|Any CPU + {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|Any CPU.Build.0 = Debug|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|ARM.ActiveCfg = Debug|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|ARM.Build.0 = Debug|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -777,7 +777,7 @@ Global {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|x86.ActiveCfg = Debug|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Debug|x86.Build.0 = Debug|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|Any CPU.ActiveCfg = Release|Any CPU - {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|Any CPU.Build.0 = Release|Any CPU + {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|Any CPU.Build.0 = Release|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|ARM.ActiveCfg = Release|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|ARM.Build.0 = Release|Any CPU {339E0B2B-4408-4947-B134-E8C5AAB11286}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -805,7 +805,7 @@ Global {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug + MobileApps|x86.ActiveCfg = Debug + MobileApps|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug + MobileApps|x86.Build.0 = Debug + MobileApps|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|ARM.ActiveCfg = Debug|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|ARM.Build.0 = Debug|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -819,7 +819,7 @@ Global {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|x86.ActiveCfg = Debug|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Debug|x86.Build.0 = Debug|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|Any CPU.Build.0 = Release|Any CPU + {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|Any CPU.Build.0 = Release|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|ARM.ActiveCfg = Release|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|ARM.Build.0 = Release|Any CPU {2AF48872-DD47-4DA1-A153-DF4DA13882C2}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -1014,7 +1014,7 @@ Global {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug + MobileApps|x86.ActiveCfg = Debug + MobileApps|Any CPU {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug + MobileApps|x86.Build.0 = Debug + MobileApps|Any CPU {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|ARM.ActiveCfg = Debug|Any CPU {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|ARM.Build.0 = Debug|Any CPU {998D38B3-344C-4F19-833E-6181B0834AF6}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -1182,7 +1182,7 @@ Global {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug + MobileApps|x86.ActiveCfg = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug + MobileApps|x86.Build.0 = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|ARM.ActiveCfg = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|ARM.Build.0 = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -1196,7 +1196,7 @@ Global {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|x86.ActiveCfg = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Debug|x86.Build.0 = Debug|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|Any CPU.Build.0 = Release|Any CPU + {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|Any CPU.Build.0 = Release|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|ARM.ActiveCfg = Release|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|ARM.Build.0 = Release|Any CPU {3A2042E9-8B03-4F2D-A2B7-EA4BEC36340C}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -1231,8 +1231,8 @@ Global {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug + MobileApps|x86.Build.0 = Debug|x86 {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug + MobileApps|x86.Deploy.0 = Debug|x86 {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|ARM.ActiveCfg = Debug|ARM {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|ARM.Build.0 = Debug|ARM {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|ARM.Deploy.0 = Debug|ARM @@ -1252,8 +1252,8 @@ Global {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|x86.Build.0 = Debug|x86 {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Debug|x86.Deploy.0 = Debug|x86 {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|Any CPU.Build.0 = Release|Any CPU - {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|Any CPU.Deploy.0 = Release|Any CPU + {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|Any CPU.Build.0 = Release|Any CPU + {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|Any CPU.Deploy.0 = Release|Any CPU {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|ARM.ActiveCfg = Release|ARM {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|ARM.Build.0 = Release|ARM {34E323E8-E706-4DF4-B916-D614FC8CFCEB}.Release|ARM.Deploy.0 = Release|ARM @@ -1371,7 +1371,7 @@ Global {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug + MobileApps|x86.ActiveCfg = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug + MobileApps|x86.Build.0 = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|Any CPU.Build.0 = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|ARM.ActiveCfg = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|ARM.Build.0 = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -1385,7 +1385,7 @@ Global {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|x86.ActiveCfg = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Debug|x86.Build.0 = Debug|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|Any CPU.Build.0 = Release|Any CPU + {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|Any CPU.Build.0 = Release|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|ARM.ActiveCfg = Release|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|ARM.Build.0 = Release|Any CPU {B381269F-44DA-4E46-8F51-1F1DF7D1F61D}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -1413,7 +1413,7 @@ Global {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug + MobileApps|x86.ActiveCfg = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug + MobileApps|x86.Build.0 = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|Any CPU.Build.0 = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|ARM.ActiveCfg = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|ARM.Build.0 = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|ARM64.ActiveCfg = Debug|Any CPU @@ -1427,7 +1427,7 @@ Global {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|x86.ActiveCfg = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Debug|x86.Build.0 = Debug|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|Any CPU.Build.0 = Release|Any CPU + {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|Any CPU.Build.0 = Release|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|ARM.ActiveCfg = Release|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|ARM.Build.0 = Release|Any CPU {4EA542D2-D4C9-403C-B615-0047D0A62790}.Release|ARM64.ActiveCfg = Release|Any CPU @@ -1455,7 +1455,7 @@ Global {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug + MobileApps|x86.ActiveCfg = Debug|Any CPU {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug + MobileApps|x86.Build.0 = Debug|Any CPU {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|ARM.ActiveCfg = Debug|Any CPU {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|ARM.Build.0 = Debug|Any CPU {1B047736-9325-4F59-906B-89A3E12AC8FB}.Debug|ARM64.ActiveCfg = Debug|Any CPU diff --git a/build/platform_and_feature_flags.props b/build/platform_and_feature_flags.props index df7137cee9..4d52be6563 100644 --- a/build/platform_and_feature_flags.props +++ b/build/platform_and_feature_flags.props @@ -1,9 +1,6 @@ - $(DefineConstants);NET_CORE;SUPPORTS_CONFIDENTIAL_CLIENT;SUPPORTS_CUSTOM_CACHE;SUPPORTS_BROKER;SUPPORTS_WIN32; - - - $(DefineConstants);SUPPORTS_SYSTEM_TEXT_JSON + $(DefineConstants);SUPPORTS_SYSTEM_TEXT_JSON;NET_CORE;SUPPORTS_CONFIDENTIAL_CLIENT;SUPPORTS_CUSTOM_CACHE;SUPPORTS_BROKER;SUPPORTS_WIN32; $(DefineConstants);SUPPORTS_OTEL; diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 46bfce3c44..d2054177b4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -25,6 +25,7 @@ true AnyCPU + diff --git a/src/client/Microsoft.Identity.Client.Broker/Microsoft.Identity.Client.Broker.csproj b/src/client/Microsoft.Identity.Client.Broker/Microsoft.Identity.Client.Broker.csproj index a7a45f606e..8786e8c800 100644 --- a/src/client/Microsoft.Identity.Client.Broker/Microsoft.Identity.Client.Broker.csproj +++ b/src/client/Microsoft.Identity.Client.Broker/Microsoft.Identity.Client.Broker.csproj @@ -27,10 +27,6 @@ true - - $(DefineConstants);NET_CORE - - diff --git a/src/client/Microsoft.Identity.Client.Extensions.Msal/MsalCachePersistenceException.cs b/src/client/Microsoft.Identity.Client.Extensions.Msal/MsalCachePersistenceException.cs index a61839b33a..47d81564a5 100644 --- a/src/client/Microsoft.Identity.Client.Extensions.Msal/MsalCachePersistenceException.cs +++ b/src/client/Microsoft.Identity.Client.Extensions.Msal/MsalCachePersistenceException.cs @@ -41,6 +41,7 @@ public MsalCachePersistenceException(string message, Exception innerException) : /// /// /// + [Obsolete] protected MsalCachePersistenceException(SerializationInfo info, StreamingContext context) : base(info, context) { } diff --git a/src/client/Microsoft.Identity.Client/Microsoft.Identity.Client.csproj b/src/client/Microsoft.Identity.Client/Microsoft.Identity.Client.csproj index b4b0d2797b..86ebb3de3b 100644 --- a/src/client/Microsoft.Identity.Client/Microsoft.Identity.Client.csproj +++ b/src/client/Microsoft.Identity.Client/Microsoft.Identity.Client.csproj @@ -53,6 +53,7 @@ $(DefineConstants);HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;$(AdditionalConstants) + $(NoWarn);CS3009 diff --git a/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidAccountManagerBroker.cs b/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidAccountManagerBroker.cs index b94dbf31c8..21176836e7 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidAccountManagerBroker.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidAccountManagerBroker.cs @@ -151,7 +151,9 @@ private Intent CreateIntentFromInteractiveBundle(Bundle accountManagerResult, Br _logger.Info("[Android broker] Android account manager didn't return any results for interactive broker request. "); } +#pragma warning disable CA1422 // Validate platform compatibility Intent interactiveIntent = (Intent)accountManagerResult?.GetParcelable(AccountManager.KeyIntent); +#pragma warning restore CA1422 // Validate platform compatibility // Validate that the intent was created successfully. if (interactiveIntent != null) diff --git a/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidBrokerHelper.cs b/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidBrokerHelper.cs index 560b78627d..3784ea8edc 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidBrokerHelper.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/Android/Broker/AndroidBrokerHelper.cs @@ -210,6 +210,7 @@ private string GetRedirectUriForBroker() return string.Empty; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1422:Validate platform compatibility", Justification = "")] private string GetCurrentSignatureForPackage(string packageName) { try @@ -347,6 +348,7 @@ private void VerifyCertificateChain(List certificates) } } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1422:Validate platform compatibility", Justification = "")] private List ReadCertDataForBrokerApp(string brokerPackageName) { #pragma warning disable CS0618 // Type or member is obsolete https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1854 diff --git a/src/client/Microsoft.Identity.Client/Platforms/Android/EmbeddedWebview/AuthenticationAgentActivity.cs b/src/client/Microsoft.Identity.Client/Platforms/Android/EmbeddedWebview/AuthenticationAgentActivity.cs index 49b0b29bc0..3cb4e573eb 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/Android/EmbeddedWebview/AuthenticationAgentActivity.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/Android/EmbeddedWebview/AuthenticationAgentActivity.cs @@ -90,7 +90,9 @@ public override void OnLoadResource(WebView view, string url) } [Obsolete] // because parent is obsolete +#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member public override bool ShouldOverrideUrlLoading(WebView view, string url) +#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member { Uri uri = new Uri(url); if (url.StartsWith(BrokerConstants.BrowserExtPrefix, StringComparison.OrdinalIgnoreCase)) diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/Broker/iOSBroker.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/Broker/iOSBroker.cs index 3e5177daa8..f5be2a9da0 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/Broker/iOSBroker.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/Broker/iOSBroker.cs @@ -178,6 +178,7 @@ private Dictionary CreateBrokerRequestDictionary( return brokerRequest; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1422:Validate platform compatibility", Justification = "")] public void HandleInstallUrl(string appLink) { DispatchQueue.MainQueue.DispatchAsync(() => UIApplication.SharedApplication.OpenUrl(new NSUrl(appLink))); diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/CoreCustomUrlProtocol.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/CoreCustomUrlProtocol.cs index 3b0d10aafc..ce6dc888ee 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/CoreCustomUrlProtocol.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/CoreCustomUrlProtocol.cs @@ -22,7 +22,7 @@ public static bool canInitWithRequest(NSUrlRequest request) } [Export("canonicalRequestForRequest:")] - public new static NSUrlRequest GetCanonicalRequest(NSUrlRequest request) + public static new NSUrlRequest GetCanonicalRequest(NSUrlRequest request) { return request; } @@ -45,7 +45,9 @@ public override void StartLoading() NSMutableUrlRequest mutableRequest = (NSMutableUrlRequest)Request.MutableCopy(); SetProperty(new NSString("YES"), "ADURLProtocol", mutableRequest); +#pragma warning disable CA1422 // Validate platform compatibility connection = new NSUrlConnection(mutableRequest, new CoreCustomConnectionDelegate(this), true); +#pragma warning restore CA1422 // Validate platform compatibility } public override void StopLoading() diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/EmbeddedWebUI.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/EmbeddedWebUI.cs index 0979932ff6..39ac1aa7aa 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/EmbeddedWebUI.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/EmbeddedWebUI.cs @@ -17,7 +17,7 @@ internal class EmbeddedWebUI : WebviewBase public RequestContext RequestContext { get; internal set; } public CoreUIParent CoreUIParent { get; set; } - public async override Task AcquireAuthorizationAsync( + public override async Task AcquireAuthorizationAsync( Uri authorizationUri, Uri redirectUri, RequestContext requestContext, @@ -46,7 +46,9 @@ public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext r UIViewController viewController = null; InvokeOnMainThread(() => { +#pragma warning disable CA1422 // Validate platform compatibility UIWindow window = UIApplication.SharedApplication.KeyWindow; +#pragma warning restore CA1422 // Validate platform compatibility viewController = CoreUIParent.FindCurrentViewController(window.RootViewController); }); diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/WKWebNavigationDelegate.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/WKWebNavigationDelegate.cs index 529f8ef790..8518a4a36f 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/WKWebNavigationDelegate.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/EmbeddedWebview/WKWebNavigationDelegate.cs @@ -41,8 +41,10 @@ public override void DecidePolicy(WKWebView webView, WKNavigationAction navigati }; requestUrlString = httpsUrlBuilder.Uri.AbsoluteUri; +#pragma warning disable CA1422 // Validate platform compatibility DispatchQueue.MainQueue.DispatchAsync( () => UIApplication.SharedApplication.OpenUrl(new NSUrl(requestUrlString))); +#pragma warning restore CA1422 // Validate platform compatibility _authenticationAgentUIViewController.DismissViewController(true, null); decisionHandler(WKNavigationActionPolicy.Cancel); return; diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/ASWebAuthenticationPresentationContextProviderWindow.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/ASWebAuthenticationPresentationContextProviderWindow.cs index f887fd0147..e2cbbe7594 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/ASWebAuthenticationPresentationContextProviderWindow.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/ASWebAuthenticationPresentationContextProviderWindow.cs @@ -10,7 +10,9 @@ internal class ASWebAuthenticationPresentationContextProviderWindow : NSObject, { public UIWindow GetPresentationAnchor(ASWebAuthenticationSession session) { +#pragma warning disable CA1422 // Validate platform compatibility return UIApplication.SharedApplication.KeyWindow; +#pragma warning restore CA1422 // Validate platform compatibility } } } diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/SystemWebUI.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/SystemWebUI.cs index 319976123d..457fdb46f9 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/SystemWebUI.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/SystemWebview/SystemWebUI.cs @@ -34,7 +34,9 @@ public override async Task AcquireAuthorizationAsync( s_viewController = null; InvokeOnMainThread(() => { +#pragma warning disable CA1422 // Validate platform compatibility UIWindow window = UIApplication.SharedApplication.KeyWindow; +#pragma warning restore CA1422 // Validate platform compatibility s_viewController = CoreUIParent.FindCurrentViewController(window.RootViewController); }); @@ -59,6 +61,7 @@ public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext r { if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) { +#pragma warning disable CA1422 // Validate platform compatibility asWebAuthenticationSession = new AuthenticationServices.ASWebAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri), redirectUri.Scheme, (callbackUrl, error) => { @@ -71,6 +74,7 @@ public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext r ContinueAuthentication(callbackUrl.ToString(), RequestContext.Logger); } }); +#pragma warning restore CA1422 // Validate platform compatibility asWebAuthenticationSession.BeginInvokeOnMainThread(() => { diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSLegacyCachePersistance.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSLegacyCachePersistance.cs index 27f22d22e2..d55f8cdf35 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSLegacyCachePersistance.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSLegacyCachePersistance.cs @@ -38,6 +38,7 @@ byte[] ILegacyCachePersistence.LoadCache() try { SecStatusCode res; +#pragma warning disable CA1422 // Validate platform compatibility var rec = new SecRecord(SecKind.GenericPassword) { Generic = NSData.FromString(LocalSettingsContainerName), @@ -48,6 +49,7 @@ byte[] ILegacyCachePersistence.LoadCache() Comment = NAME + " Cache", Description = "Storage for cache" }; +#pragma warning restore CA1422 // Validate platform compatibility if (_keychainGroup != null) { @@ -73,6 +75,7 @@ void ILegacyCachePersistence.WriteCache(byte[] serializedCache) { try { +#pragma warning disable CA1422 // Validate platform compatibility var s = new SecRecord(SecKind.GenericPassword) { Generic = NSData.FromString(LocalSettingsContainerName), @@ -83,6 +86,7 @@ void ILegacyCachePersistence.WriteCache(byte[] serializedCache) Comment = NAME + " Cache", Description = "Storage for cache" }; +#pragma warning restore CA1422 // Validate platform compatibility if (_keychainGroup != null) { diff --git a/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSTokenCacheAccessor.cs b/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSTokenCacheAccessor.cs index 1121735ba6..47dddc5cdb 100644 --- a/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSTokenCacheAccessor.cs +++ b/src/client/Microsoft.Identity.Client/Platforms/iOS/iOSTokenCacheAccessor.cs @@ -43,12 +43,14 @@ public void SetiOSKeychainSecurityGroup(string keychainSecurityGroup) private string GetTeamId() { +#pragma warning disable CA1422 // Validate platform compatibility var queryRecord = new SecRecord(SecKind.GenericPassword) { Service = "", Account = TeamIdKey, Accessible = SecAccessible.Always }; +#pragma warning restore CA1422 // Validate platform compatibility SecRecord match = SecKeyChain.QueryAsRecord(queryRecord, out SecStatusCode resultCode); diff --git a/src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Shipped.txt index 9adb851e13..b1abb73154 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Shipped.txt @@ -365,8 +365,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Shipped.txt index 9adb851e13..b1abb73154 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Shipped.txt @@ -365,8 +365,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Shipped.txt index 35b6b0f84a..803a599f94 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Shipped.txt @@ -366,8 +366,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Shipped.txt index 05c745d913..eacc22c5ca 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Shipped.txt @@ -370,8 +370,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Shipped.txt index ee3ecd7359..7296019d5d 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Shipped.txt @@ -362,8 +362,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Shipped.txt b/src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Shipped.txt index 20837e021c..bbcea292de 100644 --- a/src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Shipped.txt +++ b/src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Shipped.txt @@ -362,8 +362,6 @@ Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.get -> Micr Microsoft.Identity.Client.AuthenticationResultMetadata.RegionDetails.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.Telemetry.set -> void -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.get -> int -Microsoft.Identity.Client.AuthenticationResultMetadata.TelemetryTokenType.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.get -> string Microsoft.Identity.Client.AuthenticationResultMetadata.TokenEndpoint.set -> void Microsoft.Identity.Client.AuthenticationResultMetadata.TokenSource.get -> Microsoft.Identity.Client.TokenSource diff --git a/src/client/Microsoft.Identity.Client/json/.editorconfig b/src/client/Microsoft.Identity.Client/json/.editorconfig index 2400220bc0..903c3bb67f 100644 --- a/src/client/Microsoft.Identity.Client/json/.editorconfig +++ b/src/client/Microsoft.Identity.Client/json/.editorconfig @@ -29,5 +29,4 @@ dotnet_diagnostic.IDE0036.severity = none dotnet_diagnostic.VSTHRD200.severity = none -dotnet_diagnostic.SYSLIB0050.severity = none -dotnet_diagnostic.SYSLIB0051.severity = none +dotnet_diagnostic.RS0017.severity = error diff --git a/src/client/Microsoft.Identity.Client/json/JsonException.cs b/src/client/Microsoft.Identity.Client/json/JsonException.cs index ba4a2c89f9..48116a50e5 100644 --- a/src/client/Microsoft.Identity.Client/json/JsonException.cs +++ b/src/client/Microsoft.Identity.Client/json/JsonException.cs @@ -77,7 +77,9 @@ public JsonException(string message, Exception? innerException) /// The parameter is null. /// The class name is null or is zero (0). public JsonException(SerializationInfo info, StreamingContext context) +#pragma warning disable SYSLIB0051 // Type or member is obsolete : base(info, context) +#pragma warning restore SYSLIB0051 // Type or member is obsolete { } #endif @@ -89,4 +91,4 @@ internal static JsonException Create(IJsonLineInfo lineInfo, string path, string return new JsonException(message); } } -} \ No newline at end of file +} diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/FormatterConverter.cs b/src/client/Microsoft.Identity.Client/json/Serialization/FormatterConverter.cs index ab953a2f67..9bfc661ce5 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/FormatterConverter.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/FormatterConverter.cs @@ -8,7 +8,9 @@ namespace Microsoft.Identity.Json.Serialization { +#pragma warning disable SYSLIB0050 // Type or member is obsolete internal class FormatterConverter : IFormatterConverter +#pragma warning restore SYSLIB0050 // Type or member is obsolete { public object Convert(object value, Type type) { @@ -114,4 +116,4 @@ public ulong ToUInt64(object value) } } -#endif \ No newline at end of file +#endif diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/JsonFormatterConverter.cs b/src/client/Microsoft.Identity.Client/json/Serialization/JsonFormatterConverter.cs index 80db8aa775..09417194ed 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/JsonFormatterConverter.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/JsonFormatterConverter.cs @@ -32,7 +32,9 @@ namespace Microsoft.Identity.Json.Serialization { +#pragma warning disable SYSLIB0050 // Type or member is obsolete internal class JsonFormatterConverter : IFormatterConverter +#pragma warning restore SYSLIB0050 // Type or member is obsolete { private readonly JsonSerializerInternalReader _reader; private readonly JsonISerializableContract _contract; @@ -154,4 +156,4 @@ public ulong ToUInt64(object value) } } -#endif \ No newline at end of file +#endif diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/JsonObjectContract.cs b/src/client/Microsoft.Identity.Client/json/Serialization/JsonObjectContract.cs index 75369510a0..12a490e6eb 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/JsonObjectContract.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/JsonObjectContract.cs @@ -192,8 +192,10 @@ internal object GetUninitializedObject() throw new JsonException("Insufficient permissions. Creating an uninitialized '{0}' type requires full trust.".FormatWith(CultureInfo.InvariantCulture, NonNullableUnderlyingType)); } +#pragma warning disable SYSLIB0050 // Type or member is obsolete return FormatterServices.GetUninitializedObject(NonNullableUnderlyingType); +#pragma warning restore SYSLIB0050 // Type or member is obsolete } #endif } -} \ No newline at end of file +} diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalReader.cs b/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalReader.cs index eb4f517a0c..e545a0a8a4 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalReader.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalReader.cs @@ -1743,7 +1743,9 @@ private object CreateISerializable(JsonReader reader, JsonISerializableContract TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Deserializing {0} using ISerializable constructor.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType)), null); } +#pragma warning disable SYSLIB0050 // Type or member is obsolete SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new JsonFormatterConverter(this, contract, member)); +#pragma warning restore SYSLIB0050 // Type or member is obsolete bool finished = false; do diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalWriter.cs b/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalWriter.cs index e93b072d1a..cc20276521 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalWriter.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/JsonSerializerInternalWriter.cs @@ -869,8 +869,10 @@ private void SerializeISerializable(JsonWriter writer, ISerializable value, Json WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty); +#pragma warning disable SYSLIB0050 // Type or member is obsolete SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter()); value.GetObjectData(serializationInfo, Serializer._context); +#pragma warning restore SYSLIB0050 // Type or member is obsolete foreach (SerializationEntry serializationEntry in serializationInfo) { @@ -1241,4 +1243,4 @@ private bool IsSpecified(JsonWriter writer, JsonProperty property, object target return isSpecified; } } -} \ No newline at end of file +} diff --git a/src/client/Microsoft.Identity.Client/json/Serialization/JsonTypeReflector.cs b/src/client/Microsoft.Identity.Client/json/Serialization/JsonTypeReflector.cs index 8498a8e73f..a64dac73e1 100644 --- a/src/client/Microsoft.Identity.Client/json/Serialization/JsonTypeReflector.cs +++ b/src/client/Microsoft.Identity.Client/json/Serialization/JsonTypeReflector.cs @@ -396,10 +396,12 @@ public static bool IsNonSerializable(object provider) // no inheritance return (ReflectionUtils.GetAttribute(provider, false) != null); #else +#pragma warning disable SYSLIB0050 // Type or member is obsolete if (provider is FieldInfo fieldInfo && (fieldInfo.Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized) { return true; } +#pragma warning restore SYSLIB0050 // Type or member is obsolete return false; #endif @@ -413,10 +415,12 @@ public static bool IsSerializable(object provider) // no inheritance return (ReflectionUtils.GetAttribute(provider, false) != null); #else +#pragma warning disable SYSLIB0050 // Type or member is obsolete if (provider is Type type && (type.GetTypeInfo().Attributes & TypeAttributes.Serializable) == TypeAttributes.Serializable) { return true; } +#pragma warning restore SYSLIB0050 // Type or member is obsolete return false; #endif diff --git a/tests/Microsoft.Identity.Test.Common/Core/Mocks/MockHttpMessageHandler.cs b/tests/Microsoft.Identity.Test.Common/Core/Mocks/MockHttpMessageHandler.cs index 1b25c4cb14..5b1fb2293b 100644 --- a/tests/Microsoft.Identity.Test.Common/Core/Mocks/MockHttpMessageHandler.cs +++ b/tests/Microsoft.Identity.Test.Common/Core/Mocks/MockHttpMessageHandler.cs @@ -38,8 +38,9 @@ internal class MockHttpMessageHandler : HttpClientHandler public HttpRequestHeaders ActualRequestHeaders { get; private set; } public X509Certificate2 ExpectedMtlsBindingCertificate { get; set; } - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { + ActualRequestMessage = request; if (ExceptionToThrow != null) @@ -66,7 +67,7 @@ protected override Task SendAsync(HttpRequestMessage reques ValidateQueryParams(uri); - ValidatePostDataAsync(request); + await ValidatePostDataAsync(request).ConfigureAwait(false); ValidateNotExpectedPostData(); @@ -74,7 +75,9 @@ protected override Task SendAsync(HttpRequestMessage reques AdditionalRequestValidation?.Invoke(request); - return new TaskFactory().StartNew(() => ResponseMessage, cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); + + return ResponseMessage; } private void ValidateQueryParams(Uri uri) diff --git a/tests/Microsoft.Identity.Test.Unit/ApiConfigTests/AuthorityAliasesTests.cs b/tests/Microsoft.Identity.Test.Unit/ApiConfigTests/AuthorityAliasesTests.cs index 949b30d73f..e007e3ebfc 100644 --- a/tests/Microsoft.Identity.Test.Unit/ApiConfigTests/AuthorityAliasesTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/ApiConfigTests/AuthorityAliasesTests.cs @@ -29,111 +29,111 @@ public async Task AuthorityMigrationTestAsync() // make sure that for all network calls "preferred_cache" environment is used // (it is taken from metadata in instance discovery response), // except very first network call - instance discovery - - using var harness = CreateTestHarness(); - - var httpManager = harness.HttpManager; - var authorityUri = new Uri( - string.Format( - CultureInfo.InvariantCulture, - "https://{0}/common", - TestConstants.ProductionNotPrefEnvironmentAlias)); - - httpManager.AddInstanceDiscoveryMockHandler(authorityUri.AbsoluteUri); - - PublicClientApplication app = PublicClientApplicationBuilder.Create(TestConstants.ClientId) - .WithAuthority(authorityUri, validateAuthority: true) - .WithHttpManager(httpManager) - .WithDebugLoggingCallback() - .BuildConcrete(); - - InMemoryTokenCache cache = new InMemoryTokenCache(); - cache.Bind(app.UserTokenCache); - - app.ServiceBundle.ConfigureMockWebUI( - AuthorizationResult.FromUri(app.AppConfig.RedirectUri + "?code=some-code"), - null, - TestConstants.ProductionPrefNetworkEnvironment); - - // mock token request - httpManager.AddMockHandler(new MockHttpMessageHandler + using (var harness = CreateTestHarness()) { - ExpectedUrl = string.Format(CultureInfo.InvariantCulture, "https://{0}/common/oauth2/v2.0/token", - TestConstants.ProductionPrefNetworkEnvironment), - ExpectedMethod = HttpMethod.Post, - ResponseMessage = MockHelpers.CreateSuccessTokenResponseMessage() - }); + var httpManager = harness.HttpManager; + var authorityUri = new Uri( + string.Format( + CultureInfo.InvariantCulture, + "https://{0}/common", + TestConstants.ProductionNotPrefEnvironmentAlias)); + + httpManager.AddInstanceDiscoveryMockHandler(authorityUri.AbsoluteUri); + + PublicClientApplication app = PublicClientApplicationBuilder.Create(TestConstants.ClientId) + .WithAuthority(authorityUri, validateAuthority: true) + .WithHttpManager(httpManager) + .WithDebugLoggingCallback() + .BuildConcrete(); + + InMemoryTokenCache cache = new InMemoryTokenCache(); + cache.Bind(app.UserTokenCache); + + app.ServiceBundle.ConfigureMockWebUI( + AuthorizationResult.FromUri(app.AppConfig.RedirectUri + "?code=some-code"), + null, + TestConstants.ProductionPrefNetworkEnvironment); + + // mock token request + httpManager.AddMockHandler(new MockHttpMessageHandler + { + ExpectedUrl = string.Format(CultureInfo.InvariantCulture, "https://{0}/common/oauth2/v2.0/token", + TestConstants.ProductionPrefNetworkEnvironment), + ExpectedMethod = HttpMethod.Post, + ResponseMessage = MockHelpers.CreateSuccessTokenResponseMessage() + }); - AuthenticationResult result = await app.AcquireTokenInteractive(TestConstants.s_scope).ExecuteAsync().ConfigureAwait(false); + AuthenticationResult result = await app.AcquireTokenInteractive(TestConstants.s_scope).ExecuteAsync().ConfigureAwait(false); - // make sure that all cache entities are stored with "preferred_cache" environment - // (it is taken from metadata in instance discovery response) - ValidateCacheEntitiesEnvironment(app.UserTokenCacheInternal, TestConstants.ProductionPrefCacheEnvironment); + // make sure that all cache entities are stored with "preferred_cache" environment + // (it is taken from metadata in instance discovery response) + ValidateCacheEntitiesEnvironment(app.UserTokenCacheInternal, TestConstants.ProductionPrefCacheEnvironment); - // silent request targeting at, should return at from cache for any environment alias - foreach (var envAlias in TestConstants.s_prodEnvAliases) - { - var app2 = PublicClientApplicationBuilder.Create(TestConstants.ClientId) - .WithAuthority($"https://{envAlias}/common", validateAuthority: true) - .WithHttpManager(httpManager) - .WithDebugLoggingCallback() - .BuildConcrete(); - - cache.Bind(app2.UserTokenCache); - - IEnumerable accounts = await app.GetAccountsAsync().ConfigureAwait(false); - result = await app2.AcquireTokenSilent(TestConstants.s_scope, accounts.First()) - .WithTenantId(TestConstants.Utid) - .WithForceRefresh(false) - .ExecuteAsync(CancellationToken.None) - .ConfigureAwait(false); - - Assert.IsNotNull(result); - } - - // silent request targeting rt should find rt in cache for authority with any environment alias - foreach (var envAlias in TestConstants.s_prodEnvAliases) - { - result = null; + // silent request targeting at, should return at from cache for any environment alias + foreach (var envAlias in TestConstants.s_prodEnvAliases) + { + var app2 = PublicClientApplicationBuilder.Create(TestConstants.ClientId) + .WithAuthority($"https://{envAlias}/common", validateAuthority: true) + .WithHttpManager(httpManager) + .WithDebugLoggingCallback() + .BuildConcrete(); + + cache.Bind(app2.UserTokenCache); + + IEnumerable accounts = await app.GetAccountsAsync().ConfigureAwait(false); + result = await app2.AcquireTokenSilent(TestConstants.s_scope, accounts.First()) + .WithTenantId(TestConstants.Utid) + .WithForceRefresh(false) + .ExecuteAsync(CancellationToken.None) + .ConfigureAwait(false); + + Assert.IsNotNull(result); + } httpManager.AddMockHandler( - new MockHttpMessageHandler - { - ExpectedUrl = string.Format(CultureInfo.InvariantCulture, "https://{0}/{1}/oauth2/v2.0/token", - TestConstants.ProductionPrefNetworkEnvironment, TestConstants.Utid), - ExpectedMethod = HttpMethod.Post, - ExpectedPostData = new Dictionary + new MockHttpMessageHandler { + ExpectedUrl = string.Format(CultureInfo.InvariantCulture, "https://{0}/{1}/oauth2/v2.0/token", + TestConstants.ProductionPrefNetworkEnvironment, TestConstants.Utid), + ExpectedMethod = HttpMethod.Post, + ExpectedPostData = new Dictionary + { { "grant_type", "refresh_token" } - }, - // return not retriable status code - ResponseMessage = MockHelpers.CreateInvalidGrantTokenResponseMessage() - }); + }, + // return not retriable status code + ResponseMessage = MockHelpers.CreateInvalidGrantTokenResponseMessage() + }); - try - { - var app3 = PublicClientApplicationBuilder - .Create(TestConstants.ClientId) - .WithAuthority($"https://{envAlias}/common", true) - .WithHttpManager(httpManager) - .WithDebugLoggingCallback() - .BuildConcrete(); - - cache.Bind(app3.UserTokenCache); - - result = await app3 - .AcquireTokenSilent( - TestConstants.s_scopeForAnotherResource, - (await app.GetAccountsAsync().ConfigureAwait(false)).First()) - .WithTenantId(TestConstants.Utid) - .WithForceRefresh(false) - .ExecuteAsync(CancellationToken.None).ConfigureAwait(false); - } - catch (MsalUiRequiredException) + // silent request targeting rt should find rt in cache for authority with any environment alias + foreach (var envAlias in TestConstants.s_prodEnvAliases) { - } + result = null; + + try + { + var app3 = PublicClientApplicationBuilder + .Create(TestConstants.ClientId) + .WithAuthority($"https://{envAlias}/common", true) + .WithHttpManager(httpManager) + .WithDebugLoggingCallback() + .BuildConcrete(); + + cache.Bind(app3.UserTokenCache); + + result = await app3 + .AcquireTokenSilent( + TestConstants.s_scopeForAnotherResource, + (await app.GetAccountsAsync().ConfigureAwait(false)).First()) + .WithTenantId(TestConstants.Utid) + .WithForceRefresh(false) + .ExecuteAsync(CancellationToken.None).ConfigureAwait(false); + } + catch (MsalUiRequiredException) + { + } - Assert.IsNull(result); + Assert.IsNull(result); + } } } diff --git a/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs b/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs index fb14ef463c..9439b34dd9 100644 --- a/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/BrokerTests/BrokerRequestTests.cs @@ -517,7 +517,6 @@ public async Task NullBroker_AcquireSilentInteractive_Async() var app = builder.BuildConcrete(); builder.Config.BrokerCreatorFunc = (_, _, logger) => { return new NullBroker(logger); }; - // Act try { @@ -618,7 +617,6 @@ public async Task BrokerGetAccountsWithBrokerInstalledTestAsync() Assert.AreSame(expectedAccount, actualAccount.Single()); } - [TestMethod] public async Task SilentAuthStrategyFallbackTestAsync() { @@ -652,8 +650,8 @@ public async Task SilentAuthStrategyFallbackTestAsync() var noAccountException = new MsalClientException(MsalError.NoAccountForLoginHint); var noTokensException = new MsalClientException(MsalError.NoTokensFoundError); - mockBrokerStrategy.ExecuteAsync(default).Returns(brokerAuthenticationResult); - mockClientStrategy.ExecuteAsync(default).Throws(invalidGrantException); + mockBrokerStrategy.ExecuteAsync(default).Returns(Task.FromResult(brokerAuthenticationResult)); + mockClientStrategy.ExecuteAsync(default).Returns(Task.FromException(invalidGrantException)); _acquireTokenSilentParameters.Account = new Account("a.b", "user", "lmo"); //Execute silent request with invalid grant @@ -669,14 +667,14 @@ public async Task SilentAuthStrategyFallbackTestAsync() //Execute silent request with no accounts exception mockClientStrategy = Substitute.For(); - mockClientStrategy.ExecuteAsync(new CancellationToken()).Throws(noAccountException); + mockClientStrategy.ExecuteAsync(new CancellationToken()).Returns(Task.FromException(noAccountException)); silentRequest = new SilentRequest(harness.ServiceBundle, _parameters, _acquireTokenSilentParameters, mockClientStrategy, mockBrokerStrategy); result = silentRequest.ExecuteTestAsync(new CancellationToken()).Result; Assert.AreEqual(result, brokerAuthenticationResult); //Execute silent request with no tokens exception mockClientStrategy = Substitute.For(); - mockClientStrategy.ExecuteAsync(new CancellationToken()).Throws(noTokensException); + mockClientStrategy.ExecuteAsync(new CancellationToken()).Returns(Task.FromException(noTokensException)); silentRequest = new SilentRequest(harness.ServiceBundle, _parameters, _acquireTokenSilentParameters, mockClientStrategy, mockBrokerStrategy); result = silentRequest.ExecuteTestAsync(new CancellationToken()).Result; Assert.AreEqual(result, brokerAuthenticationResult); @@ -702,9 +700,9 @@ public void SpecialAccount_CallsBrokerSilentAuth() var mockBrokerStrategy = Substitute.For(); var ar = new AuthenticationResult(); - mockClientStrategy.ExecuteAsync(default).ThrowsForAnyArgs( - new MsalUiRequiredException(MsalError.CurrentBrokerAccount, "msg")); - mockBrokerStrategy.ExecuteAsync(default).Returns(ar); + mockClientStrategy.ExecuteAsync(default).ReturnsForAnyArgs( + Task.FromException(new MsalUiRequiredException(MsalError.CurrentBrokerAccount, "msg"))); + mockBrokerStrategy.ExecuteAsync(default).Returns(Task.FromResult(ar)); _acquireTokenSilentParameters.Account = PublicClientApplication.OperatingSystemAccount; var silentRequest = new SilentRequest( harness.ServiceBundle, @@ -844,10 +842,8 @@ public async Task MultiCloud_WithBroker_Async() builder.Config.BrokerCreatorFunc = (_, _, _) => broker; - var globalPca = builder.BuildConcrete(); - // Setup the broker to return AuthorityUrl in the MsalTokenResponse as different cloud broker.IsBrokerInstalledAndInvokable(AuthorityType.Aad).Returns(true); diff --git a/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheFallbackOperationsTests.cs b/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheFallbackOperationsTests.cs index 95a1105de0..c04a02fc9e 100644 --- a/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheFallbackOperationsTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheFallbackOperationsTests.cs @@ -413,8 +413,6 @@ public void RemoveAdalUser_RemovesUserNoClientInfo_And_NoDisplayName() // Assert AssertCacheEntryCount(6); - - _logger.Received().Error(Arg.Is(MsalErrorMessage.InternalErrorCacheEmptyUsername)); } [TestMethod] @@ -493,9 +491,6 @@ public void WriteAdalRefreshToken_ErrorLog() "scope1"); // Assert - _logger.Received().Error(Arg.Is(CacheFallbackOperations.DifferentAuthorityError)); - - _logger.Received().Error(Arg.Is(CacheFallbackOperations.DifferentEnvError)); } [TestMethod] diff --git a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/AuthenticationOperationTests.cs b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/AuthenticationOperationTests.cs index 735e9d5f7c..c72ca62deb 100644 --- a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/AuthenticationOperationTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/AuthenticationOperationTests.cs @@ -166,8 +166,6 @@ public async Task WrongTokenType_Async() authScheme.AuthorizationHeaderPrefix.Returns("BearToken"); authScheme.KeyId.Returns("keyid"); authScheme.GetTokenRequestParams().Returns(new Dictionary() { { "tokenParam", "tokenParamValue" } }); - // When FormatResult is called, change the AccessToken property - authScheme.WhenForAnyArgs(x => x.FormatResult(default)).Do(x => x[0] = "enhanced_secret_" + ((AuthenticationResult)x[0]).AccessToken); using (var httpManager = new MockHttpManager()) { diff --git a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithRegionTests.cs b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithRegionTests.cs index d17541943f..3faf999645 100644 --- a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithRegionTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/ClientCredentialWithRegionTests.cs @@ -22,35 +22,32 @@ public class ConfidentialClientWithRegionTests : TestBase { public const string EastUsRegion = "eastus"; - [TestCleanup] - public override void TestCleanup() - { - Environment.SetEnvironmentVariable("REGION_NAME", null); - } - [TestMethod] // regression for #2837 public async Task AuthorityOverrideAndRegionalAsync() { - const string region = "eastus"; - Environment.SetEnvironmentVariable("REGION_NAME", region); + using (new EnvVariableContext()) + { + const string region = "eastus"; + Environment.SetEnvironmentVariable("REGION_NAME", region); - var app = ConfidentialClientApplicationBuilder - .Create(TestConstants.ClientId) - .WithAzureRegion(ConfidentialClientApplication.AttemptRegionDiscovery) - .WithClientSecret(TestConstants.ClientSecret) - .Build(); + var app = ConfidentialClientApplicationBuilder + .Create(TestConstants.ClientId) + .WithAzureRegion(ConfidentialClientApplication.AttemptRegionDiscovery) + .WithClientSecret(TestConstants.ClientSecret) + .Build(); #pragma warning disable CS0618 // Type or member is obsolete - var ex = await AssertException.TaskThrowsAsync(() => - app - .AcquireTokenForClient(TestConstants.s_scope) - .WithAuthority("https://login.microsoft.com/17b189bc-2b81-4ec5-aa51-3e628cbc931b") + var ex = await AssertException.TaskThrowsAsync(() => + app + .AcquireTokenForClient(TestConstants.s_scope) + .WithAuthority("https://login.microsoft.com/17b189bc-2b81-4ec5-aa51-3e628cbc931b") #pragma warning restore CS0618 // Type or member is obsolete - .ExecuteAsync()) - .ConfigureAwait(false); + .ExecuteAsync()) + .ConfigureAwait(false); - Assert.AreEqual(MsalError.RegionalAndAuthorityOverride, ex.ErrorCode); + Assert.AreEqual(MsalError.RegionalAndAuthorityOverride, ex.ErrorCode); + } } [TestMethod] @@ -58,10 +55,12 @@ public async Task AuthorityOverrideAndRegionalAsync() public async Task TenantIdOverrideAndRegionalAsync() { // Arrange - Environment.SetEnvironmentVariable("REGION_NAME", EastUsRegion); - using (var harness = new MockHttpAndServiceBundle()) + using (new EnvVariableContext()) + using (var harness = base.CreateTestHarness()) { + Environment.SetEnvironmentVariable("REGION_NAME", EastUsRegion); + var tokenHttpCallHandler = new MockHttpMessageHandler() { // Asserts @@ -98,14 +97,15 @@ public async Task FetchRegionFromLocalImdsCallAsync() { const string region = "centralus"; - using (var httpManager = new MockHttpManager()) + using (new EnvVariableContext()) + using (var harness = base.CreateTestHarness()) { - httpManager.AddRegionDiscoveryMockHandler(TestConstants.Region); + harness.HttpManager.AddRegionDiscoveryMockHandler(TestConstants.Region); IConfidentialClientApplication app = CreateCca( - httpManager, + harness.HttpManager, ConfidentialClientApplication.AttemptRegionDiscovery); - httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); + harness.HttpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); AuthenticationResult result = await app .AcquireTokenForClient(TestConstants.s_scope) @@ -139,7 +139,7 @@ public async Task FetchRegionFromLocalImdsCallAsync() Assert.IsNull(result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); // try again, with force refresh, region should be from cache - httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); + harness.HttpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); result = await app .AcquireTokenForClient(TestConstants.s_scope) .WithForceRefresh(true) @@ -157,10 +157,10 @@ public async Task FetchRegionFromLocalImdsCallAsync() // try again, create a new app, result should still be from cache IConfidentialClientApplication app2 = CreateCca( - httpManager, + harness.HttpManager, ConfidentialClientApplication.AttemptRegionDiscovery); - httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); + harness.HttpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); result = await app2 .AcquireTokenForClient(TestConstants.s_scope) .ExecuteAsync(CancellationToken.None) @@ -181,8 +181,9 @@ public async Task FetchRegionFromLocalImdsCallAsync() [Description("Tokens between regional and non-regional are interchangeable.")] public async Task TokensAreInterchangable_Regional_To_NonRegional_Async() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; httpManager.AddRegionDiscoveryMockHandler(TestConstants.Region); httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); @@ -231,36 +232,31 @@ public async Task TokensAreInterchangable_Regional_To_NonRegional_Async() [Description("Test when region is received from environment variable")] public async Task FetchRegionFromEnvironmentAsync() { - using (var httpManager = new MockHttpManager()) + using (new EnvVariableContext()) + using (var harness = base.CreateTestHarness()) { - try - { - Environment.SetEnvironmentVariable("REGION_NAME", TestConstants.Region); - IConfidentialClientApplication app = CreateCca( - httpManager, - ConfidentialClientApplication.AttemptRegionDiscovery); + var httpManager = harness.HttpManager; + Environment.SetEnvironmentVariable("REGION_NAME", TestConstants.Region); + IConfidentialClientApplication app = CreateCca( + httpManager, + ConfidentialClientApplication.AttemptRegionDiscovery); - httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); + httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); - AuthenticationResult result = await app - .AcquireTokenForClient(TestConstants.s_scope) - .ExecuteAsync(CancellationToken.None) - .ConfigureAwait(false); + AuthenticationResult result = await app + .AcquireTokenForClient(TestConstants.s_scope) + .ExecuteAsync(CancellationToken.None) + .ConfigureAwait(false); - Assert.AreEqual(TestConstants.Region, result.ApiEvent.RegionUsed); - Assert.AreEqual(TestConstants.Region, result.ApiEvent.AutoDetectedRegion); - Assert.AreEqual(RegionAutodetectionSource.EnvVariable, result.ApiEvent.RegionAutodetectionSource); - Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.ApiEvent.RegionOutcome); - Assert.AreEqual(TestConstants.Region, result.AuthenticationResultMetadata.RegionDetails.RegionUsed); - Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); - Assert.IsNull(result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); - Assert.IsNotNull(result.AccessToken); + Assert.AreEqual(TestConstants.Region, result.ApiEvent.RegionUsed); + Assert.AreEqual(TestConstants.Region, result.ApiEvent.AutoDetectedRegion); + Assert.AreEqual(RegionAutodetectionSource.EnvVariable, result.ApiEvent.RegionAutodetectionSource); + Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.ApiEvent.RegionOutcome); + Assert.AreEqual(TestConstants.Region, result.AuthenticationResultMetadata.RegionDetails.RegionUsed); + Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); + Assert.IsNull(result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); + Assert.IsNotNull(result.AccessToken); - } - finally - { - Environment.SetEnvironmentVariable("REGION_NAME", null); - } } } @@ -268,8 +264,10 @@ public async Task FetchRegionFromEnvironmentAsync() [Description("Test when the region could not be fetched -> fallback to global.")] public async Task RegionFallbackToGlobalAsync() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + httpManager.AddRegionDiscoveryMockHandlerNotFound(); httpManager.AddInstanceDiscoveryMockHandler(); httpManager.AddMockHandler(CreateTokenResponseHttpHandler(false)); @@ -278,28 +276,22 @@ public async Task RegionFallbackToGlobalAsync() httpManager, ConfidentialClientApplication.AttemptRegionDiscovery); - try - { - AuthenticationResult result = await app - .AcquireTokenForClient(TestConstants.s_scope) - .ExecuteAsync(CancellationToken.None) - .ConfigureAwait(false); + AuthenticationResult result = await app + .AcquireTokenForClient(TestConstants.s_scope) + .ExecuteAsync(CancellationToken.None) + .ConfigureAwait(false); + + Assert.IsNotNull(result.AccessToken); - Assert.IsNotNull(result.AccessToken); + Assert.AreEqual(null, result.ApiEvent.RegionUsed); + Assert.IsNull(result.ApiEvent.AutoDetectedRegion); + Assert.AreEqual(RegionAutodetectionSource.FailedAutoDiscovery, result.ApiEvent.RegionAutodetectionSource); + Assert.AreEqual(RegionOutcome.FallbackToGlobal, result.ApiEvent.RegionOutcome); + Assert.IsNull(result.AuthenticationResultMetadata.RegionDetails.RegionUsed); + Assert.AreEqual(RegionOutcome.FallbackToGlobal, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); + Assert.IsTrue(result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError + .Contains(TestConstants.RegionDiscoveryIMDSCallFailedMessage)); - Assert.AreEqual(null, result.ApiEvent.RegionUsed); - Assert.IsNull(result.ApiEvent.AutoDetectedRegion); - Assert.AreEqual(RegionAutodetectionSource.FailedAutoDiscovery, result.ApiEvent.RegionAutodetectionSource); - Assert.AreEqual(RegionOutcome.FallbackToGlobal, result.ApiEvent.RegionOutcome); - Assert.IsNull(result.AuthenticationResultMetadata.RegionDetails.RegionUsed); - Assert.AreEqual(RegionOutcome.FallbackToGlobal, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); - Assert.IsTrue(result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError - .Contains(TestConstants.RegionDiscoveryIMDSCallFailedMessage)); - } - catch (MsalServiceException) - { - Assert.Fail("Fallback to global failed."); - } } } @@ -307,8 +299,10 @@ public async Task RegionFallbackToGlobalAsync() public async Task MsalForceRegionIsSet_RegionIsUsed() { using (new EnvVariableContext()) - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + Environment.SetEnvironmentVariable( ConfidentialClientApplicationBuilder.ForceRegionEnvVariable, TestConstants.Region); @@ -339,8 +333,10 @@ public async Task MsalForceRegionIsSet_RegionIsUsed() public async Task MsalForceRegionIsSet_WithRegionIsSet_WithRegionWins() { using (new EnvVariableContext()) - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + // this will be ignored, in favor of TestConstants.Region Environment.SetEnvironmentVariable( ConfidentialClientApplicationBuilder.ForceRegionEnvVariable, "someOtherRegion"); @@ -373,8 +369,10 @@ public async Task MsalForceRegionIsSet_WithRegionIsSet_WithRegionWins() public async Task MsalForceRegionIsSet_WithRegionIsSetToOptOut_NoRegionIsUsed() { using (new EnvVariableContext()) - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + Environment.SetEnvironmentVariable( ConfidentialClientApplicationBuilder.ForceRegionEnvVariable, TestConstants.Region); @@ -422,8 +420,10 @@ public async Task OtherCloudWithAuthorityValidationAsync() const string imdsError = "IMDS call failed with exception"; const string autoDiscoveryError = "Auto-discovery failed in the past. Not trying again. IMDS call failed"; - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + httpManager.AddRegionDiscoveryMockHandlerNotFound(); var discoveryHandler = MockHelpers.CreateInstanceDiscoveryMockHandler( @@ -489,86 +489,13 @@ public async Task OtherCloudWithAuthorityValidationAsync() // regression: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2686 public async Task OtherCloud_WithValidation_Async(bool validateAuthority, bool authorityIsValid) { - try - { - Environment.SetEnvironmentVariable("REGION_NAME", "eastus"); - - await RunPpeTestAsync(validateAuthority, authorityIsValid).ConfigureAwait(false); - - } - finally - { - Environment.SetEnvironmentVariable("REGION_NAME", null); - } - - } - [DataTestMethod] - [DataRow("login.partner.microsoftonline.cn", "login.partner.microsoftonline.cn")] - [DataRow("login.chinacloudapi.cn", "login.partner.microsoftonline.cn")] - [DataRow("login.microsoftonline.us", "login.microsoftonline.us")] - [DataRow("login.usgovcloudapi.net", "login.microsoftonline.us")] - [DataRow("login-us.microsoftonline.com", "login-us.microsoftonline.com")] - [DataRow("login.windows.net", "login.microsoft.com")] - [DataRow("login.microsoft.com", "login.microsoft.com")] - [DataRow("sts.windows.net", "login.microsoft.com")] - [DataRow("login.microsoftonline.com", "login.microsoft.com")] - public async Task PublicAndSovereignCloud_UsesPreferredNetwork_AndNoDiscovery_Async(string inputEnv, string expectedEnv) - { - try - { - Environment.SetEnvironmentVariable("REGION_NAME", EastUsRegion); - - using (var harness = new MockHttpAndServiceBundle()) - { - var tokenHttpCallHandler = new MockHttpMessageHandler() - { - ExpectedUrl = $"https://{EastUsRegion}.{expectedEnv}/17b189bc-2b81-4ec5-aa51-3e628cbc931b/oauth2/v2.0/token", - ExpectedMethod = HttpMethod.Post, - ResponseMessage = CreateResponse(true) - }; - harness.HttpManager.AddMockHandler(tokenHttpCallHandler); - - var app = ConfidentialClientApplicationBuilder - .Create(TestConstants.ClientId) - .WithAuthority($"https://{inputEnv}/common", true) - .WithHttpManager(harness.HttpManager) - .WithAzureRegion(ConfidentialClientApplication.AttemptRegionDiscovery) - .WithClientSecret(TestConstants.ClientSecret) - .Build(); - - AuthenticationResult result = await app - .AcquireTokenForClient(TestConstants.s_scope) - .WithTenantId($"17b189bc-2b81-4ec5-aa51-3e628cbc931b") - .ExecuteAsync() - .ConfigureAwait(false); - - Assert.AreEqual("eastus", result.ApiEvent.RegionUsed); - Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource); - - result = await app - .AcquireTokenForClient(TestConstants.s_scope) - .WithTenantId($"17b189bc-2b81-4ec5-aa51-3e628cbc931b") - .ExecuteAsync() - .ConfigureAwait(false); - - Assert.AreEqual(EastUsRegion, result.ApiEvent.RegionUsed); - Assert.AreEqual(EastUsRegion, result.AuthenticationResultMetadata.RegionDetails.RegionUsed); - Assert.AreEqual(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource); - Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); - Assert.AreEqual(null, result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); - } - } - finally + using (new EnvVariableContext()) + using (var harness = base.CreateTestHarness()) { - Environment.SetEnvironmentVariable("REGION_NAME", null); - } - } + var httpManager = harness.HttpManager; + Environment.SetEnvironmentVariable("REGION_NAME", "eastus"); - private static async Task RunPpeTestAsync(bool validateAuthority, bool authorityIsValid) - { - using (var harness = new MockHttpAndServiceBundle()) - { MockHttpMessageHandler discoveryHandler; if (authorityIsValid) { @@ -600,7 +527,11 @@ private static async Task RunPpeTestAsync(bool validateAuthority, bool authority harness.HttpManager.AddMockHandler(discoveryHandler); } - harness.HttpManager.AddMockHandler(tokenHttpCallHandler); + if (authorityIsValid || !validateAuthority) + { + harness.HttpManager.AddMockHandler(tokenHttpCallHandler); + } + var app = ConfidentialClientApplicationBuilder .Create(TestConstants.ClientId) .WithAuthority("https://" + TestConstants.PpeOrgEnvironment + "/common", validateAuthority)//login.windows-ppe.org is not known to MSAL or AAD @@ -653,14 +584,73 @@ private static async Task RunPpeTestAsync(bool validateAuthority, bool authority Assert.AreEqual(null, result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); } } + + } + + [DataTestMethod] + [DataRow("login.partner.microsoftonline.cn", "login.partner.microsoftonline.cn")] + [DataRow("login.chinacloudapi.cn", "login.partner.microsoftonline.cn")] + [DataRow("login.microsoftonline.us", "login.microsoftonline.us")] + [DataRow("login.usgovcloudapi.net", "login.microsoftonline.us")] + [DataRow("login-us.microsoftonline.com", "login-us.microsoftonline.com")] + [DataRow("login.windows.net", "login.microsoft.com")] + [DataRow("login.microsoft.com", "login.microsoft.com")] + [DataRow("sts.windows.net", "login.microsoft.com")] + [DataRow("login.microsoftonline.com", "login.microsoft.com")] + public async Task PublicAndSovereignCloud_UsesPreferredNetwork_AndNoDiscovery_Async(string inputEnv, string expectedEnv) + { + using (new EnvVariableContext()) + using (var harness = base.CreateTestHarness()) + { + Environment.SetEnvironmentVariable("REGION_NAME", EastUsRegion); + + var tokenHttpCallHandler = new MockHttpMessageHandler() + { + ExpectedUrl = $"https://{EastUsRegion}.{expectedEnv}/17b189bc-2b81-4ec5-aa51-3e628cbc931b/oauth2/v2.0/token", + ExpectedMethod = HttpMethod.Post, + ResponseMessage = CreateResponse(true) + }; + harness.HttpManager.AddMockHandler(tokenHttpCallHandler); + + var app = ConfidentialClientApplicationBuilder + .Create(TestConstants.ClientId) + .WithAuthority($"https://{inputEnv}/common", true) + .WithHttpManager(harness.HttpManager) + .WithAzureRegion(ConfidentialClientApplication.AttemptRegionDiscovery) + .WithClientSecret(TestConstants.ClientSecret) + .Build(); + + AuthenticationResult result = await app + .AcquireTokenForClient(TestConstants.s_scope) + .WithTenantId($"17b189bc-2b81-4ec5-aa51-3e628cbc931b") + .ExecuteAsync() + .ConfigureAwait(false); + + Assert.AreEqual("eastus", result.ApiEvent.RegionUsed); + Assert.AreEqual(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource); + + result = await app + .AcquireTokenForClient(TestConstants.s_scope) + .WithTenantId($"17b189bc-2b81-4ec5-aa51-3e628cbc931b") + .ExecuteAsync() + .ConfigureAwait(false); + + Assert.AreEqual(EastUsRegion, result.ApiEvent.RegionUsed); + Assert.AreEqual(EastUsRegion, result.AuthenticationResultMetadata.RegionDetails.RegionUsed); + Assert.AreEqual(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource); + Assert.AreEqual(RegionOutcome.AutodetectSuccess, result.AuthenticationResultMetadata.RegionDetails.RegionOutcome); + Assert.AreEqual(null, result.AuthenticationResultMetadata.RegionDetails.AutoDetectionError); + } } [TestMethod] [Description("Test with a user configured region.")] public async Task UserRegion_DiscoveryHappensOnce_Async() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + httpManager.AddRegionDiscoveryMockHandler(TestConstants.Region); httpManager.AddMockHandler(CreateTokenResponseHttpHandler(true)); @@ -698,8 +688,9 @@ public async Task UserRegion_DiscoveryHappensOnce_Async() // Test for https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2514 public async Task AuthorityValidationHappensOnNonRegionalAuthorityAsync() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; var handler = new MockHttpMessageHandler() { ExpectedUrl = "https://login.microsoftonline.com/common/discovery/instance", @@ -737,8 +728,10 @@ public async Task AuthorityValidationHappensOnNonRegionalAuthorityAsync() [Description("Test when region is configured with custom metadata")] public void RegionConfiguredWithCustomInstanceDiscoveryThrowsException() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + var ex = Assert.ThrowsException(() => CreateCca( httpManager, ConfidentialClientApplication.AttemptRegionDiscovery, @@ -753,8 +746,10 @@ public void RegionConfiguredWithCustomInstanceDiscoveryThrowsException() [Description("Test when region is configured with custom metadata uri")] public void RegionConfiguredWithCustomInstanceDiscoveryUriThrowsException() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + var ex = Assert.ThrowsException(() => CreateCca( httpManager, ConfidentialClientApplication.AttemptRegionDiscovery, @@ -817,8 +812,10 @@ private static HttpResponseMessage CreateResponse(bool clientCredentialFlow) [TestMethod] public async Task RegionFallbackToGlobal_WhenImdsFailsAndNoEnvVarSet() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + httpManager.AddRegionDiscoveryMockHandlerNotFound(); httpManager.AddInstanceDiscoveryMockHandler(); httpManager.AddMockHandler(CreateTokenResponseHttpHandler(false)); @@ -842,8 +839,10 @@ public async Task RegionFallbackToGlobal_WhenImdsFailsAndNoEnvVarSet() [TestMethod] public void RegionDiscoveryThrowsException_WhenCustomMetadataAndRegionDiscoveryEnabled() { - using (var httpManager = new MockHttpManager()) + using (var harness = base.CreateTestHarness()) { + var httpManager = harness.HttpManager; + var ex = Assert.ThrowsException(() => CreateCca( httpManager, ConfidentialClientApplication.AttemptRegionDiscovery, diff --git a/tests/Microsoft.Identity.Test.Unit/RequestsTests/InteractiveRequestOrchestrationTests.cs b/tests/Microsoft.Identity.Test.Unit/RequestsTests/InteractiveRequestOrchestrationTests.cs index 395ee07140..b3415b3b4e 100644 --- a/tests/Microsoft.Identity.Test.Unit/RequestsTests/InteractiveRequestOrchestrationTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/RequestsTests/InteractiveRequestOrchestrationTests.cs @@ -83,18 +83,14 @@ public async Task NoBroker_WebUiOnly_Async() Assert.AreEqual(1, cache.Accessor.GetAllAccessTokens().Count); // Assert - orchestration -#pragma warning disable VSTHRD101 // Avoid unsupported async delegates - Received.InOrder(async () => + Received.InOrder(() => { - await _authCodeRequestComponentOverride - .FetchAuthCodeAndPkceVerifierAsync(default) - .ConfigureAwait(false); + _authCodeRequestComponentOverride + .FetchAuthCodeAndPkceVerifierAsync(default); - await _authCodeExchangeComponentOverride - .FetchTokensAsync(default) - .ConfigureAwait(false); + _authCodeExchangeComponentOverride + .FetchTokensAsync(default); }); -#pragma warning restore VSTHRD101 // Avoid unsupported async delegates await _brokerExchangeComponentOverride .DidNotReceiveWithAnyArgs() @@ -214,22 +210,17 @@ public async Task Broker_Configured_But_Not_Installed_Async() // Assert - orchestration // Assert - orchestration -#pragma warning disable VSTHRD101 // Avoid unsupported async delegates - Received.InOrder(async () => + Received.InOrder(() => { - await _brokerExchangeComponentOverride - .FetchTokensAsync(default) - .ConfigureAwait(false); + _brokerExchangeComponentOverride + .FetchTokensAsync(default); - await _authCodeRequestComponentOverride - .FetchAuthCodeAndPkceVerifierAsync(default) - .ConfigureAwait(false); + _authCodeRequestComponentOverride + .FetchAuthCodeAndPkceVerifierAsync(default); - await _authCodeExchangeComponentOverride - .FetchTokensAsync(default) - .ConfigureAwait(false); + _authCodeExchangeComponentOverride + .FetchTokensAsync(default); }); -#pragma warning restore VSTHRD101 // Avoid unsupported async delegates } } @@ -281,17 +272,13 @@ public async Task Broker_Not_Configured_But_Installed_EvoWantsBroker_Async() Assert.AreEqual(1, cache.Accessor.GetAllAccessTokens().Count); // Assert - orchestration -#pragma warning disable VSTHRD101 // Avoid unsupported async delegates - Received.InOrder(async () => + Received.InOrder(() => { - await _authCodeRequestComponentOverride - .FetchAuthCodeAndPkceVerifierAsync(default) - .ConfigureAwait(false); - await _brokerExchangeComponentOverride - .FetchTokensAsync(default) - .ConfigureAwait(false); + _authCodeRequestComponentOverride + .FetchAuthCodeAndPkceVerifierAsync(default); + _brokerExchangeComponentOverride + .FetchTokensAsync(default); }); -#pragma warning restore VSTHRD101 // Avoid unsupported async delegates await _authCodeExchangeComponentOverride .DidNotReceiveWithAnyArgs() diff --git a/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs b/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs index a0fc353f09..d06bca851b 100644 --- a/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/TelemetryTests/HttpTelemetryTests.cs @@ -572,8 +572,8 @@ private enum AcquireTokenInteractiveOutcome var ui = Substitute.For(); ui.UpdateRedirectUri(Arg.Any()).Returns(new Uri("http://localhost:1234")); - ui.AcquireAuthorizationAsync(null, null, null, default).ThrowsForAnyArgs( - new MsalClientException("user_cancelled")); + ui.AcquireAuthorizationAsync(null, null, null, default).ReturnsForAnyArgs( + Task.FromException(new MsalClientException("user_cancelled"))); _app.ServiceBundle.ConfigureMockWebUI(ui); var ex = await AssertException.TaskThrowsAsync(() => @@ -622,11 +622,13 @@ private enum AcquireTokenInteractiveOutcome cts.Cancel(true); CancellationToken token = cts.Token; - var operationCanceledException = await AssertException.TaskThrowsAsync(() => + var operationCanceledException = await AssertException.TaskThrowsAsync(() => _app .AcquireTokenInteractive(TestConstants.s_scope) .WithCorrelationId(correlationId) - .ExecuteAsync(token)) + .ExecuteAsync(token), + allowDerived: true) // do not catch TaskCanceledException + .ConfigureAwait(false); break; diff --git a/tests/devapps/Directory.Packages.props b/tests/devapps/Directory.Packages.props index d936a70e9d..d45b64b040 100644 --- a/tests/devapps/Directory.Packages.props +++ b/tests/devapps/Directory.Packages.props @@ -2,6 +2,8 @@ false + false + diff --git a/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/AquireToken.cs b/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/AquireToken.cs index ff189ae7fb..b45f9cd702 100644 --- a/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/AquireToken.cs +++ b/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/AquireToken.cs @@ -32,7 +32,7 @@ public static async Task Run(HttpRequest req, ILogger log) try { - log.LogInformation("uri : ", uri); + log.LogInformation("uri: {uri}", uri); //set the http get method and the required headers for a web app var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri); diff --git a/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/GetEnvironmentVariables.cs b/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/GetEnvironmentVariables.cs index a42da2180a..55e45db4ac 100644 --- a/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/GetEnvironmentVariables.cs +++ b/tests/devapps/Managed Identity apps/MSIHelperService/AzureFunction/GetEnvironmentVariables.cs @@ -31,7 +31,7 @@ public static IActionResult Run(HttpRequest req, ILogger log) string? name = req.Query["variableName"]; - log.LogInformation("Querystring value for variableName is : ", name); + log.LogInformation("Querystring value for variableName is : {variableName}", name); if (string.IsNullOrEmpty(name)) { @@ -46,7 +46,7 @@ public static IActionResult Run(HttpRequest req, ILogger log) else { string? responseMessage = Environment.GetEnvironmentVariable(name); - log.LogInformation("Returning Environment Variable Based on the variable name : ", name); + log.LogInformation("Returning Environment Variable Based on the variable name : {variableName}", name); return new OkObjectResult(responseMessage); } } diff --git a/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/AppShell.xaml.cs b/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/AppShell.xaml.cs index e6c00d597c..7d0db88f71 100644 --- a/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/AppShell.xaml.cs +++ b/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/AppShell.xaml.cs @@ -1,4 +1,7 @@ -namespace WAMMauiApp; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace WAMMauiApp; public partial class AppShell : Shell { diff --git a/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/WAMMauiApp.csproj b/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/WAMMauiApp.csproj index aa63a846a2..13228bb603 100644 --- a/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/WAMMauiApp.csproj +++ b/tests/devapps/WAM/WAMMauiApp/WAMMauiApp/WAMMauiApp.csproj @@ -1,10 +1,9 @@  - net6.0-windows10.0.19041.0 + net8.0-windows10.0.19041.0 Exe WAMMauiApp - true true enable @@ -45,6 +44,7 @@ + diff --git a/tests/devapps/WebApi/Misc/TestSize.cs b/tests/devapps/WebApi/Misc/TestSize.cs deleted file mode 100644 index fec73eeb6e..0000000000 --- a/tests/devapps/WebApi/Misc/TestSize.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - -namespace WebApi.Misc -{ - class TestSize - { - // as per https://github.com/CyberSaving/MemoryUsage/blob/master/Main/Program.cs - static private int SizeOfObj(Type T, object thevalue) - { - var type = T; - int returnval = 0; - if (type.IsValueType) - { - var nulltype = Nullable.GetUnderlyingType(type); - returnval = System.Runtime.InteropServices.Marshal.SizeOf(nulltype ?? type); - } - else if (thevalue == null) - return 0; - else if (thevalue is string stringValue) - returnval = Encoding.Default.GetByteCount(stringValue); - else if (type.IsArray && type.GetElementType().IsValueType) - { - returnval = ((Array)thevalue).GetLength(0) * System.Runtime.InteropServices.Marshal.SizeOf(type.GetElementType()); - } - else if (thevalue is Stream streamValue) - { - returnval = (int)streamValue.Length; - } - else if (type.IsSerializable) - { - try - { - returnval = JsonSerializer.SerializeToUtf8Bytes(thevalue).Length; - } - catch { } - } - else - { - var fields = type.GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - for (int i = 0; i < fields.Length; i++) - { - Type t = fields[i].FieldType; - Object v = fields[i].GetValue(thevalue); - returnval += 4 + SizeOfObj(t, v); - } - } - if (returnval == 0) - try - { - returnval = System.Runtime.InteropServices.Marshal.SizeOf(thevalue); - } - catch { } - return returnval; - } - static public int SizeOf(T value) - { - return SizeOfObj(typeof(T), value); - } - } -}