Skip to content

Admin Export Template Image: Add Ops, TA Cmdlet and security check for exporting template image out of ARA #2963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
Expand Down Expand Up @@ -160,4 +161,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.8-preview" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.7" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.WebSites" version="4.4.2-prerelease" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public abstract class RemoteAppClientTest : SMTestBase

protected const string appAlias = "9bd99659-9772-4689-af10-7ac72e43c28e";

protected const string storageAccountName = "testsaname";

protected const string storageAccountKey = "testsakey";

protected const string containerName = "testcontainername";

protected Action<string> logger { get; private set; }

public MockCommandRuntime mockCommandRuntime { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,24 @@ public static bool ContainsExpectedResult(List<TemplateImageResult> expectedResu

return isIdentical;
}

public static void SetUpDefaultRemoteAppExportTemplateImage(Mock<IRemoteAppManagementClient> clientMock, string sourceCollectionName, string DestinationStorageAccountName, string DestinationStorageAccountKey, string DestinationStorageAccountContainerName, string trackingId)
{
OperationResultWithTrackingId response = new OperationResultWithTrackingId()
{
StatusCode = System.Net.HttpStatusCode.Accepted,
TrackingId = trackingId,
RequestId = "02111-222-3456"
};

mockTrackingId = new List<TrackingResult>()
{
new TrackingResult(response)
};

ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup =
clientMock.Setup(c => c.TemplateImages.MigrateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test.Common
{
using Microsoft.WindowsAzure.Management.RemoteApp;
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
using Microsoft.Azure;
using Moq;
using Moq.Language.Flow;
Expand Down Expand Up @@ -49,5 +50,24 @@ public static void SetUpDefaultRemoteAppCopyUserDisk(Mock<IRemoteAppManagementCl
clientMock.Setup(c => c.UserDisks.CopyAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));
}

public static void SetUpDefaultRemoteAppExportUserDisk(Mock<IRemoteAppManagementClient> clientMock, string sourceCollectionName, string DestinationStorageAccountName, string DestinationStorageAccountKey, string DestinationStorageAccountContainerName, string trackingId)
{
OperationResultWithTrackingId response = new OperationResultWithTrackingId()
{
StatusCode = System.Net.HttpStatusCode.Accepted,
TrackingId = trackingId,
RequestId = "02111-222-3456"
};

mockTrackingId = new List<TrackingResult>()
{
new TrackingResult(response)
};

ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup =
clientMock.Setup(c => c.UserDisks.MigrateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,40 @@ public void RemoveTemplate()

Log("The test for Remove-AzureRemoteAppTemplate completed successfully");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ExportTemplateImage()
{
List<TrackingResult> trackingIds = null;
ExportAzureRemoteAppTemplateImage mockCmdlet = SetUpTestCommon<ExportAzureRemoteAppTemplateImage>();

// Required parameters for this test
mockCmdlet.CollectionName = collectionName;
mockCmdlet.DestinationStorageAccountName = storageAccountName;
mockCmdlet.DestinationStorageAccountKey = storageAccountKey;
mockCmdlet.DestinationStorageAccountContainerName = containerName;

// Setup the environment for testing this cmdlet
MockObject.SetUpDefaultRemoteAppExportTemplateImage(remoteAppManagementClientMock, mockCmdlet.CollectionName, mockCmdlet.DestinationStorageAccountName, mockCmdlet.DestinationStorageAccountKey, mockCmdlet.DestinationStorageAccountContainerName, trackingId);
mockCmdlet.ResetPipelines();

Log("Calling Export-AzureRemoteAppTemplateImage");

mockCmdlet.ExecuteCmdlet();
if (mockCmdlet.runTime().ErrorStream.Count != 0)
{
Assert.True(false,
String.Format("Export-AzureRemoteAppTemplateImage returned the following error {0}",
mockCmdlet.runTime().ErrorStream[0].Exception.Message
)
);
}

trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline);
Assert.NotNull(trackingIds);

Log("The test for Export-AzureRemoteAppTemplateImage completed successfully");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,47 @@ public void CopyUserDisk()
if (mockCmdlet.runTime().ErrorStream.Count != 0)
{
Assert.True(false,
String.Format("Copy-AzureRemoteAppTemplate returned the following error {0}",
String.Format("Copy-AzureRemoteAppUserDisk returned the following error {0}",
mockCmdlet.runTime().ErrorStream[0].Exception.Message
)
);
}

Log("The test for Copy-AzureRemoteAppTemplate completed successfully");
Log("The test for Copy-AzureRemoteAppUserDisk completed successfully");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ExportUserDisk()
{
List<TrackingResult> trackingIds = null;
ExportAzureRemoteAppUserDisk mockCmdlet = SetUpTestCommon<ExportAzureRemoteAppUserDisk>();

// Required parameters for this test
mockCmdlet.CollectionName = collectionName;
mockCmdlet.DestinationStorageAccountName = storageAccountName;
mockCmdlet.DestinationStorageAccountKey = storageAccountKey;
mockCmdlet.DestinationStorageAccountContainerName = containerName;

MockObject.SetUpDefaultRemoteAppExportUserDisk(remoteAppManagementClientMock, mockCmdlet.CollectionName, mockCmdlet.DestinationStorageAccountName, mockCmdlet.DestinationStorageAccountKey, mockCmdlet.DestinationStorageAccountContainerName, trackingId);
mockCmdlet.ResetPipelines();

Log("Calling Export-AzureRemoteAppUserDisk");

mockCmdlet.ExecuteCmdlet();
if (mockCmdlet.runTime().ErrorStream.Count != 0)
{
Assert.True(false,
String.Format("Export-AzureRemoteAppUserDisk returned the following error {0}",
mockCmdlet.runTime().ErrorStream[0].Exception.Message
)
);
}

trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline);
Assert.NotNull(trackingIds);

Log("The test for Export-AzureRemoteAppUserDisk completed successfully");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.8-preview" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.6" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.7" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Network, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.8.0.0\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.8.0.0\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.6.0.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
Expand Down Expand Up @@ -215,11 +215,13 @@
<Compile Include="TemplateImage\GetAzureRemoteAppTemplateImage.cs" />
<Compile Include="Sessions\GetAzureRemoteAppSession.cs" />
<Compile Include="SecurityPrincipals\GetAzureRemoteAppUser.cs" />
<Compile Include="TemplateImage\ExportAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\NewAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\RemoveAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\RenameAzureRemoteAppTemplateImage.cs" />
<Compile Include="TemplateImage\TemplateImage.cs" />
<Compile Include="UserDisk\CopyAzureRemoteAppUserDisk.cs" />
<Compile Include="UserDisk\ExportAzureRemoteAppUserDisk.cs" />
<Compile Include="UserDisk\RemoveAzureRemoteAppUserDisk.cs" />
<Compile Include="Vm\ClearAzureRemoteAppVmStaleAdObject.cs" />
<Compile Include="Vm\GetAzureRemoteAppVm.cs" />
Expand Down
Loading