Skip to content

Commit c004ef9

Browse files
committed
Merge pull request #87 from perseusCode/master
FW: Adding cmdlets for creating and deleting AD application & service principal
2 parents 915b585 + af3f5e5 commit c004ef9

24 files changed

+1135
-35
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" />
34
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
45
<PropertyGroup>
56
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -15,6 +16,7 @@
1516
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
1617
<RestorePackages>true</RestorePackages>
1718
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
19+
<NuGetPackageImportStamp>944f727b</NuGetPackageImportStamp>
1820
</PropertyGroup>
1921
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
2022
<SignAssembly>true</SignAssembly>
@@ -376,6 +378,12 @@
376378
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestGetAllADUser.json">
377379
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
378380
</None>
381+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADApplication.json">
382+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
383+
</None>
384+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipal.json">
385+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
386+
</None>
379387
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaByResource.json">
380388
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
381389
</None>
@@ -423,6 +431,12 @@
423431
<PropertyGroup>
424432
<PostBuildEvent>xcopy "$(SolutionDir)Package\$(ConfigurationName)\*.*" $(TargetDir) /Y /E</PostBuildEvent>
425433
</PropertyGroup>
434+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
435+
<PropertyGroup>
436+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
437+
</PropertyGroup>
438+
<Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props'))" />
439+
</Target>
426440
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
427441
Other similar extension points exist, see Microsoft.Common.targets.
428442
<Target Name="BeforeBuild">

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,39 @@ public void TestGetADUserWithBadSearchString()
555555
ResourcesController.NewInstance.RunPsTest("Test-GetADUserWithBadSearchString");
556556
}
557557

558+
[Fact]
559+
[Trait(Category.AcceptanceType, Category.CheckIn)]
560+
public void TestNewADApplication()
561+
{
562+
ResourcesController.NewInstance.RunPsTest("Test-NewADApplication");
563+
}
564+
565+
[Fact]
566+
[Trait(Category.AcceptanceType, Category.CheckIn)]
567+
public void TestNewADServicePrincipal()
568+
{
569+
const string scriptMethod = "Test-NewADServicePrincipal '{0}'";
570+
Application application = null;
571+
var controllerAdmin = ResourcesController.NewInstance;
572+
573+
controllerAdmin.RunPsTestWorkflow(
574+
// scriptBuilder
575+
() =>
576+
{
577+
application = CreateNewAdApp(controllerAdmin);
578+
return new[] { string.Format(scriptMethod, application.AppId) };
579+
},
580+
// initialize
581+
null,
582+
// cleanup
583+
() =>
584+
{
585+
DeleteAdApp(controllerAdmin, application);
586+
},
587+
TestUtilities.GetCallingClass(),
588+
TestUtilities.GetCurrentMethodName());
589+
}
590+
558591
private User CreateNewAdUser(ResourcesController controllerAdmin)
559592
{
560593
var name = TestUtilities.GenerateName("aduser");

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,37 @@ function Test-GetADUserWithBadSearchString
432432
# Assert
433433
Assert-Null($users)
434434
}
435+
436+
<#
437+
.SYNOPSIS
438+
Tests Creating and deleting application.
439+
#>
440+
function Test-NewADApplication
441+
{
442+
# Setup
443+
$displayName = getAssetName
444+
$homePage = "http://" + $displayName + ".com"
445+
$identifierUri = "http://" + $displayName
446+
447+
# Test
448+
$application = New-AzureADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identifierUri
449+
450+
# Assert
451+
Assert-NotNull $application
452+
}
453+
454+
<#
455+
.SYNOPSIS
456+
Tests Creating and deleting service principal.
457+
#>
458+
function Test-NewADServicePrincipal
459+
{
460+
param([string]$applicationId)
461+
462+
# Test
463+
$servicePrincipal = New-AzureADServicePrincipal -ApplicationId $applicationId
464+
465+
# Assert
466+
Assert-NotNull $servicePrincipal
467+
}
468+

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/Common.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ function Get-ProviderLocation($provider)
4444
}
4545
}
4646

47+
<#
48+
.SYNOPSIS
49+
Gets valid application display name
50+
#>
51+
function Get-ApplicatonDisplayName
52+
{
53+
return getAssetName
54+
}
55+
4756
<#
4857
.SYNOPSIS
4958
Cleans the created resource groups

0 commit comments

Comments
 (0)