Reputation: 21
I have written a PowerShell function that generates an auth token in azure using REST API call. I am using the tenant id, Service principal client id and client secret as input param to generate this token. The SP client id and client secret are being read from the azure keyvault.
I wish to write a unit test to:
I am planning to use PESTER for unit testing and need some assistance here.
Here is my function:
function string GetAuthToken() {
$AuthTokenUri = "https://login.microsoftonline.com/$TenantId/oauth2/token"
$Body = @{
'resource' = $resourcename
'client_id' = $ID
'grant_type' = 'client_credentials'
'client_secret' = $Secret
}
$Token = Invoke-RestMethod -Method Post -Uri $AuthTokenUri -Body $Body -ContentType application/x-www-form-urlencoded'
$AuthToken = ($Token.access_token).ToString()
return $AuthToken
}
Upvotes: 0
Views: 275