コード例 #1
0
        public void ParseExtractsValues()
        {
            var signature = "SharedAccessSignature sr=amqps%3A%2F%2Fmy.eh.com%2Fsomepath%2F&sig=%2BLsuqDlN8Us5lp%2FGdyEUMnU1XA4HdXx%2BJUdtkRNr7qI%3D&se=1562258488&skn=keykeykey";
            var parsed    = SharedAccessSignature.ParseSignature(signature);

            Assert.That(parsed, Is.Not.Null, "There should have been a result returned.");
            Assert.That(parsed.Resource, Is.Not.Null.Or.Empty, "The resource should have been parsed.");
            Assert.That(parsed.KeyName, Is.Not.Null.Or.Empty, "The key should have been parsed.");
            Assert.That(parsed.ExpirationUtc, Is.Not.EqualTo(default(DateTime)), "The expiration should be parsed.");
        }
コード例 #2
0
        public void ParseProducesCorrectValues()
        {
            var host       = "my.hubthing.com";
            var path       = "someHubInstance";
            var keyName    = "rootShared";
            var key        = "ABC123FFF333";
            var validFor   = TimeSpan.FromMinutes(30);
            var expiration = DateTime.UtcNow.Add(validFor);
            var signature  = new SharedAccessSignature(TransportType.AmqpTcp, host, path, keyName, key, validFor);
            var parsed     = SharedAccessSignature.ParseSignature(signature.ToString());

            Assert.That(parsed, Is.Not.Null, "There should have been a result returned.");
            Assert.That(parsed.Resource, Contains.Substring(host.ToLower()), "The resource should contain the host.");
            Assert.That(parsed.Resource, Contains.Substring(path.ToLower()), "The resource should contain the Event Hub path.");
            Assert.That(parsed.KeyName, Is.EqualTo(keyName), "The key name should have been parsed.");
            Assert.That(parsed.ExpirationUtc, Is.EqualTo(expiration).Within(TimeSpan.FromSeconds(5)), "The expiration should be parsed.");
        }
コード例 #3
0
 public void ParseToleratesExtraTokens(string signature)
 {
     Assert.That(() => SharedAccessSignature.ParseSignature(signature), Throws.Nothing);
 }
コード例 #4
0
 public void ParseToleratesTrailingDelimiters(string signature)
 {
     Assert.That(() => SharedAccessSignature.ParseSignature(signature), Throws.Nothing);
 }
コード例 #5
0
 public void ParseSignatureFailsWhenExpirationIsInvalid(string signature)
 {
     Assert.That(() => SharedAccessSignature.ParseSignature(signature), Throws.ArgumentException);
 }
コード例 #6
0
 public void ParseSignatureFailsWhenValuesAreMissing(string signature)
 {
     Assert.That(() => SharedAccessSignature.ParseSignature(signature), Throws.ArgumentException);
 }