Skip to content

Commit 71e05a6

Browse files
authored
{IoT Hub} Fixed issue in SAS token generation (#13881)
* Fixed issue in SAS token generation * Added SAS token validation test and updated test recording * Fixed status code for device message result
1 parent 1d97a57 commit 71e05a6

File tree

4 files changed

+826
-819
lines changed

4 files changed

+826
-819
lines changed

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPDeviceTests.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Test all iothub device cmdlets
2424
function Test-AzureRmIotHubDeviceLifecycle
2525
{
2626
$Location = Get-Location "Microsoft.Devices" "IotHubs"
27+
$dataplaneApiVersion = '2020-03-13'
2728
$IotHubName = getAssetName
2829
$ResourceGroupName = getAssetName
2930
$Sku = "S1"
@@ -83,6 +84,12 @@ function Test-AzureRmIotHubDeviceLifecycle
8384
$deviceToken = New-AzIotHubSasToken -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device1
8485
Assert-StartsWith $SasTokenPrefix $deviceToken
8586

87+
# Test SAS token validity
88+
$hostname = $iothub.Properties.HostName
89+
$deviceMessageUri = "https://$hostname/devices/$device1/messages/events?api-version=$dataplaneApiVersion"
90+
$deviceMessageResult = Invoke-WebRequest -Uri $deviceMessageUri -Method Post -Body "test" -Headers @{Authorization = $deviceToken}
91+
Assert-True { $deviceMessageResult.StatusCode -eq 204 }
92+
8693
# Expected error while generating SAS token for device
8794
$errorMessage = "This device does not support SAS auth."
8895
Assert-ThrowsContains { New-AzIotHubSasToken -ResourceGroupName $ResourceGroupName -IotHubName $IotHubName -DeviceId $device3 } $errorMessage
@@ -122,7 +129,7 @@ function Test-AzureRmIotHubDeviceLifecycle
122129
Assert-True { $updateddevice1twin3.tags.Count -eq 1}
123130

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

128135
# Get all devices

0 commit comments

Comments
 (0)