Skip to content
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

Add scripts for setting up and tearing down AAD environment for tests #97

Merged
merged 45 commits into from
Oct 18, 2018

Conversation

brandonpollett
Copy link
Contributor

No description provided.

@johnstairs
Copy link
Member

As discussed, it probably makes sense to fold in ConvertTo-FlattenedConfigurationHashtable.ps1 to the module.

* Formatting scripts
* Moving ConvertTo-FlattenedConfigurationHashtable.ps1 out of module
* Changing `TestAuthorizationEnvironment` to `TestAuthEnvironment`
* Adding timeout to sleep loop
$appRolesToEnable = $false
$desiredAppRoles = @()

if ($RoleConfiguration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need this check anymore since the validation is already happening above.

Description = $role.name
DisplayName = $role.name
Id = $id
IsEnabled = "true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be string "true" or boolean true?

}
}

if (!($azureAdApplication.PsObject.Properties.Name -eq "AppRoles")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more readable if we use -contains? Name property is an array and -eq returns items matching the value but it "feels" a little odd ot use -eq on array? (maybe just me)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although.. i am not sure what it would do if Name only contains 1 item.

foreach ($diff in Compare-Object -ReferenceObject $desiredAppRoles -DifferenceObject $azureAdApplication.AppRoles -Property "Id") {
switch ($diff.SideIndicator) {
"<=" {
$appRolesToEnable = $true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a little bit of comment describing the logic would help here. The AppRole should be enabled if $auzreAdApplication.PsObject.Properties.Name contains "AppRoles" or one of the newly specified role is not in the application already?

}
}

if ($appRolesToEnable -or $appRolesToDisable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't really need this line?

            if ($appRolesToDisable) {
                Write-Host "Disabling old appRoles"
                Set-AzureADApplication -ObjectId $azureAdApplication.objectId -appRoles $azureAdApplication.AppRoles | Out-Null
            }

            if ($appRolesToEnable) {
                # Update app roles 
                Write-Host "Updating appRoles"
                Set-AzureADApplication -ObjectId $azureAdApplication.objectId -appRoles $desiredAppRoles | Out-Null
            }

foreach ($user in $UserConfiguration) {
$userId = $user.id
if ($UserNamePrefix) {
$userId = Get-UserId -EnvironmentName $UserNamePrefix -UserId $user.Id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should -EnvironmentName be renamed to -Prefix? It's simply prepending the prefix to the username so -EnvironmentName feels a little weird?

Set-AzureADUserPassword -ObjectId $aadUser.ObjectId -Password $passwordSecureString -EnforceChangePasswordPolicy $false -ForceChangePasswordNextLogin $false
}
else {
$PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be lowercase since it's a variable $passwordProfile


$environmentUsers += @{
upn = $userUpn
environmentId = $userId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: envrionmentId = $userId seems a little weird?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it's not a good name. Basically I want to return the environment specific user id, so something like pr-123-john.


if (!$keyVault) {
Write-Host "Creating keyvault with the name ${keyVaultName}"
New-AzureRmKeyVault -VaultName $keyVaultName -ResourceGroupName ${EnvironmentName} -Location 'East US' | Out-Null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should KeyVault always be created in East US?


Write-Host "Ensuring client application exists"
foreach ($clientApp in $TestAuthEnvironment.ClientApplications) {
$displayName = "${EnvironmentName}-$($clientApp.Id)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: most of the other scripts are using $EnvironmentName for simple variables instead of ${EnvironmentName}. Should we keep them consistent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this format is used in both Add-AadTestAuthEnvironment and Remove-AadTestAuthEnvironment. Should it be extracted to shared module?


Write-Host "Tearing down test authorization environment for AAD"

$TestAuthEnvironment = Get-Content -Raw -Path $TestAuthEnvironmentPath | ConvertFrom-Json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase $testAuthEnvironment


Write-Host "Setting up Test Authorization Environment for AAD"

$TestAuthEnvironment = Get-Content -Raw -Path $TestAuthEnvironmentPath | ConvertFrom-Json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase $testAuthEnvironment

@brandonpollett brandonpollett merged commit 1e6e1a0 into master Oct 18, 2018
@brandonpollett brandonpollett deleted the personal/brpoll/auth-aad-scripts branch October 23, 2018 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants