-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle clients with special characters in their names (#682)
- Loading branch information
1 parent
0dac12c
commit 82ce72e
Showing
7 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,14 @@ public void ParseIdsTest() | |
audience = "edgehubtest1.azure-devices.net/device/device1/module/mod1"; | ||
// Act/Assert | ||
Assert.Throws<InvalidOperationException>(() => CbsNode.ParseIds(audience)); | ||
|
||
// Arrange | ||
audience = "edgehubtest1.azure-devices.net/devices/d%40n.f/modules/m%40n.p"; | ||
// Act | ||
(deviceId, moduleId) = CbsNode.ParseIds(audience); | ||
// Assert | ||
Assert.Equal("[email protected]", deviceId); | ||
Assert.Equal("[email protected]", moduleId); | ||
} | ||
|
||
[Fact] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ namespace Microsoft.Azure.Devices.Edge.Hub.Amqp.Test | |
using Microsoft.Azure.Amqp; | ||
using Microsoft.Azure.Devices.Edge.Hub.Amqp.LinkHandlers; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Device; | ||
using Microsoft.Azure.Devices.Edge.Hub.Core.Identity; | ||
using Microsoft.Azure.Devices.Edge.Util.Test.Common; | ||
using Moq; | ||
|
@@ -174,5 +175,68 @@ public void GetLinkHandlerTest(string url, bool isReceiver, Type expectedLinkHan | |
Assert.NotNull(linkHandler); | ||
Assert.IsType(expectedLinkHandlerType, linkHandler); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetIdentityFromBoundVariablesTestData))] | ||
public void GetIdentityFromBoundVariablesTest(IDictionary<string, string> boundVariables, string expectedDeviceId, string expectedModuleId) | ||
{ | ||
// Arrange | ||
var messageConverter = Mock.Of<IMessageConverter<AmqpMessage>>(); | ||
var twinMessageConverter = Mock.Of<IMessageConverter<AmqpMessage>>(); | ||
var methodMessageConverter = Mock.Of<IMessageConverter<AmqpMessage>>(); | ||
var identityProvider = new IdentityProvider("foo.azure-device.net"); | ||
var linkHandlerProvider = new LinkHandlerProvider(messageConverter, twinMessageConverter, methodMessageConverter, identityProvider); | ||
|
||
// Act | ||
IIdentity identity = linkHandlerProvider.GetIdentity(boundVariables); | ||
|
||
// Assert | ||
if (string.IsNullOrEmpty(expectedModuleId)) | ||
{ | ||
Assert.IsType<DeviceIdentity>(identity); | ||
Assert.Equal(expectedDeviceId, identity.Id); | ||
} | ||
else | ||
{ | ||
Assert.IsType<ModuleIdentity>(identity); | ||
Assert.Equal(expectedDeviceId, ((ModuleIdentity)identity).DeviceId); | ||
Assert.Equal(expectedModuleId, ((ModuleIdentity)identity).ModuleId); | ||
} | ||
} | ||
|
||
static IEnumerable<object[]> GetIdentityFromBoundVariablesTestData() | ||
{ | ||
yield return new object[] | ||
{ | ||
new Dictionary<string, string> | ||
{ | ||
["deviceid"] = "d1" | ||
}, | ||
"d1", | ||
string.Empty | ||
}; | ||
|
||
yield return new object[] | ||
{ | ||
new Dictionary<string, string> | ||
{ | ||
["deviceid"] = "d1", | ||
["moduleid"] = "m1" | ||
}, | ||
"d1", | ||
"m1" | ||
}; | ||
|
||
yield return new object[] | ||
{ | ||
new Dictionary<string, string> | ||
{ | ||
["deviceid"] = "d%40n.f", | ||
["moduleid"] = "m%40n.p" | ||
}, | ||
"[email protected]", | ||
"[email protected]" | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters