Esempio n. 1
0
        public void BuildAudienceDeviceTest()
        {
            // Arrange
            string iotHubHostName = "testIotHub.azure-devices.net";
            string deviceId       = "device1";

            // Act
            string audience = SasTokenHelper.BuildAudience(iotHubHostName, deviceId);

            // Assert
            Assert.Equal("testIotHub.azure-devices.net%2Fdevices%2Fdevice1", audience);
        }
Esempio n. 2
0
        public void BuildAudienceModule_WithSplChars_Test()
        {
            // Arrange
            string iotHubHostName = "testIotHub.azure-devices.net";
            string deviceId       = "[email protected]#st";
            string moduleId       = "$edgeAgent";

            // Act
            string audience = SasTokenHelper.BuildAudience(iotHubHostName, deviceId, moduleId);

            // Assert
            Assert.Equal("testIotHub.azure-devices.net%2Fdevices%2Fn%2540m.et%2523st%2Fmodules%2F%2524edgeAgent", audience);
        }
        public async Task SignTest()
        {
            // Arrange
            string audience  = SasTokenHelper.BuildAudience("foo.azure-devices.net", "ed1", "$edgeHub");
            string expiresOn = SasTokenHelper.BuildExpiresOn(new DateTime(2018, 01, 01), TimeSpan.FromHours(1));
            string data      = string.Join("\n", new List <string> {
                audience, expiresOn
            });
            string key               = Convert.ToBase64String(Encoding.UTF8.GetBytes("DummyKey123"));
            string expectedToken     = Convert.ToBase64String(new HMACSHA256(Convert.FromBase64String(key)).ComputeHash(Encoding.UTF8.GetBytes(data)));
            var    signatureProvider = new SharedAccessKeySignatureProvider(key);

            // Act
            string token = await signatureProvider.SignAsync(data);

            // Assert
            Assert.Equal(expectedToken, token);
        }