Skip to content

. #297

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 5 commits into from
Jan 5, 2016
Merged

. #297

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 @@ -144,8 +144,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">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.3\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Management.RemoteApp, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.RemoteApp.2.0.4\lib\net40\Microsoft.WindowsAzure.Management.RemoteApp.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public abstract class RemoteAppClientTest : SMTestBase

protected const string remoteApplication = "Mohoro Test App";

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

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 @@ -65,6 +65,46 @@ public static int SetUpDefaultRemoteAppSecurityPrincipals(Mock<IRemoteAppManagem
return mockUsersConsents.Count;
}

public static int SetUpRemoteAppSecurityPrincipalsForApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, string userName)
{
SecurityPrincipalInfoListResult response = new SecurityPrincipalInfoListResult();

response.SecurityPrincipalInfoList = new List<SecurityPrincipalInfo>()
{
new SecurityPrincipalInfo()
{
SecurityPrincipal = new SecurityPrincipal()
{
Name = userName,
SecurityPrincipalType = PrincipalType.User,
UserIdType = PrincipalProviderType.OrgId,
},
Status = ConsentStatus.Pending
},
new SecurityPrincipalInfo()
{
SecurityPrincipal = new SecurityPrincipal()
{
Name = "user2",
SecurityPrincipalType = PrincipalType.User,
UserIdType = PrincipalProviderType.OrgId,
},
Status = ConsentStatus.Pending
},
};

mockUsersConsents = new List<ConsentStatusModel>();
foreach (SecurityPrincipalInfo consent in response.SecurityPrincipalInfoList)
{
mockUsersConsents.Add(new ConsentStatusModel(consent));
};

ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalInfoListResult>> setup = clientMock.Setup(c => c.Principals.ListForAppAsync(collectionName, appAlias, It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));

return mockUsersConsents.Count;
}

public static int SetUpRemoteAppUserToAdd(Mock<IRemoteAppManagementClient> clientMock, string collectionName, PrincipalProviderType userIdType, string[] userNames)
{
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
Expand Down Expand Up @@ -148,6 +188,89 @@ public static int SetUpDefaultRemoteAppUserToRemove(Mock<IRemoteAppManagementCli
return mockUsers.Count;
}

public static int SetUpRemoteAppUserToAddForApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, PrincipalProviderType userIdType, string[] userNames)
{
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
{
RequestId = "122-13342",
TrackingId = "2334-323456",
StatusCode = System.Net.HttpStatusCode.Accepted,
Errors = null,
};

mockSecurityPrincipalResult = new List<SecurityPrincipalOperationsResult>()
{
new SecurityPrincipalOperationsResult()
{
RequestId = response.RequestId,
TrackingId = response.TrackingId,
StatusCode = response.StatusCode,
Errors = response.Errors
},
};

SecurityPrincipalList spAdd = new SecurityPrincipalList();

foreach (string userName in userNames)
{
SecurityPrincipal mockUser = new SecurityPrincipal()
{
Name = userName,
SecurityPrincipalType = PrincipalType.User,
UserIdType = userIdType,
};
spAdd.SecurityPrincipals.Add(mockUser);
}

ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalOperationsResult>> setup = clientMock.Setup(c => c.Principals.AddToAppAsync(collectionName, appAlias, It.IsAny<SecurityPrincipalList>(), It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));

mockUsers = spAdd.SecurityPrincipals;

return mockUsers.Count;
}

public static int SetUpRemoteAppUserToRemoveFromApp(Mock<IRemoteAppManagementClient> clientMock, string collectionName, string appAlias, PrincipalProviderType userIdType, string[] userNames)
{
SecurityPrincipalOperationsResult response = new SecurityPrincipalOperationsResult()
{
RequestId = "122-13342",
TrackingId = "1348570-182754",
StatusCode = System.Net.HttpStatusCode.Accepted,
Errors = null
};
mockSecurityPrincipalResult = new List<SecurityPrincipalOperationsResult>()
{
new SecurityPrincipalOperationsResult()
{
RequestId = response.RequestId,
TrackingId = response.TrackingId,
StatusCode = response.StatusCode,
Errors = response.Errors
},
};

SecurityPrincipalList spRemove = new SecurityPrincipalList();

foreach (string userName in userNames)
{
SecurityPrincipal mockUser = new SecurityPrincipal()
{
Name = userName,
SecurityPrincipalType = PrincipalType.User,
UserIdType = userIdType,
};
spRemove.SecurityPrincipals.Add(mockUser);
}

ISetup<IRemoteAppManagementClient, Task<SecurityPrincipalOperationsResult>> setup = clientMock.Setup(c => c.Principals.DeleteFromAppAsync(collectionName, appAlias, It.IsAny<SecurityPrincipalList>(), It.IsAny<CancellationToken>()));
setup.Returns(Task.Factory.StartNew(() => response));

mockUsers = spRemove.SecurityPrincipals;

return mockUsers.Count;
}

public static bool ContainsExpectedServicePrincipalList(IList<LocalModels.ConsentStatusModel> expectedResult, IList<LocalModels.ConsentStatusModel> principalList)
{
bool isIdentical = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,51 @@ public void GetAllUsers()
Log("The test for Get-AzureRemoteAppUser with {0} users completed successfully.", countOfExpectedUsers);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetAllUsersForApp()
{
int countOfExpectedUsers = 0;
GetAzureRemoteAppUser MockCmdlet = SetUpTestCommon<GetAzureRemoteAppUser>();

// Required parameters for this test
MockCmdlet.CollectionName = collectionName;
MockCmdlet.Alias = appAlias;

// Setup the environment for testing this cmdlet
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
countOfExpectedUsers = MockObject.SetUpRemoteAppSecurityPrincipalsForApp(remoteAppManagementClientMock, collectionName, appAlias, userName);
MockCmdlet.ResetPipelines();

Log("Calling Get-AzureRemoteAppUser which should have {0} users.", countOfExpectedUsers);

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

List<ConsentStatusModel> users = MockObject.ConvertList<ConsentStatusModel>(MockCmdlet.runTime().OutputPipeline);
Assert.NotNull(users);

Assert.True(users.Count == countOfExpectedUsers,
String.Format("The expected number of users returned {0} does not match the actual {1}.",
countOfExpectedUsers,
users.Count
)
);

Assert.True(MockObject.ContainsExpectedServicePrincipalList(MockObject.mockUsersConsents, users),
"The actual result does not match the expected"
);

Log("The test for Get-AzureRemoteAppUser with {0} users completed successfully.", countOfExpectedUsers);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetUsersByName()
Expand Down Expand Up @@ -206,6 +251,97 @@ public void AddOrgIDUserThatDoesntExist()
Log("The test for Add-AzureRemoteAppOrgIDUser successfully added {0} users the new count is {1}.", countOfNewUsers, countOfExistingUsers + countOfNewUsers);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void AddUsersToApp()
{
int countOfExistingUsers = 0;
int countOfNewUsers = 0;
AddAzureRemoteAppUser MockCmdlet = SetUpTestCommon<AddAzureRemoteAppUser>();

// Required parameters for this test
MockCmdlet.CollectionName = collectionName;
MockCmdlet.Alias = appAlias;
MockCmdlet.Type = PrincipalProviderType.OrgId;
MockCmdlet.UserUpn = new string[]
{
"testUser1",
"testUser2",
};

// Setup the environment for testing this cmdlet
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
countOfExistingUsers = MockObject.SetUpDefaultRemoteAppSecurityPrincipals(remoteAppManagementClientMock, collectionName, userName);
countOfNewUsers = MockObject.SetUpRemoteAppUserToAddForApp(remoteAppManagementClientMock, collectionName, appAlias, PrincipalProviderType.OrgId, MockCmdlet.UserUpn);
MockCmdlet.ResetPipelines();

Log("Calling Add-AzureRemoteAppOrgIDUser and adding {0} users.", countOfNewUsers);

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

List<SecurityPrincipalOperationsResult> status = MockObject.ConvertList<SecurityPrincipalOperationsResult>(MockCmdlet.runTime().OutputPipeline);
Assert.NotNull(status);

Assert.True(MockObject.HasExpectedResults<SecurityPrincipalOperationsResult>(status, MockObject.ContainsExpectedStatus),
"The actual result does not match the expected."
);

Log("The test for Add-AzureRemoteAppOrgIDUser successfully added {0} users the new count is {1}.", countOfNewUsers, countOfExistingUsers + countOfNewUsers);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveUserThatExistsFromApp()
{
int countOfExistingUsers = 0;
int countOfDeletedUsers = 0;
RemoveAzureRemoteAppUser MockCmdlet = SetUpTestCommon<RemoveAzureRemoteAppUser>();

// Required parameters for this test
MockCmdlet.CollectionName = collectionName;
MockCmdlet.Alias = appAlias;
MockCmdlet.Type = PrincipalProviderType.OrgId;
MockCmdlet.UserUpn = new string[]
{
userName
};

// Setup the environment for testing this cmdlet
MockObject.SetUpDefaultRemoteAppCollectionByName(remoteAppManagementClientMock, collectionName);
countOfExistingUsers = MockObject.SetUpDefaultRemoteAppSecurityPrincipals(remoteAppManagementClientMock, collectionName, userName);
countOfDeletedUsers = MockObject.SetUpRemoteAppUserToRemoveFromApp(remoteAppManagementClientMock, collectionName, appAlias, PrincipalProviderType.OrgId, MockCmdlet.UserUpn);
MockCmdlet.ResetPipelines();

Log("Calling Remove-AzureRemoteAppOrgIdUser and removing {0} users.", countOfDeletedUsers);

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

List<SecurityPrincipalOperationsResult> status = MockObject.ConvertList<SecurityPrincipalOperationsResult>(MockCmdlet.runTime().OutputPipeline);
Assert.NotNull(status);

Assert.True(MockObject.HasExpectedResults<SecurityPrincipalOperationsResult>(status, MockObject.ContainsExpectedStatus),
"The actual result does not match the expected."
);

Log("The test for Remove-AzureRemoteAppOrgIdUser successfully removed {0} users the new count is {1}.", countOfDeletedUsers, countOfExistingUsers - countOfDeletedUsers);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveMSAUserThatExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<package id="Microsoft.Rest.ClientRuntime" version="1.8.2" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="0.11.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management.RemoteApp" version="2.0.4" targetFramework="net45" />
<package id="Moq" version="4.2.1402.2112" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocalModels
{
public enum CollectionAclLevel
{
Collection,
Application
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Collection(Microsoft.WindowsAzure.Management.RemoteApp.Models.Collection
TemplateImageName = col.TemplateImageName;
TrialOnly = col.TrialOnly;
VNetName = String.IsNullOrWhiteSpace(col.VNetName) || col.VNetName.StartsWith ("simplevnet-") ? "" : col.VNetName;
AclLevel = col.AclLevel;
}
}
}
Loading