コード例 #1
0
        [InlineData("http://localhost/RetrieveBlob?containerName=testcontainer&path=testpath&expirationTime=20300722173059&hashKeyName=key1", false)]                                       //no hashCode, should just return false, not throw
        public void ValidateUriTest(string uriString, bool isValid)
        {
            var fixture         = new HashCalculatorTestFixture();
            var currentDateTime = new DateTime(2020, 7, 22, 12, 30, 59, 5);

            fixture.TestDateTimeServiceProvider.SetCurrentDateTimeUTC(currentDateTime);
            var uriToValidate = new Uri(uriString);
            var valid         = fixture.HashCalculator.IsValidUri(uriToValidate);

            valid.Should().Be(isValid);
        }
コード例 #2
0
        public void CalculateUriToHashNoParametersTest()
        {
            var fixture         = new HashCalculatorTestFixture();
            var uri             = new Uri("http://localhost/RetrieveBlob");
            var currentDateTime = fixture.TestDateTimeServiceProvider.CurrentDateTimeUTC;

            var uriToHash   = fixture.HashCalculator.CalculateUriToHash(uri, TimeSpan.FromHours(5));
            var expectedUri = new Uri(uri.ToString() + $"?expirationTime={currentDateTime.AddHours(5):yyyyMMddHHmmss}&hashKeyName=key1");

            uriToHash.Uri.Should().Be(expectedUri);
        }
コード例 #3
0
        public void ExpiredUriTest()
        {
            var fixture         = new HashCalculatorTestFixture();
            var currentDateTime = new DateTime(2020, 7, 22, 17, 31, 1, 0);

            fixture.TestDateTimeServiceProvider.SetCurrentDateTimeUTC(currentDateTime);
            var uriToValidate = new Uri("http://localhost/RetrieveBlob?containerName=testcontainer&path=testpath&expirationTime=20200722173100&hashKeyName=key1&hashCode=Bdovm71WPeAcxwPhCQnbZCC/1K0=");
            var valid         = fixture.HashCalculator.IsValidUri(uriToValidate);

            valid.Should().Be(false);
        }
コード例 #4
0
        public void CalculateHashedUriTest()
        {
            var fixture         = new HashCalculatorTestFixture();
            var currentDateTime = new DateTime(2020, 7, 22, 12, 30, 59, 5);

            fixture.TestDateTimeServiceProvider.SetCurrentDateTimeUTC(currentDateTime);

            var uri         = new Uri("http://localhost/RetrieveBlob?containerName=testcontainer&path=testpath");
            var uriWithHash = fixture.HashCalculator.CalculateUriWithHash(uri, TimeSpan.FromHours(5));
            var expectedUri = new Uri(uri.ToString() + "&expirationTime=20200722173059&hashKeyName=key1&hashCode=PNd18qkQSAmWp5ZVpAnH3tUxSZY=");

            uriWithHash.Should().Be(expectedUri);
        }