Ejemplo n.º 1
0
        public void UpdateSharedAccessSignatureShouldUpdateTheSharedAccessSignature()
        {
            var resource       = "amqps://before/path";
            var beforeKeyName  = "beforeKeyName";
            var afterKeyName   = "afterKeyName";
            var beforeKeyValue = "beforeKeyValue";
            var afterKeyValue  = "afterKeyValue";
            var validSpan      = TimeSpan.FromHours(4);
            var signature      = new SharedAccessSignature(resource, beforeKeyName, beforeKeyValue, validSpan.Add(TimeSpan.FromHours(2)));
            var keyCredential  = new ServiceBusSharedAccessKeyCredential(signature.Value);
            var sasCredential  = keyCredential.AsSharedAccessSignatureCredential(resource, validSpan);

            // Updates
            var newSignature = new SharedAccessSignature(resource, afterKeyName, afterKeyValue, validSpan);

            keyCredential.UpdateSharedAccessSignature(newSignature.Value);

            Assert.That(sasCredential, Is.Not.Null, "A shared access signature credential should have been created.");

            var credentialSignature = GetSharedAccessSignature(sasCredential);

            Assert.That(credentialSignature, Is.Not.Null, "The SAS credential should contain a shared access signature.");
            Assert.That(credentialSignature.Resource, Is.EqualTo(signature.Resource), "The resource should match.");
            Assert.That(credentialSignature.SharedAccessKeyName, Is.EqualTo(afterKeyName), "The shared access key name should match.");
            Assert.That(credentialSignature.SharedAccessKey, Is.Null, "The shared access key should not have been set.");
            Assert.That(credentialSignature.SignatureExpiration, Is.EqualTo(newSignature.SignatureExpiration).Within(TimeSpan.FromSeconds(5)), "The expiration should match.");
        }
Ejemplo n.º 2
0
        public void AsSharedAccessSignatureCredentialShouldNotRefreshTokenValidityForSharedAccessSignatures()
        {
            var beforeResource    = "amqps://before/path";
            var afterResource     = "amqps://after/path";
            var beforeSpan        = TimeSpan.FromHours(4);
            var afterSpan         = TimeSpan.FromHours(8);
            var keyName           = "keyName";
            var keyValue          = "keyValue";
            var expectedSignature = new SharedAccessSignature(beforeResource, keyName, keyValue, beforeSpan);
            var keyCredential     = new ServiceBusSharedAccessKeyCredential(expectedSignature.Value);

            SharedAccessSignatureCredential sasCredential   = keyCredential.AsSharedAccessSignatureCredential(beforeResource, beforeSpan);
            SharedAccessSignature           beforeSignature = GetSharedAccessSignature(sasCredential);

            Assert.That(beforeSignature.SignatureExpiration, Is.EqualTo(expectedSignature.SignatureExpiration).Within(TimeSpan.FromSeconds(5)), "The expiration should match.");

            sasCredential = keyCredential.AsSharedAccessSignatureCredential(afterResource, afterSpan);
            SharedAccessSignature afterSignature = GetSharedAccessSignature(sasCredential);

            Assert.That(afterSignature.SignatureExpiration, Is.EqualTo(expectedSignature.SignatureExpiration).Within(TimeSpan.FromSeconds(5)), "The expiration should match.");
        }
Ejemplo n.º 3
0
        public void ServiceBusSharedAccessKeyCredentialShouldHoldAReferenceToASharedAccessKey()
        {
            var resource      = "amqps://some.hub.com/path";
            var span          = TimeSpan.FromHours(4);
            var keyName       = "keyName";
            var keyValue      = "keyValue";
            var keyCredential = new ServiceBusSharedAccessKeyCredential(keyName, keyValue);

            SharedAccessSignatureCredential sasCredential     = keyCredential.AsSharedAccessSignatureCredential(resource, span);
            SharedAccessSignatureCredential wrappedCredential = GetSharedAccessSignatureCredential(keyCredential);

            Assert.That(wrappedCredential, Is.EqualTo(sasCredential), "The credentials should be wrapped.");
        }
Ejemplo n.º 4
0
        public void AsSharedAccessSignatureCredentialProducesTheExpectedCredentialForSharedKeys()
        {
            var resource      = "amqps://some.hub.com/path";
            var keyName       = "sharedKey";
            var keyValue      = "keyValue";
            var validSpan     = TimeSpan.FromHours(4);
            var signature     = new SharedAccessSignature(resource, keyName, keyValue, validSpan);
            var keyCredential = new ServiceBusSharedAccessKeyCredential(keyName, keyValue);
            var sasCredential = keyCredential.AsSharedAccessSignatureCredential(resource, validSpan);

            Assert.That(sasCredential, Is.Not.Null, "A shared access signature credential should have been created.");

            var credentialSignature = GetSharedAccessSignature(sasCredential);

            Assert.That(credentialSignature, Is.Not.Null, "The SAS credential should contain a shared access signature.");
            Assert.That(credentialSignature.Resource, Is.EqualTo(signature.Resource), "The resource should match.");
            Assert.That(credentialSignature.SharedAccessKeyName, Is.EqualTo(signature.SharedAccessKeyName), "The shared access key name should match.");
            Assert.That(credentialSignature.SharedAccessKey, Is.EqualTo(signature.SharedAccessKey), "The shared access key should match.");
            Assert.That(credentialSignature.SignatureExpiration, Is.EqualTo(signature.SignatureExpiration).Within(TimeSpan.FromSeconds(5)), "The expiration should match.");
        }
Ejemplo n.º 5
0
        public void UpdateSharedAccessKeyShouldNotChangeOtherPropertiesForTheSharedAccessSignature()
        {
            var resource       = "amqps://before/path";
            var validSpan      = TimeSpan.FromHours(4);
            var beforeKeyName  = "beforeKeyName";
            var afterKeyName   = "afterKeyName";
            var beforeKeyValue = "beforeKeyValue";
            var afterKeyValue  = "afterKeyValue";
            var keyCredential  = new ServiceBusSharedAccessKeyCredential(beforeKeyName, beforeKeyValue);

            // Needed to instantiate a SharedAccessTokenCredential
            var sasCredential       = keyCredential.AsSharedAccessSignatureCredential(resource, validSpan);
            var credentialSignature = GetSharedAccessSignature(sasCredential);

            var signatureExpiration = credentialSignature.SignatureExpiration;

            keyCredential.UpdateSharedAccessKey(afterKeyName, afterKeyValue);

            Assert.That(credentialSignature.SignatureExpiration, Is.EqualTo(signatureExpiration), "The expiration of a signature should not change when the credentials are rolled.");
            Assert.That(credentialSignature.Resource, Is.EqualTo(resource), "The resource of a signature should not change when the credentials are rolled.");
        }
Ejemplo n.º 6
0
        public void UpdateSharedAccessKeyShoulRefreshServiceBusSharedAccessKeyCredentialNameAndKey()
        {
            var resource       = "amqps://before/path";
            var validSpan      = TimeSpan.FromHours(4);
            var beforeKeyName  = "beforeKeyName";
            var afterKeyName   = "afterKeyName";
            var beforeKeyValue = "beforeKeyValue";
            var afterKeyValue  = "afterKeyValue";
            var keyCredential  = new ServiceBusSharedAccessKeyCredential(beforeKeyName, beforeKeyValue);

            keyCredential.UpdateSharedAccessKey(afterKeyName, afterKeyValue);

            var keyName = keyCredential.SharedAccessKeyName;
            var key     = keyCredential.SharedAccessKey;

            var sasCredential       = keyCredential.AsSharedAccessSignatureCredential(resource, validSpan);
            var credentialSignature = GetSharedAccessSignature(sasCredential);

            Assert.That(credentialSignature.SharedAccessKeyName, Is.EqualTo(afterKeyName), "The shared access key name should change after being updated.");
            Assert.That(credentialSignature.SharedAccessKey, Is.EqualTo(afterKeyValue), "The shared access key value should change after being updated.");
            Assert.That(keyName, Is.EqualTo(afterKeyName), "The shared access key name should change after being updated.");
            Assert.That(key, Is.EqualTo(afterKeyValue), "The shared access key value should change after being updated.");
        }