Skip to content

Commit c19a050

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
# Conflicts: # setup/azurecmdfiles.wxi
2 parents c03048b + e7d9953 commit c19a050

File tree

972 files changed

+19229
-3794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

972 files changed

+19229
-3794
lines changed

AzurePowershell.Test.targets

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<XUnitTests Include=".\src\ResourceManager\ApiManagement\Commands.ApiManagement.Test\bin\Debug\Microsoft.Azure.Commands.ApiManagement.Test.dll"/>
8585
<XUnitTests Include=".\src\ResourceManager\Profile\Commands.Profile.Test\bin\Debug\Microsoft.Azure.Commands.Profile.Test.dll"/>
8686
<XUnitTests Include=".\src\ResourceManager\AzureBackup\Commands.AzureBackup.Test\bin\Debug\Microsoft.Azure.Commands.AzureBackup.Test.dll"/>
87-
<XUnitTests Include=".\src\ResourceManager\NotificationHubs\Commands.NotificationHubs.Test\bin\Debug\Microsoft.Azure.Commands.NotificationHubs.Test.dll"/>
87+
<XUnitTests Include=".\src\ResourceManager\NotificationHubs\Commands.NotificationHubs.Test\bin\Debug\Microsoft.Azure.Commands.NotificationHubs.Test.dll"/>
8888
<XUnitTests Include="@(AsmXUnitTests)"/>
8989
</ItemGroup>
9090
<ItemGroup Condition=" '$(scope)' == 'ServiceManagement' ">
@@ -98,19 +98,37 @@
9898
<Target Name="InvokeXUnit" DependsOnTargets="DeclareXunitTests">
9999
<Message Importance="high" Text="Running XUnit tests" />
100100
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
101-
<Exec
102-
Command="$(MSBuildProjectDirectory)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -parallel none -maxthreads 0 -trait &quot;AcceptanceType=CheckIn&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
103-
Timeout="$(TestTimeout)" ContinueOnError="false" Condition=" @(XUnitTests) != '' "/>
104-
<OnError ExecuteTargets="TimeoutErrorHandler"/>
101+
102+
<xunit
103+
Assemblies="@(XUnitTests)"
104+
AppDomains="true"
105+
ShadowCopy="false"
106+
ParallelizeTestCollections="false"
107+
ParallelizeAssemblies="true"
108+
IncludeTraits="AcceptanceType=CheckIn"
109+
Html="$(TestOutputDirectory)\AzurePowershellTestResults.html"
110+
MaxParallelThreads="10"
111+
DiagnosticMessages="false"
112+
ContinueOnError="false"
113+
Condition=" @(XUnitTests) != '' "/>
105114
</Target>
106115

107116
<Target Name="InvokeXUnitAll" DependsOnTargets="DeclareXunitTests">
108117
<Message Importance="high" Text="Running XUnit tests" />
109118
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
110-
<Exec
111-
Command="$(MSBuildProjectDirectory)\packages\xunit.runner.console.2.0.0\tools\xunit.console.x86.exe &quot;%(XUnitTests.Identity)&quot; -notrait &quot;RunType=LiveOnly&quot; -html &quot;$(TestOutputDirectory)\%(XUnitTests.Filename).html&quot;"
112-
Timeout="$(TestTimeout)" ContinueOnError="false"/>
113-
<OnError ExecuteTargets="TimeoutErrorHandler"/>
119+
120+
<xunit
121+
Assemblies="@(XUnitTests)"
122+
AppDomains="true"
123+
ShadowCopy="false"
124+
ParallelizeTestCollections="false"
125+
ParallelizeAssemblies="true"
126+
ExcludeTraits="RunType=LiveOnly"
127+
Html="$(TestOutputDirectory)\AzurePowershellAllTestResults.html"
128+
MaxParallelThreads="10"
129+
DiagnosticMessages="false"
130+
ContinueOnError="false"
131+
Condition=" @(XUnitTests) != '' "/>
114132
</Target>
115133

116134
<Target Name="TimeoutErrorHandler">
@@ -458,7 +476,7 @@
458476

459477
<Target Name="LiveTests">
460478
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
461-
<Exec Command="packages\xunit.runners.1.9.2\tools\xunit.console.clr4.exe @(LiveTestDlls) /trait &quot;AcceptanceType=LiveBVT&quot; /html &quot;$(TestOutputDirectory)\Live.%(Filename).html&quot;" />
479+
<Exec Command="packages\xunit.runner.console.2.1.0\tools\xunit.console.x86.exe @(LiveTestDlls) /trait &quot;AcceptanceType=LiveBVT&quot; /html &quot;$(TestOutputDirectory)\Live.%(Filename).html&quot;" />
462480
</Target>
463481

464482

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<Import Condition=" $(OnPremiseBuild) " Project="$(CIToolsPath)\Microsoft.WindowsAzure.Build.OnPremise.msbuild" />
7171

7272
<UsingTask
73-
AssemblyFile="$(MSBuildProjectDirectory)\src\packages\xunit.MSBuild.2.0.0.0\tools\xunit.runner.msbuild.dll"
73+
AssemblyFile="$(MSBuildProjectDirectory)\packages\xunit.runner.msbuild.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.dll"
7474
TaskName="Xunit.Runner.MSBuild.xunit" />
7575

7676
<!-- Clean the build in all configurations -->

packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="xunit.runner.console" version="2.0.0" />
4-
<package id="xunit.runners" version="1.9.2" />
3+
<package id="xunit.runner.console" version="2.1.0" />
4+
<package id="xunit.runner.msbuild" version="2.1.0" />
55
</packages>

setup/azurecmdfiles.wxi

Lines changed: 284 additions & 244 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
17+
namespace Microsoft.Azure.Commands.Common.Authentication
18+
{
19+
/// <summary>
20+
/// Base class representing an exception that occurs when
21+
/// authenticating against Azure Active Directory
22+
/// </summary>
23+
[Serializable]
24+
public abstract class AadAuthenticationException : Exception
25+
{
26+
protected AadAuthenticationException()
27+
{
28+
}
29+
30+
protected AadAuthenticationException(string message) : base(message)
31+
{
32+
}
33+
34+
protected AadAuthenticationException(string message, Exception innerException) : base(message, innerException)
35+
{
36+
}
37+
}
38+
39+
/// <summary>
40+
/// Exception that gets thrown when the user explicitly
41+
/// cancels an authentication operation.
42+
/// </summary>
43+
[Serializable]
44+
public class AadAuthenticationCanceledException : AadAuthenticationException
45+
{
46+
public AadAuthenticationCanceledException(string message, Exception innerException) : base(message, innerException)
47+
{
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Exception that gets thrown when the ADAL library
53+
/// is unable to authenticate without a popup dialog.
54+
/// </summary>
55+
[Serializable]
56+
public class AadAuthenticationFailedWithoutPopupException : AadAuthenticationException
57+
{
58+
public AadAuthenticationFailedWithoutPopupException(string message, Exception innerException)
59+
: base(message, innerException)
60+
{
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Exception that gets thrown if an authentication operation
66+
/// fails on the server.
67+
/// </summary>
68+
[Serializable]
69+
public class AadAuthenticationFailedException : AadAuthenticationException
70+
{
71+
public AadAuthenticationFailedException(string message, Exception innerException) : base(message, innerException)
72+
{
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Exception thrown if a refresh token has expired.
78+
/// </summary>
79+
[Serializable]
80+
public class AadAuthenticationCantRenewException : AadAuthenticationException
81+
{
82+
public AadAuthenticationCantRenewException()
83+
{
84+
}
85+
86+
public AadAuthenticationCantRenewException(string message) : base(message)
87+
{
88+
}
89+
90+
public AadAuthenticationCantRenewException(string message, Exception innerException) : base(message, innerException)
91+
{
92+
}
93+
}
94+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Net.Http;
17+
using System.Net.Http.Headers;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.Common.Authentication
22+
{
23+
public class AccessTokenCredential : SubscriptionCloudCredentials
24+
{
25+
private readonly Guid subscriptionId;
26+
private readonly IAccessToken token;
27+
28+
public AccessTokenCredential(Guid subscriptionId, IAccessToken token)
29+
{
30+
this.subscriptionId = subscriptionId;
31+
this.token = token;
32+
this.TenantID = token.TenantId;
33+
}
34+
35+
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
36+
{
37+
token.AuthorizeRequest((tokenType, tokenValue) => {
38+
request.Headers.Authorization = new AuthenticationHeaderValue(tokenType, tokenValue);
39+
});
40+
return base.ProcessHttpRequestAsync(request, cancellationToken);
41+
}
42+
43+
public override string SubscriptionId
44+
{
45+
get { return subscriptionId.ToString(); }
46+
}
47+
48+
public string TenantID { get; set; }
49+
}
50+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
16+
using System;
17+
18+
namespace Microsoft.Azure.Commands.Common.Authentication
19+
{
20+
/// <summary>
21+
/// Class storing the configuration information needed
22+
/// for ADAL to request token from the right AD tenant
23+
/// depending on environment.
24+
/// </summary>
25+
public class AdalConfiguration
26+
{
27+
//
28+
// These constants define the default values to use for AD authentication
29+
// against RDFE
30+
//
31+
public const string PowerShellClientId = "1950a258-227b-4e31-a9cf-717495945fc2";
32+
33+
public static readonly Uri PowerShellRedirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob");
34+
35+
// ID for site to pass to enable EBD (email-based differentiation)
36+
// This gets passed in the call to get the azure branding on the
37+
// login window. Also adding popup flag to handle overly large login windows.
38+
public const string EnableEbdMagicCookie = "site_id=501358&display=popup";
39+
40+
public string AdEndpoint { get;set; }
41+
42+
public bool ValidateAuthority { get; set; }
43+
44+
public string AdDomain { get; set; }
45+
46+
public string ClientId { get; set; }
47+
48+
public Uri ClientRedirectUri { get; set; }
49+
50+
public string ResourceClientUri { get; set; }
51+
52+
public TokenCache TokenCache { get; set; }
53+
54+
public AdalConfiguration()
55+
{
56+
ClientId = PowerShellClientId;
57+
ClientRedirectUri = PowerShellRedirectUri;
58+
ValidateAuthority = true;
59+
AdEndpoint = string.Empty;
60+
ResourceClientUri = "https://management.core.windows.net/";
61+
}
62+
}
63+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication.Models;
16+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
17+
using System;
18+
using System.Security;
19+
using System.Windows.Forms;
20+
21+
namespace Microsoft.Azure.Commands.Common.Authentication
22+
{
23+
/// <summary>
24+
/// A token provider that uses ADAL to retrieve
25+
/// tokens from Azure Active Directory
26+
/// </summary>
27+
public class AdalTokenProvider : ITokenProvider
28+
{
29+
private readonly ITokenProvider userTokenProvider;
30+
private readonly ITokenProvider servicePrincipalTokenProvider;
31+
32+
public AdalTokenProvider()
33+
: this(new ConsoleParentWindow())
34+
{
35+
}
36+
37+
public AdalTokenProvider(IWin32Window parentWindow)
38+
{
39+
this.userTokenProvider = new UserTokenProvider(parentWindow);
40+
servicePrincipalTokenProvider = new ServicePrincipalTokenProvider();
41+
}
42+
43+
public IAccessToken GetAccessToken(AdalConfiguration config, ShowDialog promptBehavior, string userId, SecureString password,
44+
AzureAccount.AccountType credentialType)
45+
{
46+
switch (credentialType)
47+
{
48+
case AzureAccount.AccountType.User:
49+
return userTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
50+
case AzureAccount.AccountType.ServicePrincipal:
51+
return servicePrincipalTokenProvider.GetAccessToken(config, promptBehavior, userId, password, credentialType);
52+
default:
53+
throw new ArgumentException(Resources.UnknownCredentialType, "credentialType");
54+
}
55+
}
56+
57+
public IAccessToken GetAccessTokenWithCertificate(AdalConfiguration config, string clientId, string certificate, AzureAccount.AccountType credentialType)
58+
{
59+
switch (credentialType)
60+
{
61+
case AzureAccount.AccountType.ServicePrincipal:
62+
return servicePrincipalTokenProvider.GetAccessTokenWithCertificate(config, clientId, certificate, credentialType);
63+
default:
64+
throw new ArgumentException(string.Format(Resources.UnsupportedCredentialType, credentialType), "credentialType");
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)