Skip to content

Commit 852b321

Browse files
committed
Authentication Test changes
1 parent ee5e317 commit 852b321

16 files changed

+728
-279
lines changed

src/Common/Commands.Common.Authentication.Test/AuthenticationFactoryTests.cs

+31-40
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2222
using Xunit;
23+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2324

2425
namespace Common.Authentication.Test
2526
{
@@ -29,32 +30,28 @@ public class AuthenticationFactoryTests
2930
[Trait(Category.AcceptanceType, Category.CheckIn)]
3031
public void VerifySubscriptionTokenCacheRemove()
3132
{
33+
AzureSessionInitializer.InitializeAzureSession();
3234
var authFactory = new AuthenticationFactory
3335
{
3436
TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
3537
};
3638

3739
var subscriptionId = Guid.NewGuid();
38-
40+
var account = new AzureAccount
41+
{
42+
Id = "testuser",
43+
Type = AzureAccount.AccountType.User,
44+
};
45+
account.SetTenants("123");
46+
var sub = new AzureSubscription
47+
{
48+
Id = subscriptionId.ToString(),
49+
};
50+
sub.SetTenant("123");
3951
var credential = authFactory.GetSubscriptionCloudCredentials(new AzureContext
4052
(
41-
new AzureSubscription
42-
{
43-
Id = subscriptionId,
44-
Properties = new Dictionary<AzureSubscription.Property, string>
45-
{
46-
{ AzureSubscription.Property.Tenants, "123"}
47-
}
48-
},
49-
new AzureAccount
50-
{
51-
Id = "testuser",
52-
Type = AzureAccount.AccountType.User,
53-
Properties = new Dictionary<AzureAccount.Property, string>
54-
{
55-
{ AzureAccount.Property.Tenants, "123" }
56-
}
57-
},
53+
sub,
54+
account,
5855
AzureEnvironment.PublicEnvironments["AzureCloud"]
5956
));
6057

@@ -66,40 +63,34 @@ public void VerifySubscriptionTokenCacheRemove()
6663
[Trait(Category.AcceptanceType, Category.CheckIn)]
6764
public void VerifyValidateAuthorityFalseForOnPremise()
6865
{
66+
AzureSessionInitializer.InitializeAzureSession();
6967
var authFactory = new AuthenticationFactory
7068
{
7169
TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
7270
};
7371

7472
var subscriptionId = Guid.NewGuid();
73+
var account = new AzureAccount
74+
{
75+
Id = "testuser",
76+
Type = AzureAccount.AccountType.User,
77+
};
78+
account.SetTenants("123");
79+
var sub = new AzureSubscription
80+
{
81+
Id = subscriptionId.ToString(),
82+
};
83+
sub.SetTenant("123");
7584
var context = new AzureContext
7685
(
77-
new AzureSubscription
78-
{
79-
Id = subscriptionId,
80-
Properties = new Dictionary<AzureSubscription.Property, string>
81-
{
82-
{ AzureSubscription.Property.Tenants, "123"}
83-
}
84-
},
85-
new AzureAccount
86-
{
87-
Id = "testuser",
88-
Type = AzureAccount.AccountType.User,
89-
Properties = new Dictionary<AzureAccount.Property, string>
90-
{
91-
{ AzureAccount.Property.Tenants, "123" }
92-
}
93-
},
86+
sub,
87+
account,
9488
new AzureEnvironment
9589
{
9690
Name = "Katal",
9791
OnPremise = true,
98-
Endpoints = new Dictionary<AzureEnvironment.Endpoint, string>
99-
{
100-
{ AzureEnvironment.Endpoint.ActiveDirectory, "http://ad.com" },
101-
{ AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, "http://adresource.com" }
102-
}
92+
ActiveDirectoryAuthority = "http://ad.com",
93+
ActiveDirectoryServiceEndpointResourceId = "http://adresource.com"
10394
}
10495
);
10596

src/Common/Commands.Common.Authentication.Test/ClientFactoryHandlerTests.cs

+19-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2424
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2525
using Xunit;
26+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2627

2728
namespace Common.Authentication.Test
2829
{
@@ -32,27 +33,30 @@ public class ClientFactoryHandlerTests
3233
[Trait(Category.AcceptanceType, Category.CheckIn)]
3334
public void DelegatingHandlersAreCloned()
3435
{
36+
AzureSessionInitializer.InitializeAzureSession();
3537
string userAccount = "[email protected]";
3638
Guid subscriptionId = Guid.NewGuid();
37-
AzureContext context = new AzureContext
39+
var account = new AzureAccount()
40+
{
41+
Id = userAccount,
42+
Type = AzureAccount.AccountType.User,
43+
};
44+
account.SetTenants("common");
45+
var sub = new AzureSubscription()
46+
{
47+
Id = subscriptionId.ToString(),
48+
};
49+
sub.SetAccount(userAccount);
50+
sub.SetEnvironment("AzureCloud");
51+
sub.SetTenant("common");
52+
AzureContext context = new AzureContext
3853
(
39-
new AzureSubscription()
40-
{
41-
Account = userAccount,
42-
Environment = "AzureCloud",
43-
Id = subscriptionId,
44-
Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } }
45-
},
46-
new AzureAccount()
47-
{
48-
Id = userAccount,
49-
Type = AzureAccount.AccountType.User,
50-
Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } }
51-
},
54+
sub,
55+
account,
5256
AzureEnvironment.PublicEnvironments["AzureCloud"]
5357
);
5458

55-
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString());
59+
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString());
5660
var mockHandler = new MockDelegatingHandler();
5761
var factory = new ClientFactory();
5862
factory.AddHandler(mockHandler);

src/Common/Commands.Common.Authentication.Test/ClientFactoryTests.cs

+20-18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2525
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2626
using Xunit;
27+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2728

2829
namespace Common.Authentication.Test
2930
{
@@ -72,34 +73,35 @@ public void VerifyClientFactoryWorks()
7273
{
7374
return;
7475
}
75-
76+
var sub = new AzureSubscription()
77+
{
78+
Id = subscriptionId,
79+
};
80+
sub.SetAccount(userAccount);
81+
sub.SetEnvironment("AzureCloud");
82+
sub.SetTenant("common");
83+
var account = new AzureAccount()
84+
{
85+
Id = userAccount,
86+
Type = AzureAccount.AccountType.User,
87+
};
88+
account.SetTenants("common");
7689
AzureContext context = new AzureContext
7790
(
78-
new AzureSubscription()
79-
{
80-
Account = userAccount,
81-
Environment = "AzureCloud",
82-
Id = Guid.Parse(subscriptionId),
83-
Properties = new Dictionary<AzureSubscription.Property, string>() { { AzureSubscription.Property.Tenants, "common" } }
84-
},
85-
new AzureAccount()
86-
{
87-
Id = userAccount,
88-
Type = AzureAccount.AccountType.User,
89-
Properties = new Dictionary<AzureAccount.Property, string>() { { AzureAccount.Property.Tenants, "common" } }
90-
},
91+
sub,
92+
account,
9193
AzureEnvironment.PublicEnvironments["AzureCloud"]
9294
);
9395

9496
// Add registration action to make sure we register for the used provider (if required)
95-
// AzureSession.ClientFactory.AddAction(new RPRegistrationAction());
97+
// AzureSession.Instance.ClientFactory.AddAction(new RPRegistrationAction());
9698

9799
// Authenticate!
98-
AzureSession.AuthenticationFactory.Authenticate(context.Account, context.Environment, "common", password, ShowDialog.Always);
100+
AzureSession.Instance.AuthenticationFactory.Authenticate(context.Account, context.Environment, "common", password, ShowDialog.Always);
99101

100-
AzureSession.ClientFactory.AddUserAgent("TestUserAgent", "1.0");
102+
AzureSession.Instance.ClientFactory.AddUserAgent("TestUserAgent", "1.0");
101103
// Create the client
102-
var client = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
104+
var client = AzureSession.Instance.ClientFactory.CreateClient<StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement);
103105

104106
// List storage accounts
105107
var storageAccounts = client.StorageAccounts.List().StorageAccounts;

src/Common/Commands.Common.Authentication.Test/Commands.Common.Authentication.Test.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@
120120
</Reference>
121121
</ItemGroup>
122122
<ItemGroup>
123-
<Compile Include="AzureRMProfileTests.cs" />
124123
<Compile Include="ClientFactoryHandlerTests.cs" />
125124
<Compile Include="ClientFactoryTests.cs" />
126125
<Compile Include="AuthenticationFactoryTests.cs" />
127126
<Compile Include="ConversionUtilitiesTests.cs" />
128-
<Compile Include="AzureSMProfileTests.cs" />
129127
<Compile Include="Mocks\MockDataStore.cs" />
130128
<Compile Include="Properties\AssemblyInfo.cs" />
131129
<Compile Include="Properties\Resources.Designer.cs">
@@ -136,6 +134,10 @@
136134
<EmbeddedResource Include="Resources\ResourceLocator.cs" />
137135
</ItemGroup>
138136
<ItemGroup>
137+
<ProjectReference Include="..\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">
138+
<Project>{70527617-7598-4aef-b5bd-db9186b8184b}</Project>
139+
<Name>Commands.Common.Authentication.Abstractions</Name>
140+
</ProjectReference>
139141
<ProjectReference Include="..\Commands.Common.Authentication\Commands.Common.Authentication.csproj">
140142
<Project>{d3804b64-c0d3-48f8-82ec-1f632f833c9e}</Project>
141143
<Name>Commands.Common.Authentication</Name>
@@ -187,4 +189,4 @@
187189
</ItemGroup>
188190
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
189191
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
190-
</Project>
192+
</Project>

src/Common/Commands.ScenarioTests.Common/Commands.ScenarioTests.Common.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@
148148
<Compile Include="PermissiveRecordMatcherWithApiExclusion.cs" />
149149
<Compile Include="PowerShellExtensions.cs" />
150150
<Compile Include="Properties\AssemblyInfo.cs" />
151-
<Compile Include="SMTestBase.cs" />
152151
<Compile Include="XunitTracingInterceptor.cs" />
153152
</ItemGroup>
154153
<ItemGroup>
@@ -165,6 +164,10 @@
165164
<Project>{cff09e81-1e31-444e-b4d4-a21e946c29e2}</Project>
166165
<Name>Commands.ServiceManagement.Common</Name>
167166
</ProjectReference>
167+
<ProjectReference Include="..\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">
168+
<Project>{70527617-7598-4aef-b5bd-db9186b8184b}</Project>
169+
<Name>Commands.Common.Authentication.Abstractions</Name>
170+
</ProjectReference>
168171
<ProjectReference Include="..\Commands.Common.Authentication\Commands.Common.Authentication.csproj">
169172
<Project>{d3804b64-c0d3-48f8-82ec-1f632f833c9e}</Project>
170173
<Name>Commands.Common.Authentication</Name>
@@ -176,4 +179,4 @@
176179
</ItemGroup>
177180
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
178181
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
179-
</Project>
182+
</Project>

0 commit comments

Comments
 (0)