Skip to content

{IoT Hub} Fixed issue in SAS token generation #13881

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 3 commits into from
Jan 7, 2021
Merged
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
9 changes: 8 additions & 1 deletion src/IotHub/IotHub.Test/ScenarioTests/IotHubDPDeviceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Test all iothub device cmdlets
function Test-AzureRmIotHubDeviceLifecycle
{
$Location = Get-Location "Microsoft.Devices" "IotHubs"
$dataplaneApiVersion = '2020-03-13'
$IotHubName = getAssetName
$ResourceGroupName = getAssetName
$Sku = "S1"
Expand Down Expand Up @@ -83,6 +84,12 @@ function Test-AzureRmIotHubDeviceLifecycle
$deviceToken = New-AzIotHubSasToken -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1
Assert-StartsWith $SasTokenPrefix $deviceToken

# Test SAS token validity
$hostname = $iothub.Properties.HostName
$deviceMessageUri = "https://$hostname/devices/$device1/messages/events?api-version=$dataplaneApiVersion"
$deviceMessageResult = Invoke-WebRequest -Uri $deviceMessageUri -Method Post -Body "test" -Headers @{Authorization = $deviceToken}
Assert-True { $deviceMessageResult.StatusCode -eq 204 }

# Expected error while generating SAS token for device
$errorMessage = "This device does not support SAS auth."
Assert-ThrowsContains { New-AzIotHubSasToken -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device3 } $errorMessage
Expand Down Expand Up @@ -122,7 +129,7 @@ function Test-AzureRmIotHubDeviceLifecycle
Assert-True { $updateddevice1twin3.tags.Count -eq 1}

# Invoke direct method on device
$errorMessage = 'Timed out waiting for device to connect.'
$errorMessage = "The operation failed because the requested device isn't online or hasn't registered the direct method callback."
Assert-ThrowsContains { Invoke-AzIotHubDeviceMethod -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1 -Name "SetTelemetryInterval" } $errorMessage

# Get all devices
Expand Down
Loading