Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Accounts/Accounts.Test/AutoSaveSettingOnLoadingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Core;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.Properties;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand Down Expand Up @@ -111,7 +110,7 @@ public void DisableAutoSaveWhenSettingFileBreaks()
var newSetting = JsonConvert.DeserializeObject<ContextAutosaveSettings>(afterModified) as ContextAutosaveSettings;
Assert.NotNull(newSetting);
Assert.Equal(ContextSaveMode.CurrentUser, newSetting.Mode);
Assert.Equal(typeof(AuthenticationStoreTokenCache), AzureSession.Instance.TokenCache.GetType());
//Assert.Equal(typeof(AzureTokenCache), AzureSession.Instance.TokenCache.GetType());
}
finally
{
Expand Down
26 changes: 17 additions & 9 deletions src/Accounts/Accounts.Test/AutosaveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication;
// TODO: Remove IfDef
#if NETSTANDARD
using Microsoft.Azure.Commands.Common.Authentication.Core;
#endif
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
Expand Down Expand Up @@ -49,11 +45,15 @@ void ResetState()

TestExecutionHelpers.SetUpSessionAndProfile();
ResourceManagerProfileProvider.InitializeResourceManagerProfile(true);
// prevent token acquisition
AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>().ShouldRefreshContextsFromCache = false;
AzureSession.Instance.DataStore = dataStore;
AzureSession.Instance.ARMContextSaveMode = ContextSaveMode.Process;
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
AzureSession.Instance.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache());
Environment.SetEnvironmentVariable("Azure_PS_Data_Collection", "false");
PowerShellTokenCacheProvider tokenProvider = new InMemoryTokenCacheProvider();
AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenProvider);
AzureSession.Instance.RegisterComponent(nameof(PowerShellTokenCache), () => tokenProvider.GetTokenCache());
}

[Fact]
Expand All @@ -70,9 +70,12 @@ public void EnableAutosaveWhenDisabled()
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Assert.Equal(ContextSaveMode.CurrentUser, AzureSession.Instance.ARMContextSaveMode);
Assert.Equal(typeof(ProtectedFileTokenCache), AzureSession.Instance.TokenCache.GetType());
Assert.Equal(typeof(ProtectedProfileProvider), AzureRmProfileProvider.Instance.GetType());
}
catch (PlatformNotSupportedException)
{
// swallow exception when test env (Linux server) doesn't support token cache persistence
}
finally
{
ResetState();
Expand All @@ -94,9 +97,12 @@ public void EnableAutosaveWhenEnabled()
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Assert.Equal(ContextSaveMode.CurrentUser, AzureSession.Instance.ARMContextSaveMode);
Assert.Equal(typeof(ProtectedFileTokenCache), AzureSession.Instance.TokenCache.GetType());
Assert.Equal(typeof(ProtectedProfileProvider), AzureRmProfileProvider.Instance.GetType());
}
catch (PlatformNotSupportedException)
{
// swallow exception when test env (Linux server) doesn't support token cache persistence
}
finally
{
ResetState();
Expand All @@ -119,7 +125,8 @@ public void DisableAutosaveWhenEnabled()
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Assert.Equal(ContextSaveMode.Process, AzureSession.Instance.ARMContextSaveMode);
Assert.Equal(typeof(AuthenticationStoreTokenCache), AzureSession.Instance.TokenCache.GetType());
Assert.True(AzureSession.Instance.TryGetComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, out PowerShellTokenCacheProvider factory));
Assert.Equal(typeof(InMemoryTokenCacheProvider), factory.GetType());
Assert.Equal(typeof(ResourceManagerProfileProvider), AzureRmProfileProvider.Instance.GetType());
}
finally
Expand All @@ -142,7 +149,8 @@ public void DisableAutoSsaveWhenDisabled()
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Assert.Equal(ContextSaveMode.Process, AzureSession.Instance.ARMContextSaveMode);
Assert.Equal(typeof(AuthenticationStoreTokenCache), AzureSession.Instance.TokenCache.GetType());
Assert.True(AzureSession.Instance.TryGetComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, out PowerShellTokenCacheProvider factory));
Assert.Equal(typeof(InMemoryTokenCacheProvider), factory.GetType());
Assert.Equal(typeof(ResourceManagerProfileProvider), AzureRmProfileProvider.Instance.GetType());
}
finally
Expand Down
7 changes: 1 addition & 6 deletions src/Accounts/Accounts.Test/AzureRMProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication;
// TODO: Remove IfDef
#if NETSTANDARD
using Microsoft.Azure.Commands.Common.Authentication.Core;
#endif
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Factories;
using Microsoft.Azure.Commands.Common.Authentication.Models;
Expand Down Expand Up @@ -946,7 +942,7 @@ public void SavingProfileWorks()
};
profile.DefaultContext = new AzureContext(sub, account, environment, tenant);
profile.EnvironmentTable[environment.Name] = environment;
profile.DefaultContext.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache { CacheData = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 } });
//profile.DefaultContext.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache { CacheData = new byte[] { 1, 2, 3, 4, 5, 6, 8, 9, 0 } });
profile.Save();
string actual = dataStore.ReadFileAsText(path).Substring(1).TrimEnd(new[] { '\0' });
#if NETSTANDARD
Expand Down Expand Up @@ -1019,7 +1015,6 @@ public void LoadingProfileWorks()
Assert.Equal("testCloud", profile.DefaultContext.Environment.Name);
Assert.Equal("[email protected]", profile.DefaultContext.Account.Id);
Assert.Equal(AzureAccount.AccountType.User, profile.DefaultContext.Account.Type);
Assert.Equal(expectedArray, profile.DefaultContext.TokenCache.CacheData);
Assert.Equal(path, profile.ProfilePath);
}

Expand Down
17 changes: 9 additions & 8 deletions src/Accounts/Accounts.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Accounts", "Accounts\Accounts.csproj", "{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}"
EndProject
Expand All @@ -16,10 +16,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScenarioTest.ResourceManage
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFx", "..\..\tools\TestFx\TestFx.csproj", "{BC80A1D0-FFA4-43D9-AA74-799F5CB54B58}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication.Test", "Authentication.Test\Authentication.Test.csproj", "{78D9B754-6A18-4125-80CC-63437BDE3244}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authenticators", "Authenticators\Authenticators.csproj", "{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication.Test", "Authentication.Test\Authentication.Test.csproj", "{43BE9983-BD21-4474-92E5-1FFC0220B2AD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -50,20 +50,21 @@ Global
{BC80A1D0-FFA4-43D9-AA74-799F5CB54B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC80A1D0-FFA4-43D9-AA74-799F5CB54B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC80A1D0-FFA4-43D9-AA74-799F5CB54B58}.Release|Any CPU.Build.0 = Release|Any CPU
{78D9B754-6A18-4125-80CC-63437BDE3244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78D9B754-6A18-4125-80CC-63437BDE3244}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78D9B754-6A18-4125-80CC-63437BDE3244}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78D9B754-6A18-4125-80CC-63437BDE3244}.Release|Any CPU.Build.0 = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
{43BE9983-BD21-4474-92E5-1FFC0220B2AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BE9983-BD21-4474-92E5-1FFC0220B2AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BE9983-BD21-4474-92E5-1FFC0220B2AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43BE9983-BD21-4474-92E5-1FFC0220B2AD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{152D78F0-A642-4D0E-B3A8-2FC64FFA9714} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
{43BE9983-BD21-4474-92E5-1FFC0220B2AD} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AA51E4F8-AA75-429D-9626-12C7B4305D72}
Expand Down
Loading