Skip to content

Commit bb9e4c9

Browse files
committed
Merge pull request Azure#1578 from vadimp-msft/dev
Azure RemoteApp: per-app publishing support
2 parents aecf42f + 357656c commit bb9e4c9

15 files changed

+454
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
<Reference Include="Microsoft.WindowsAzure.Management">
145145
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
146146
</Reference>
147-
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp">
148-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.3\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
147+
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
148+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.4\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
149149
</Reference>
150150
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
151151
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public abstract class RemoteAppClientTest : SMTestBase
6464

6565
protected const string remoteApplication = "Mohoro Test App";
6666

67+
protected const string appAlias = "9bd99659-9772-4689-af10-7ac72e43c28e";
68+
6769
protected Action<string> logger { get; private set; }
6870

6971
public MockCommandRuntime mockCommandRuntime { get; private set; }

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,46 @@ public static int SetUpDefaultRemoteAppSecurityPrincipals(Mock<IRemoteAppManagem
6565
return mockUsersConsents.Count;
6666
}
6767

68+
public static int SetUpRemoteAppSecurityPrincipalsForApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, string userName)
69+
{
70+
SecurityPrincipalInfoListResult response = new SecurityPrincipalInfoListResult();
71+
72+
response.SecurityPrincipalInfoList = new List<SecurityPrincipalInfo>()
73+
{
74+
new SecurityPrincipalInfo()
75+
{
76+
SecurityPrincipal = new SecurityPrincipal()
77+
{
78+
Name = userName,
79+
SecurityPrincipalType = PrincipalType.User,
80+
UserIdType = PrincipalProviderType.OrgId,
81+
},
82+
Status = ConsentStatus.Pending
83+
},
84+
new SecurityPrincipalInfo()
85+
{
86+
SecurityPrincipal = new SecurityPrincipal()
87+
{
88+
Name = "user2",
89+
SecurityPrincipalType = PrincipalType.User,
90+
UserIdType = PrincipalProviderType.OrgId,
91+
},
92+
Status = ConsentStatus.Pending
93+
},
94+
};
95+
96+
mockUsersConsents = new List<ConsentStatusModel>();
97+
foreach (SecurityPrincipalInfo consent in response.SecurityPrincipalInfoList)
98+
{
99+
mockUsersConsents.Add(new ConsentStatusModel(consent));
100+
};
101+
102+
ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalInfoListResult>> setup = clientMock.Setup(c => c.Principals.ListForAppAsync(collectionName, appAlias, It.IsAny<CancellationToken>()));
103+
setup.Returns(Task.Factory.StartNew(() => response));
104+
105+
return mockUsersConsents.Count;
106+
}
107+
68108
public static int SetUpRemoteAppUserToAdd(Mock<IRemoteAppManagementClient> clientMock, string collectionName, PrincipalProviderType userIdType, string[] userNames)
69109
{
70110
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
@@ -148,6 +188,89 @@ public static int SetUpDefaultRemoteAppUserToRemove(Mock<IRemoteAppManagementCli
148188
return mockUsers.Count;
149189
}
150190

191+
public static int SetUpRemoteAppUserToAddForApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, PrincipalProviderType userIdType, string[] userNames)
192+
{
193+
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
194+
{
195+
RequestId = "122-13342",
196+
TrackingId = "2334-323456",
197+
StatusCode = System.Net.HttpStatusCode.Accepted,
198+
Errors = null,
199+
};
200+
201+
mockSecurityPrincipalResult = new List<SecurityPrincipalOperationsResult>()
202+
{
203+
new SecurityPrincipalOperationsResult()
204+
{
205+
RequestId = response.RequestId,
206+
TrackingId = response.TrackingId,
207+
StatusCode = response.StatusCode,
208+
Errors = response.Errors
209+
},
210+
};
211+
212+
SecurityPrincipalList spAdd = new SecurityPrincipalList();
213+
214+
foreach (string userName in userNames)
215+
{
216+
SecurityPrincipal mockUser = new SecurityPrincipal()
217+
{
218+
Name = userName,
219+
SecurityPrincipalType = PrincipalType.User,
220+
UserIdType = userIdType,
221+
};
222+
spAdd.SecurityPrincipals.Add(mockUser);
223+
}
224+
225+
ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalOperationsResult>> setup = clientMock.Setup(c => c.Principals.AddToAppAsync(collectionName, appAlias, It.IsAny<SecurityPrincipalList>(), It.IsAny<CancellationToken>()));
226+
setup.Returns(Task.Factory.StartNew(() => response));
227+
228+
mockUsers = spAdd.SecurityPrincipals;
229+
230+
return mockUsers.Count;
231+
}
232+
233+
public static int SetUpRemoteAppUserToRemoveFromApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, PrincipalProviderType userIdType, string[] userNames)
234+
{
235+
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
236+
{
237+
RequestId = "122-13342",
238+
TrackingId = "1348570-182754",
239+
StatusCode = System.Net.HttpStatusCode.Accepted,
240+
Errors = null
241+
};
242+
mockSecurityPrincipalResult = new List<SecurityPrincipalOperationsResult>()
243+
{
244+
new SecurityPrincipalOperationsResult()
245+
{
246+
RequestId = response.RequestId,
247+
TrackingId = response.TrackingId,
248+
StatusCode = response.StatusCode,
249+
Errors = response.Errors
250+
},
251+
};
252+
253+
SecurityPrincipalList spRemove = new SecurityPrincipalList();
254+
255+
foreach (string userName in userNames)
256+
{
257+
SecurityPrincipal mockUser = new SecurityPrincipal()
258+
{
259+
Name = userName,
260+
SecurityPrincipalType = PrincipalType.User,
261+
UserIdType = userIdType,
262+
};
263+
spRemove.SecurityPrincipals.Add(mockUser);
264+
}
265+
266+
ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalOperationsResult>> setup = clientMock.Setup(c => c.Principals.DeleteFromAppAsync(collectionName, appAlias, It.IsAny<SecurityPrincipalList>(), It.IsAny<CancellationToken>()));
267+
setup.Returns(Task.Factory.StartNew(() => response));
268+
269+
mockUsers = spRemove.SecurityPrincipals;
270+
271+
return mockUsers.Count;
272+
}
273+
151274
public static bool ContainsExpectedServicePrincipalList(IList<LocalModels.ConsentStatusModel> expectedResult, IList<LocalModels.ConsentStatusModel> principalList)
152275
{
153276
bool isIdentical = false;

src/ServiceManagement/RemoteApp/Commands.RemoteApp.Test/SecurityPrincipals/RemoteAppSecurityPrincipals.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,51 @@ public void GetAllUsers()
7171
Log("The test for Get-AzureRemoteAppUser with {0} users completed successfully.", countOfExpectedUsers);
7272
}
7373

74+
[Fact]
75+
[Trait(Category.AcceptanceType, Category.CheckIn)]
76+
public void GetAllUsersForApp()
77+
{
78+
int countOfExpectedUsers = 0;
79+
GetAzureRemoteAppUser MockCmdlet = SetUpTestCommon<GetAzureRemoteAppUser>();
80+
81+
// Required parameters for this test
82+
MockCmdlet.CollectionName = collectionName;
83+
MockCmdlet.Alias = appAlias;
84+
85+
// Setup the environment for testing this cmdlet
86+
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
87+
countOfExpectedUsers = MockObject.SetUpRemoteAppSecurityPrincipalsForApp(remoteAppManagementClientMock, collectionName, appAlias, userName);
88+
MockCmdlet.ResetPipelines();
89+
90+
Log("Calling Get-AzureRemoteAppUser which should have {0} users.", countOfExpectedUsers);
91+
92+
MockCmdlet.ExecuteCmdlet();
93+
if (MockCmdlet.runTime().ErrorStream.Count != 0)
94+
{
95+
Assert.True(false,
96+
String.Format("Get-AzureRemoteAppUser returned the following error {0}.",
97+
MockCmdlet.runTime().ErrorStream[0].Exception.Message
98+
)
99+
);
100+
}
101+
102+
List<ConsentStatusModel> users = MockObject.ConvertList<ConsentStatusModel>(MockCmdlet.runTime().OutputPipeline);
103+
Assert.NotNull(users);
104+
105+
Assert.True(users.Count == countOfExpectedUsers,
106+
String.Format("The expected number of users returned {0} does not match the actual {1}.",
107+
countOfExpectedUsers,
108+
users.Count
109+
)
110+
);
111+
112+
Assert.True(MockObject.ContainsExpectedServicePrincipalList(MockObject.mockUsersConsents, users),
113+
"The actual result does not match the expected"
114+
);
115+
116+
Log("The test for Get-AzureRemoteAppUser with {0} users completed successfully.", countOfExpectedUsers);
117+
}
118+
74119
[Fact]
75120
[Trait(Category.AcceptanceType, Category.CheckIn)]
76121
public void GetUsersByName()
@@ -206,6 +251,97 @@ public void AddOrgIDUserThatDoesntExist()
206251
Log("The test for Add-AzureRemoteAppOrgIDUser successfully added {0} users the new count is {1}.", countOfNewUsers, countOfExistingUsers + countOfNewUsers);
207252
}
208253

254+
[Fact]
255+
[Trait(Category.AcceptanceType, Category.CheckIn)]
256+
public void AddUsersToApp()
257+
{
258+
int countOfExistingUsers = 0;
259+
int countOfNewUsers = 0;
260+
AddAzureRemoteAppUser MockCmdlet = SetUpTestCommon<AddAzureRemoteAppUser>();
261+
262+
// Required parameters for this test
263+
MockCmdlet.CollectionName = collectionName;
264+
MockCmdlet.Alias = appAlias;
265+
MockCmdlet.Type = PrincipalProviderType.OrgId;
266+
MockCmdlet.UserUpn = new string[]
267+
{
268+
"testUser1",
269+
"testUser2",
270+
};
271+
272+
// Setup the environment for testing this cmdlet
273+
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
274+
countOfExistingUsers = MockObject.SetUpDefaultRemoteAppSecurityPrincipals(remoteAppManagementClientMock, collectionName, userName);
275+
countOfNewUsers = MockObject.SetUpRemoteAppUserToAddForApp(remoteAppManagementClientMock, collectionName, appAlias, PrincipalProviderType.OrgId, MockCmdlet.UserUpn);
276+
MockCmdlet.ResetPipelines();
277+
278+
Log("Calling Add-AzureRemoteAppOrgIDUser and adding {0} users.", countOfNewUsers);
279+
280+
MockCmdlet.ExecuteCmdlet();
281+
if (MockCmdlet.runTime().ErrorStream.Count != 0)
282+
{
283+
Assert.True(false,
284+
String.Format("Add-AzureRemoteAppOrgIDUser returned the following error {0}.",
285+
MockCmdlet.runTime().ErrorStream[0].Exception.Message
286+
)
287+
);
288+
}
289+
290+
List<SecurityPrincipalOperationsResult> status = MockObject.ConvertList<SecurityPrincipalOperationsResult>(MockCmdlet.runTime().OutputPipeline);
291+
Assert.NotNull(status);
292+
293+
Assert.True(MockObject.HasExpectedResults<SecurityPrincipalOperationsResult>(status, MockObject.ContainsExpectedStatus),
294+
"The actual result does not match the expected."
295+
);
296+
297+
Log("The test for Add-AzureRemoteAppOrgIDUser successfully added {0} users the new count is {1}.", countOfNewUsers, countOfExistingUsers + countOfNewUsers);
298+
}
299+
300+
[Fact]
301+
[Trait(Category.AcceptanceType, Category.CheckIn)]
302+
public void RemoveUserThatExistsFromApp()
303+
{
304+
int countOfExistingUsers = 0;
305+
int countOfDeletedUsers = 0;
306+
RemoveAzureRemoteAppUser MockCmdlet = SetUpTestCommon<RemoveAzureRemoteAppUser>();
307+
308+
// Required parameters for this test
309+
MockCmdlet.CollectionName = collectionName;
310+
MockCmdlet.Alias = appAlias;
311+
MockCmdlet.Type = PrincipalProviderType.OrgId;
312+
MockCmdlet.UserUpn = new string[]
313+
{
314+
userName
315+
};
316+
317+
// Setup the environment for testing this cmdlet
318+
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
319+
countOfExistingUsers = MockObject.SetUpDefaultRemoteAppSecurityPrincipals(remoteAppManagementClientMock, collectionName, userName);
320+
countOfDeletedUsers = MockObject.SetUpRemoteAppUserToRemoveFromApp(remoteAppManagementClientMock, collectionName, appAlias, PrincipalProviderType.OrgId, MockCmdlet.UserUpn);
321+
MockCmdlet.ResetPipelines();
322+
323+
Log("Calling Remove-AzureRemoteAppOrgIdUser and removing {0} users.", countOfDeletedUsers);
324+
325+
MockCmdlet.ExecuteCmdlet();
326+
if (MockCmdlet.runTime().ErrorStream.Count != 0)
327+
{
328+
Assert.True(false,
329+
String.Format("Remove-AzureRemoteAppMSAUser returned the following error {0}.",
330+
MockCmdlet.runTime().ErrorStream[0].Exception.Message
331+
)
332+
);
333+
}
334+
335+
List<SecurityPrincipalOperationsResult> status = MockObject.ConvertList<SecurityPrincipalOperationsResult>(MockCmdlet.runTime().OutputPipeline);
336+
Assert.NotNull(status);
337+
338+
Assert.True(MockObject.HasExpectedResults<SecurityPrincipalOperationsResult>(status, MockObject.ContainsExpectedStatus),
339+
"The actual result does not match the expected."
340+
);
341+
342+
Log("The test for Remove-AzureRemoteAppOrgIdUser successfully removed {0} users the new count is {1}.", countOfDeletedUsers, countOfExistingUsers - countOfDeletedUsers);
343+
}
344+
209345
[Fact]
210346
[Trait(Category.AcceptanceType, Category.CheckIn)]
211347
public void RemoveMSAUserThatExists()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<package id="Microsoft.Rest.ClientRuntime" version="1.8.2" targetFramework="net45" />
1414
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.11.0" targetFramework="net45" />
1515
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
16-
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.3" targetFramework="net45" />
16+
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.4" targetFramework="net45" />
1717
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
1818
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
1919
<package id="xunit" version="1.9.2" targetFramework="net45" />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LocalModels
8+
{
9+
public enum CollectionAclLevel
10+
{
11+
Collection,
12+
Application
13+
}
14+
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/Model/Collections.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public Collection(Microsoft.WindowsAzure.Management.RemoteApp.Models.Collection
4242
TemplateImageName = col.TemplateImageName;
4343
TrialOnly = col.TrialOnly;
4444
VNetName = String.IsNullOrWhiteSpace(col.VNetName) || col.VNetName.StartsWith ("simplevnet-") ? "" : col.VNetName;
45+
AclLevel = col.AclLevel;
4546
}
4647
}
4748
}

0 commit comments

Comments
 (0)