public void Should_setup_permissions() { var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueNameForReceiving); // use the network service account since that one won't be in the local admin group creator.CreateQueueIfNecessary(bindings, NetworkServiceAccountName); var createdQueue = GetQueue(testQueueNameForReceiving); MessageQueueAccessRights?accountAccessRights; AccessControlEntryType? accessControlEntryType; Assert.True(createdQueue.TryGetPermissions(NetworkServiceAccountName, out accountAccessRights, out accessControlEntryType)); Assert.True(accountAccessRights.HasValue); Assert.True(accessControlEntryType == AccessControlEntryType.Allow, "User should have access"); Assert.True(accountAccessRights?.HasFlag(MessageQueueAccessRights.WriteMessage), $"{NetworkServiceAccountName} should have write access"); Assert.True(accountAccessRights?.HasFlag(MessageQueueAccessRights.ReceiveMessage), $"{NetworkServiceAccountName} should have receive messages access"); MessageQueueAccessRights?localAdminAccessRights; AccessControlEntryType? accessControlEntryTypeForLocalAdmin; Assert.True(createdQueue.TryGetPermissions(LocalAdministratorsGroupName, out localAdminAccessRights, out accessControlEntryTypeForLocalAdmin)); Assert.True(localAdminAccessRights.HasValue); Assert.True(localAdminAccessRights?.HasFlag(MessageQueueAccessRights.FullControl), $"{LocalAdministratorsGroupName} should have full control"); Assert.IsTrue(accessControlEntryTypeForLocalAdmin == AccessControlEntryType.Allow, $"{LocalAdministratorsGroupName} should have access"); }
public void Should_setup_permissions() { var testQueueName = "MsmqQueueCreatorTests.permissions"; var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); DeleteQueueIfPresent(testQueueName); bindings.BindReceiving(testQueueName); // use the network service account since that one won't be in the local admin group creator.CreateQueueIfNecessary(bindings, NetworkServiceAccountName); var createdQueue = GetQueue(testQueueName); MessageQueueAccessRights? accountAccessRights; Assert.True(createdQueue.TryGetPermissions(NetworkServiceAccountName, out accountAccessRights)); Assert.True(accountAccessRights.HasValue, "User should have access rights"); Assert.AreEqual(MessageQueueAccessRights.WriteMessage | MessageQueueAccessRights.ReceiveMessage, accountAccessRights, "User should have write/read access"); MessageQueueAccessRights? localAdminAccessRights; Assert.True(createdQueue.TryGetPermissions(LocalAdministratorsGroupName, out localAdminAccessRights)); Assert.True(localAdminAccessRights.HasValue, "User should have access rights"); Assert.AreEqual(MessageQueueAccessRights.FullControl, localAdminAccessRights, "LocalAdmins should have full control"); }
protected async Task StartPump(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, TransportTransactionMode transactionMode, Action <string, Exception> onCriticalError = null) { InputQueueName = GetTestName() + transactionMode; ErrorQueueName = $"{InputQueueName}.error"; transportSettings.Set("NServiceBus.Routing.EndpointName", InputQueueName); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(InputQueueName); queueBindings.BindSending(ErrorQueueName); transportSettings.Set(ErrorQueueSettings.SettingsKey, ErrorQueueName); transportSettings.Set <QueueBindings>(queueBindings); transportSettings.Set <EndpointInstances>(new EndpointInstances()); Configurer = CreateConfigurer(); var configuration = Configurer.Configure(transportSettings, transactionMode); TransportInfrastructure = configuration.TransportInfrastructure; IgnoreUnsupportedTransactionModes(transactionMode); IgnoreUnsupportedDeliveryConstraints(); ReceiveInfrastructure = TransportInfrastructure.ConfigureReceiveInfrastructure(); SendInfrastructure = TransportInfrastructure.ConfigureSendInfrastructure(); lazyDispatcher = new Lazy <IDispatchMessages>(() => SendInfrastructure.DispatcherFactory()); MessagePump = ReceiveInfrastructure.MessagePumpFactory(); var queueCreator = ReceiveInfrastructure.QueueCreatorFactory(); await queueCreator.CreateQueueIfNecessary(queueBindings, WindowsIdentity.GetCurrent().Name); var pushSettings = new PushSettings(InputQueueName, ErrorQueueName, configuration.PurgeInputQueueOnStartup, transactionMode); await MessagePump.Init( context => { if (context.Headers.ContainsKey(TestIdHeaderName) && context.Headers[TestIdHeaderName] == testId) { return(onMessage(context)); } return(Task.FromResult(0)); }, context => { if (context.Message.Headers.ContainsKey(TestIdHeaderName) && context.Message.Headers[TestIdHeaderName] == testId) { return(onError(context)); } return(Task.FromResult(ErrorHandleResult.Handled)); }, new FakeCriticalError(onCriticalError), pushSettings); MessagePump.Start(configuration.PushRuntimeSettings); }
public void Should_setup_permissions() { var testQueueName = "MsmqQueueCreatorTests.permissions"; var creator = new QueueCreator(true); var bindings = new QueueBindings(); DeleteQueueIfPresent(testQueueName); bindings.BindReceiving(testQueueName); // use the network service account since that one won't be in the local admin group creator.CreateQueueIfNecessary(bindings, NetworkServiceAccountName); var createdQueue = GetQueue(testQueueName); MessageQueueAccessRights?accountAccessRights; Assert.True(createdQueue.TryGetPermissions(NetworkServiceAccountName, out accountAccessRights)); Assert.True(accountAccessRights.HasValue, "User should have access rights"); Assert.AreEqual(MessageQueueAccessRights.WriteMessage | MessageQueueAccessRights.ReceiveMessage, accountAccessRights, "User should have write/read access"); MessageQueueAccessRights?localAdminAccessRights; Assert.True(createdQueue.TryGetPermissions(LocalAdministratorsGroupName, out localAdminAccessRights)); Assert.True(localAdminAccessRights.HasValue, "User should have access rights"); Assert.AreEqual(MessageQueueAccessRights.FullControl, localAdminAccessRights, "LocalAdmins should have full control"); }
public void Should_not_add_everyone_and_anonymous_to_already_existing_queues() { var path = MsmqAddress.Parse(testQueueNameForReceiving).PathWithoutPrefix; using (var queue = MessageQueue.Create(path)) { queue.SetPermissions(LocalEveryoneGroupName, MessageQueueAccessRights.GenericWrite, AccessControlEntryType.Revoke); queue.SetPermissions(LocalAnonymousLogonName, MessageQueueAccessRights.WriteMessage, AccessControlEntryType.Revoke); } var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueNameForReceiving); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); var existingQueue = GetQueue(testQueueNameForReceiving); MessageQueueAccessRights?nullBecauseRevoked; AccessControlEntryType? accessControlEntryType; Assert.False(existingQueue.TryGetPermissions(LocalEveryoneGroupName, out nullBecauseRevoked, out accessControlEntryType)); Assert.False(existingQueue.TryGetPermissions(LocalAnonymousLogonName, out nullBecauseRevoked, out accessControlEntryType)); Assert.IsNull(accessControlEntryType); }
static Task CreateOutputQueueIfNecessary(QueueAddressTranslator addressParser, SqlConnectionFactory sqlConnectionFactory) { var queueCreator = new QueueCreator(sqlConnectionFactory, addressParser, new CanonicalQueueAddress("Delayed", "dbo", "nservicebus")); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(validAddress); return(queueCreator.CreateQueueIfNecessary(queueBindings, "")); }
static Task CreateQueueIfNotExists(QueueAddressTranslator addressTranslator) { var queueCreator = new QueueCreator(sqlConnectionFactory, addressTranslator); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(QueueTableName); return(queueCreator.CreateQueueIfNecessary(queueBindings, "")); }
static Task CreateQueueIfNotExists(QueueAddressTranslator addressTranslator, SqlConnectionFactory sqlConnectionFactory) { var queueCreator = new QueueCreator(sqlConnectionFactory, addressTranslator, new CanonicalQueueAddress("Delayed", "dbo", "nservicebus")); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(QueueTableName); return(queueCreator.CreateQueueIfNecessary(queueBindings, "")); }
public void Should_blow_up_if_name_is_null() { var creator = new QueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(null); Assert.Throws <ArgumentNullException>(() => creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name)); }
static Task CreateOutputQueueIfNecessary(QueueAddressParser addressParser) { var queueCreator = new QueueCreator(sqlConnectionFactory, addressParser); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(validAddress); return(queueCreator.CreateQueueIfNecessary(queueBindings, "")); }
void BindQueues(QueueBindings queueBindings) { if (IsSendOnly) { return; } queueBindings.BindReceiving(configuration.LocalAddress); if (configuration.InstanceSpecificQueue != null) { queueBindings.BindReceiving(configuration.InstanceSpecificQueue); } foreach (var satellitePipeline in configuration.SatelliteDefinitions) { queueBindings.BindReceiving(satellitePipeline.ReceiveAddress); } }
public void Should_blow_up_for_invalid_accounts() { var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueNameForReceiving); var ex = Assert.Throws <InvalidOperationException>(() => creator.CreateQueueIfNecessary(bindings, "invalidaccount")); StringAssert.Contains("invalidaccount", ex.Message); }
public void Should_create_all_queues() { var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueNameForReceiving); bindings.BindSending(testQueueNameForSending); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); Assert.True(QueueExists(testQueueNameForSending)); Assert.True(QueueExists(testQueueNameForReceiving)); }
public void Should_make_queues_non_transactional_if_requested() { var creator = new MsmqQueueCreator(false); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueNameForReceiving); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); var queue = GetQueue(testQueueNameForReceiving); Assert.False(queue.Transactional); }
static async Task ResetQueue(QueueAddressTranslator addressTranslator) { var queueCreator = new QueueCreator(sqlConnectionFactory, addressTranslator); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(QueueTableName); using (var connection = await sqlConnectionFactory.OpenNewConnection().ConfigureAwait(false)) { using (var comm = connection.CreateCommand()) { comm.CommandText = $"IF OBJECT_ID('{QueueTableName}', 'U') IS NOT NULL DROP TABLE {QueueTableName}"; comm.ExecuteNonQuery(); } } await queueCreator.CreateQueueIfNecessary(queueBindings, "").ConfigureAwait(false); }
public void Should_make_queues_transactional_if_requested() { var testQueueName = "MsmqQueueCreatorTests.txreceiver"; DeleteQueueIfPresent(testQueueName); var creator = new QueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); var queue = GetQueue(testQueueName); Assert.True(queue.Transactional); }
public void Should_allow_queue_names_above_the_limit_for_set_permission() { var testQueueName = $"MsmqQueueCreatorTests.tolong.{Guid.NewGuid().ToString().Replace("-", "")}"; var maxQueueNameForSetPermissionToWork = 102 - Environment.MachineName.Length; testQueueName = $"{testQueueName}{new string('a', maxQueueNameForSetPermissionToWork - testQueueName.Length + 1)}"; DeleteQueueIfPresent(testQueueName); var creator = new QueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); Assert.DoesNotThrow(() => creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name)); }
public void Should_create_all_queues() { var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); DeleteQueueIfPresent("MsmqQueueCreatorTests.receiver"); DeleteQueueIfPresent("MsmqQueueCreatorTests.endpoint1"); DeleteQueueIfPresent("MsmqQueueCreatorTests.endpoint2"); bindings.BindReceiving("MsmqQueueCreatorTests.receiver"); bindings.BindSending("MsmqQueueCreatorTests.target1"); bindings.BindSending("MsmqQueueCreatorTests.target2"); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); Assert.True(QueueExists("MsmqQueueCreatorTests.receiver")); Assert.True(QueueExists("MsmqQueueCreatorTests.target1")); Assert.True(QueueExists("MsmqQueueCreatorTests.target2")); }
public void Should_create_all_queues() { var creator = new QueueCreator(true); var bindings = new QueueBindings(); DeleteQueueIfPresent("MsmqQueueCreatorTests.receiver"); DeleteQueueIfPresent("MsmqQueueCreatorTests.endpoint1"); DeleteQueueIfPresent("MsmqQueueCreatorTests.endpoint2"); bindings.BindReceiving("MsmqQueueCreatorTests.receiver"); bindings.BindSending("MsmqQueueCreatorTests.target1"); bindings.BindSending("MsmqQueueCreatorTests.target2"); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); Assert.True(QueueExists("MsmqQueueCreatorTests.receiver")); Assert.True(QueueExists("MsmqQueueCreatorTests.target1")); Assert.True(QueueExists("MsmqQueueCreatorTests.target2")); }
public void Should_blow_up_for_invalid_accounts() { var testQueueName = "MsmqQueueCreatorTests.badidentity"; DeleteQueueIfPresent(testQueueName); var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); var ex = Assert.Throws<InvalidOperationException>(() => creator.CreateQueueIfNecessary(bindings, "invalidaccount")); StringAssert.Contains("invalidaccount", ex.Message); }
public void Should_not_add_everyone_and_anonymous_to_already_existing_queues() { var testQueueName = "MsmqQueueCreatorTests.NoChangesToExisting"; DeleteQueueIfPresent(testQueueName); var path = MsmqAddress.Parse(testQueueName).PathWithoutPrefix; using (var existingQueue = MessageQueue.Create(path)) { existingQueue.SetPermissions(LocalEveryoneGroupName, MessageQueueAccessRights.GenericWrite, AccessControlEntryType.Revoke); existingQueue.SetPermissions(LocalAnonymousLogonName, MessageQueueAccessRights.WriteMessage, AccessControlEntryType.Revoke); } var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); var queue = GetQueue(testQueueName); MessageQueueAccessRights? nullBecauseRevoked; Assert.False(queue.TryGetPermissions(LocalEveryoneGroupName, out nullBecauseRevoked)); Assert.False(queue.TryGetPermissions(LocalAnonymousLogonName, out nullBecauseRevoked)); }
public void Should_blow_up_if_name_is_null() { var bindings = new QueueBindings(); Assert.Throws <ArgumentNullException>(() => bindings.BindReceiving(null)); }
public void Should_allow_queue_names_above_the_limit_for_set_permission() { var testQueueName = $"MsmqQueueCreatorTests.tolong.{Guid.NewGuid().ToString().Replace("-", "")}"; var maxQueueNameForSetPermissionToWork = 102 - Environment.MachineName.Length; testQueueName = $"{testQueueName}{new string('a', maxQueueNameForSetPermissionToWork - testQueueName.Length + 1)}"; DeleteQueueIfPresent(testQueueName); var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); Assert.DoesNotThrow(() => creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name)); }
public void Should_blow_up_if_name_is_null() { var creator = new MsmqQueueCreator(true); var bindings = new QueueBindings(); bindings.BindReceiving(null); Assert.Throws<ArgumentNullException>(() => creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name)); }
public void Should_make_queues_non_transactional_if_requested() { var testQueueName = "MsmqQueueCreatorTests.txreceiver"; DeleteQueueIfPresent(testQueueName); var creator = new MsmqQueueCreator(false); var bindings = new QueueBindings(); bindings.BindReceiving(testQueueName); creator.CreateQueueIfNecessary(bindings, WindowsIdentity.GetCurrent().Name); var queue = GetQueue(testQueueName); Assert.False(queue.Transactional); }