Exemple #1
0
        public void GetTokenExpiryBufferSecondsTest()
        {
            string   token         = Util.Test.Common.TokenHelper.CreateSasToken("azure.devices.net");
            TimeSpan timeRemaining = TokenHelper.GetTokenExpiryTimeRemaining("foo.azuredevices.net", token);

            Assert.True(timeRemaining > TimeSpan.Zero);
        }
Exemple #2
0
        public void GetIsTokenExpiredTest()
        {
            // Arrange
            DateTime tokenExpiry = DateTime.UtcNow.AddYears(1);
            string   token       = Util.Test.Common.TokenHelper.CreateSasToken("azure.devices.net", tokenExpiry);

            // Act
            TimeSpan expiryTimeRemaining = TokenHelper.GetTokenExpiryTimeRemaining("azure.devices.net", token);

            // Assert
            Assert.True(expiryTimeRemaining - (tokenExpiry - DateTime.UtcNow) < TimeSpan.FromSeconds(1));
        }
Exemple #3
0
        public void CheckTokenExpiredTest()
        {
            // Arrange
            string   hostname   = "dummy.azure-devices.net";
            DateTime expiryTime = DateTime.UtcNow.AddHours(2);
            string   validToken = Util.Test.Common.TokenHelper.CreateSasToken(hostname, expiryTime);

            // Act
            DateTime actualExpiryTime = TokenHelper.GetTokenExpiry(hostname, validToken);

            // Assert
            Assert.True(actualExpiryTime - expiryTime < TimeSpan.FromSeconds(1));

            // Arrange
            expiryTime = DateTime.UtcNow.AddHours(-2);
            string expiredToken = Util.Test.Common.TokenHelper.CreateSasToken(hostname, expiryTime);

            // Act
            actualExpiryTime = TokenHelper.GetTokenExpiry(hostname, expiredToken);

            // Assert
            Assert.Equal(DateTime.MinValue, actualExpiryTime);
        }