Skip to content

Commit cecc059

Browse files
authored
Merge pull request Azure#2963 from arcadiahlyy/dev
Admin Export Template Image: Add Ops, TA Cmdlet and security check for exporting template image out of ARA
2 parents 190da02 + e533dbf commit cecc059

File tree

14 files changed

+706
-14
lines changed

14 files changed

+706
-14
lines changed

src/ServiceManagement/RemoteApp/Commands.RemoteApp.ScenarioTest/Commands.RemoteAppScenarioTest.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@
8282
<Reference Include="Microsoft.WindowsAzure.Management">
8383
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
8484
</Reference>
85-
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
86-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
85+
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
86+
<SpecificVersion>False</SpecificVersion>
87+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
8788
</Reference>
8889
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
8990
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
@@ -160,4 +161,4 @@
160161
<Target Name="AfterBuild">
161162
</Target>
162163
-->
163-
</Project>
164+
</Project>

src/ServiceManagement/RemoteApp/Commands.RemoteApp.ScenarioTest/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.8-preview" targetFramework="net45" />
2020
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
2121
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
22+
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.7" targetFramework="net45" />
2223
<package id="Microsoft.WindowsAzure.Management.WebSites" version="4.4.2-prerelease" targetFramework="net45" />
2324
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
2425
<package id="System.Spatial" version="5.6.4" targetFramework="net45" />

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Commands.RemoteApp.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@
148148
<Reference Include="Microsoft.WindowsAzure.Management">
149149
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
150150
</Reference>
151-
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
152-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
151+
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
152+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
153153
</Reference>
154154
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
155155
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/RemoteAppClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public abstract class RemoteAppClientTest : SMTestBase
7070

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

73+
protected const string storageAccountName = "testsaname";
74+
75+
protected const string storageAccountKey = "testsakey";
76+
77+
protected const string containerName = "testcontainername";
78+
7379
protected Action<string> logger { get; private set; }
7480

7581
public MockCommandRuntime mockCommandRuntime { get; private set; }

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/TemplateObjects.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,24 @@ public static bool ContainsExpectedResult(List<TemplateImageResult> expectedResu
342342

343343
return isIdentical;
344344
}
345+
346+
public static void SetUpDefaultRemoteAppExportTemplateImage(Mock<IRemoteAppManagementClient> clientMock, string sourceCollectionName, string DestinationStorageAccountName, string DestinationStorageAccountKey, string DestinationStorageAccountContainerName, string trackingId)
347+
{
348+
OperationResultWithTrackingId response = new OperationResultWithTrackingId()
349+
{
350+
StatusCode = System.Net.HttpStatusCode.Accepted,
351+
TrackingId = trackingId,
352+
RequestId = "02111-222-3456"
353+
};
354+
355+
mockTrackingId = new List<TrackingResult>()
356+
{
357+
new TrackingResult(response)
358+
};
359+
360+
ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup =
361+
clientMock.Setup(c => c.TemplateImages.MigrateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
362+
setup.Returns(Task.Factory.StartNew(() => response));
363+
}
345364
}
346365
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Common/UserDiskObjects.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Microsoft.WindowsAzure.Commands.RemoteApp.Test.Common
1616
{
1717
using Microsoft.WindowsAzure.Management.RemoteApp;
18+
using Microsoft.WindowsAzure.Management.RemoteApp.Models;
1819
using Microsoft.Azure;
1920
using Moq;
2021
using Moq.Language.Flow;
@@ -49,5 +50,24 @@ public static void SetUpDefaultRemoteAppCopyUserDisk(Mock<IRemoteAppManagementCl
4950
clientMock.Setup(c => c.UserDisks.CopyAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
5051
setup.Returns(Task.Factory.StartNew(() => response));
5152
}
53+
54+
public static void SetUpDefaultRemoteAppExportUserDisk(Mock<IRemoteAppManagementClient> clientMock, string sourceCollectionName, string DestinationStorageAccountName, string DestinationStorageAccountKey, string DestinationStorageAccountContainerName, string trackingId)
55+
{
56+
OperationResultWithTrackingId response = new OperationResultWithTrackingId()
57+
{
58+
StatusCode = System.Net.HttpStatusCode.Accepted,
59+
TrackingId = trackingId,
60+
RequestId = "02111-222-3456"
61+
};
62+
63+
mockTrackingId = new List<TrackingResult>()
64+
{
65+
new TrackingResult(response)
66+
};
67+
68+
ISetup<IRemoteAppManagementClient, Task<OperationResultWithTrackingId>> setup =
69+
clientMock.Setup(c => c.UserDisks.MigrateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()));
70+
setup.Returns(Task.Factory.StartNew(() => response));
71+
}
5272
}
5373
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/Templates/RemoteAppTemplates.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,40 @@ public void RemoveTemplate()
187187

188188
Log("The test for Remove-AzureRemoteAppTemplate completed successfully");
189189
}
190+
191+
[Fact]
192+
[Trait(Category.AcceptanceType, Category.CheckIn)]
193+
public void ExportTemplateImage()
194+
{
195+
List<TrackingResult> trackingIds = null;
196+
ExportAzureRemoteAppTemplateImage mockCmdlet = SetUpTestCommon<ExportAzureRemoteAppTemplateImage>();
197+
198+
// Required parameters for this test
199+
mockCmdlet.CollectionName = collectionName;
200+
mockCmdlet.DestinationStorageAccountName = storageAccountName;
201+
mockCmdlet.DestinationStorageAccountKey = storageAccountKey;
202+
mockCmdlet.DestinationStorageAccountContainerName = containerName;
203+
204+
// Setup the environment for testing this cmdlet
205+
MockObject.SetUpDefaultRemoteAppExportTemplateImage(remoteAppManagementClientMock, mockCmdlet.CollectionName, mockCmdlet.DestinationStorageAccountName, mockCmdlet.DestinationStorageAccountKey, mockCmdlet.DestinationStorageAccountContainerName, trackingId);
206+
mockCmdlet.ResetPipelines();
207+
208+
Log("Calling Export-AzureRemoteAppTemplateImage");
209+
210+
mockCmdlet.ExecuteCmdlet();
211+
if (mockCmdlet.runTime().ErrorStream.Count != 0)
212+
{
213+
Assert.True(false,
214+
String.Format("Export-AzureRemoteAppTemplateImage returned the following error {0}",
215+
mockCmdlet.runTime().ErrorStream[0].Exception.Message
216+
)
217+
);
218+
}
219+
220+
trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline);
221+
Assert.NotNull(trackingIds);
222+
223+
Log("The test for Export-AzureRemoteAppTemplateImage completed successfully");
224+
}
190225
}
191226
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/UserDisk/RemoteAppUserDisk.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,47 @@ public void CopyUserDisk()
7373
if (mockCmdlet.runTime().ErrorStream.Count != 0)
7474
{
7575
Assert.True(false,
76-
String.Format("Copy-AzureRemoteAppTemplate returned the following error {0}",
76+
String.Format("Copy-AzureRemoteAppUserDisk returned the following error {0}",
7777
mockCmdlet.runTime().ErrorStream[0].Exception.Message
7878
)
7979
);
8080
}
8181

82-
Log("The test for Copy-AzureRemoteAppTemplate completed successfully");
82+
Log("The test for Copy-AzureRemoteAppUserDisk completed successfully");
83+
}
84+
85+
[Fact]
86+
[Trait(Category.AcceptanceType, Category.CheckIn)]
87+
public void ExportUserDisk()
88+
{
89+
List<TrackingResult> trackingIds = null;
90+
ExportAzureRemoteAppUserDisk mockCmdlet = SetUpTestCommon<ExportAzureRemoteAppUserDisk>();
91+
92+
// Required parameters for this test
93+
mockCmdlet.CollectionName = collectionName;
94+
mockCmdlet.DestinationStorageAccountName = storageAccountName;
95+
mockCmdlet.DestinationStorageAccountKey = storageAccountKey;
96+
mockCmdlet.DestinationStorageAccountContainerName = containerName;
97+
98+
MockObject.SetUpDefaultRemoteAppExportUserDisk(remoteAppManagementClientMock, mockCmdlet.CollectionName, mockCmdlet.DestinationStorageAccountName, mockCmdlet.DestinationStorageAccountKey, mockCmdlet.DestinationStorageAccountContainerName, trackingId);
99+
mockCmdlet.ResetPipelines();
100+
101+
Log("Calling Export-AzureRemoteAppUserDisk");
102+
103+
mockCmdlet.ExecuteCmdlet();
104+
if (mockCmdlet.runTime().ErrorStream.Count != 0)
105+
{
106+
Assert.True(false,
107+
String.Format("Export-AzureRemoteAppUserDisk returned the following error {0}",
108+
mockCmdlet.runTime().ErrorStream[0].Exception.Message
109+
)
110+
);
111+
}
112+
113+
trackingIds = MockObject.ConvertList<TrackingResult>(mockCmdlet.runTime().OutputPipeline);
114+
Assert.NotNull(trackingIds);
115+
116+
Log("The test for Export-AzureRemoteAppUserDisk completed successfully");
83117
}
84118
}
85119
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net45" />
1313
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.8-preview" targetFramework="net45" />
1414
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
15-
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.6" targetFramework="net45" />
15+
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.7" targetFramework="net45" />
1616
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
1717
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
1818
<package id="xunit" version="2.1.0" targetFramework="net45" />

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Commands.RemoteApp.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@
111111
</Reference>
112112
<Reference Include="Microsoft.WindowsAzure.Management.Network, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
113113
<SpecificVersion>False</SpecificVersion>
114-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.8.0.0\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
114+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Network.8.0.0\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
115115
</Reference>
116-
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
116+
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.7.0, Culture=neutral, processorArchitecture=MSIL">
117117
<SpecificVersion>False</SpecificVersion>
118-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.6\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
118+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.7\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
119119
</Reference>
120120
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
121121
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.6.0.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
@@ -215,11 +215,13 @@
215215
<Compile Include="TemplateImage\GetAzureRemoteAppTemplateImage.cs" />
216216
<Compile Include="Sessions\GetAzureRemoteAppSession.cs" />
217217
<Compile Include="SecurityPrincipals\GetAzureRemoteAppUser.cs" />
218+
<Compile Include="TemplateImage\ExportAzureRemoteAppTemplateImage.cs" />
218219
<Compile Include="TemplateImage\NewAzureRemoteAppTemplateImage.cs" />
219220
<Compile Include="TemplateImage\RemoveAzureRemoteAppTemplateImage.cs" />
220221
<Compile Include="TemplateImage\RenameAzureRemoteAppTemplateImage.cs" />
221222
<Compile Include="TemplateImage\TemplateImage.cs" />
222223
<Compile Include="UserDisk\CopyAzureRemoteAppUserDisk.cs" />
224+
<Compile Include="UserDisk\ExportAzureRemoteAppUserDisk.cs" />
223225
<Compile Include="UserDisk\RemoveAzureRemoteAppUserDisk.cs" />
224226
<Compile Include="Vm\ClearAzureRemoteAppVmStaleAdObject.cs" />
225227
<Compile Include="Vm\GetAzureRemoteAppVm.cs" />

0 commit comments

Comments
 (0)