我正在嘗試檢查 Azure 中應用注冊的權限并正在運行
(Get-AzRoleAssignment -ObjectId $objectId).RoleDefinitionName
它回傳多個值,例如“所有者、貢獻者、讀者、KeyVault 秘密用戶”等。
我正在嘗試撰寫 Pester 測驗以確保它具有兩個值或一個。
例如,$objectId 應該包含“Contributor”和KeyVault Secret User,或者,“Owner”。因此,只要有“所有者”或“貢獻者/KeyVault 秘密用戶”,測驗就會很愉快。需要注意的是,如果測驗全部 3,則測驗仍應通過。
到目前為止,我有以下內容,但似乎無法從我在網上找到的內容中得到這個作業。
BeforeALL {
$objectId = "<App-Reg-Object-Id>"
$RoleDefName = Get-AzRoleAssignment -ObjectId $objectId
}
Describe "Permissions Role Definition Checks" {
It "Checked the App Reg and it has the correct permissions" {
if ($RoleDefName.RoleDefinitionName | Should -Contain 'Owner')
{
Write-Host "Owner permission successfully found"
}
else {
$RoleDefName.RoleDefinitionName | Should -Contain 'Contributor'|'User Access Administrator'
}
}
}
}
任何幫助將不勝感激
編輯
現在在 Mark Wraggs 的評論的幫助下作業!我不得不將邏輯移到應該的左側,并為多個角色使用 ForEach。下面是我如何得到這個作業。
Describe "Permissions Role Definition Checks" {
It "Checked the App Reg and it has the correct permissions" -ForEach 'User Access Administrator','Contributor' {
$RoleDefName.RoleDefinitionName -Contains 'Owner' -Or $RoleDefName.RoleDefinitionName -Contains $_ | Should -Be $true
}
}
uj5u.com熱心網友回復:
對于此斷言,您需要執行以下操作:
$RoleDefName.RoleDefinitionName | Should -Contain 'Contributor','User Access Administrator'
但是因為你的場景有點復雜(你想檢查兩個不同的結果),最好將邏輯移到Should. 例如:
$RoleDefName.RoleDefinitionName -Contains 'Owner' -Or $RoleDefName.RoleDefinitionName -Contains 'Contributor','User Access Administrator' | Should -Be $true
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/530096.html
上一篇:如何跳過bs4標簽內的一些迭代?
