Exemple #1
0
    def test_two_identities(self):
        # In order to run this test, 2 service bus service identities are created using
        # the sbaztool available at:
        # http://code.msdn.microsoft.com/windowsazure/Authorization-SBAzTool-6fd76d93
        #
        # Use the following commands to create 2 identities and grant access rights.
        # Replace <servicebusnamespace> with the namespace specified in the test .json file
        # Replace <servicebuskey> with the key specified in the test .json file
        # This only needs to be executed once, after the service bus namespace is created.
        #
        # sbaztool makeid user1 NoHEoD6snlvlhZm7yek9Etxca3l0CYjfc19ICIJZoUg= -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Send /path1 user1 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Listen /path1 user1 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Manage /path1 user1 -n <servicebusnamespace> -k <servicebuskey>

        # sbaztool makeid user2 Tb6K5qEgstyRBwp86JEjUezKj/a+fnkLFnibfgvxvdg= -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Send /path2 user2 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Listen /path2 user2 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Manage /path2 user2 -n <servicebusnamespace> -k <servicebuskey>

        sbs1 = ServiceBusService(
            credentials.getServiceBusNamespace(),
            'NoHEoD6snlvlhZm7yek9Etxca3l0CYjfc19ICIJZoUg=', 'user1')
        sbs2 = ServiceBusService(
            credentials.getServiceBusNamespace(),
            'Tb6K5qEgstyRBwp86JEjUezKj/a+fnkLFnibfgvxvdg=', 'user2')

        queue1_name = 'path1/queue' + str(random.randint(1, 10000000))
        queue2_name = 'path2/queue' + str(random.randint(1, 10000000))

        try:
            # Create queues, success
            sbs1.create_queue(queue1_name)
            sbs2.create_queue(queue2_name)

            # Receive messages, success
            msg = sbs1.receive_queue_message(queue1_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs1.receive_queue_message(queue1_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs2.receive_queue_message(queue2_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs2.receive_queue_message(queue2_name, True, 1)
            self.assertIsNone(msg.body)

            # Receive messages, failure
            with self.assertRaises(HTTPError):
                msg = sbs1.receive_queue_message(queue2_name, True, 1)
            with self.assertRaises(HTTPError):
                msg = sbs2.receive_queue_message(queue1_name, True, 1)
        finally:
            try:
                sbs1.delete_queue(queue1_name)
            except:
                pass
            try:
                sbs2.delete_queue(queue2_name)
            except:
                pass
    def test_two_identities(self):
        # In order to run this test, 2 service bus service identities are created using
        # the sbaztool available at:
        # http://code.msdn.microsoft.com/windowsazure/Authorization-SBAzTool-6fd76d93
        #
        # Use the following commands to create 2 identities and grant access rights.
        # Replace <servicebusnamespace> with the namespace specified in the test .json file
        # Replace <servicebuskey> with the key specified in the test .json file
        # This only needs to be executed once, after the service bus namespace is created.
        #
        # sbaztool makeid user1 NoHEoD6snlvlhZm7yek9Etxca3l0CYjfc19ICIJZoUg= -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Send /path1 user1 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Listen /path1 user1 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Manage /path1 user1 -n <servicebusnamespace> -k <servicebuskey>

        # sbaztool makeid user2 Tb6K5qEgstyRBwp86JEjUezKj/a+fnkLFnibfgvxvdg= -n <servicebusnamespace> -k <servicebuskey> 
        # sbaztool grant Send /path2 user2 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Listen /path2 user2 -n <servicebusnamespace> -k <servicebuskey>
        # sbaztool grant Manage /path2 user2 -n <servicebusnamespace> -k <servicebuskey>

        sbs1 = ServiceBusService(credentials.getServiceBusNamespace(), 
                                 'NoHEoD6snlvlhZm7yek9Etxca3l0CYjfc19ICIJZoUg=', 
                                 'user1')
        sbs2 = ServiceBusService(credentials.getServiceBusNamespace(), 
                                 'Tb6K5qEgstyRBwp86JEjUezKj/a+fnkLFnibfgvxvdg=', 
                                 'user2')

        queue1_name = 'path1/queue' + str(random.randint(1, 10000000))
        queue2_name = 'path2/queue' + str(random.randint(1, 10000000))

        try:
            # Create queues, success
            sbs1.create_queue(queue1_name)
            sbs2.create_queue(queue2_name)

            # Receive messages, success
            msg = sbs1.receive_queue_message(queue1_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs1.receive_queue_message(queue1_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs2.receive_queue_message(queue2_name, True, 1)
            self.assertIsNone(msg.body)
            msg = sbs2.receive_queue_message(queue2_name, True, 1)
            self.assertIsNone(msg.body)

            # Receive messages, failure
            with self.assertRaises(HTTPError):
                msg = sbs1.receive_queue_message(queue2_name, True, 1)
            with self.assertRaises(HTTPError):
                msg = sbs2.receive_queue_message(queue1_name, True, 1)
        finally:
            try:
                sbs1.delete_queue(queue1_name)
            except: pass
            try:
                sbs2.delete_queue(queue2_name)
            except: pass
    def test_check_namespace_availability_not_available(self):
        # arrange
        name = credentials.getServiceBusNamespace()

        # act
        availability = self.sms.check_namespace_availability(name)

        # assert
        self.assertFalse(availability.result)
    def test_check_namespace_availability_not_available(self):
        # arrange
        name = credentials.getServiceBusNamespace()

        # act
        availability = self.sms.check_namespace_availability(name)

        # assert
        self.assertFalse(availability.result)
    def test_create_service_bus_env_variables(self):
        # Arrange
        os.environ[AZURE_SERVICEBUS_NAMESPACE] = credentials.getServiceBusNamespace()
        os.environ[AZURE_SERVICEBUS_ACCESS_KEY] = credentials.getServiceBusKey()
        os.environ[AZURE_SERVICEBUS_ISSUER] = 'owner'

        # Act
        sbs = ServiceBusService()

        if os.environ.has_key(AZURE_SERVICEBUS_NAMESPACE):
            del os.environ[AZURE_SERVICEBUS_NAMESPACE]
        if os.environ.has_key(AZURE_SERVICEBUS_ACCESS_KEY):
            del os.environ[AZURE_SERVICEBUS_ACCESS_KEY]
        if os.environ.has_key(AZURE_SERVICEBUS_ISSUER):
            del os.environ[AZURE_SERVICEBUS_ISSUER]

        # Assert
        self.assertIsNotNone(sbs)
        self.assertEquals(sbs.service_namespace, credentials.getServiceBusNamespace())
        self.assertEquals(sbs.account_key, credentials.getServiceBusKey())
        self.assertEquals(sbs.issuer, 'owner')
Exemple #6
0
    def test_create_service_bus_env_variables(self):
        # Arrange
        os.environ[
            AZURE_SERVICEBUS_NAMESPACE] = credentials.getServiceBusNamespace()
        os.environ[AZURE_SERVICEBUS_ACCESS_KEY] = credentials.getServiceBusKey(
        )
        os.environ[AZURE_SERVICEBUS_ISSUER] = 'owner'

        # Act
        sbs = ServiceBusService()

        if os.environ.has_key(AZURE_SERVICEBUS_NAMESPACE):
            del os.environ[AZURE_SERVICEBUS_NAMESPACE]
        if os.environ.has_key(AZURE_SERVICEBUS_ACCESS_KEY):
            del os.environ[AZURE_SERVICEBUS_ACCESS_KEY]
        if os.environ.has_key(AZURE_SERVICEBUS_ISSUER):
            del os.environ[AZURE_SERVICEBUS_ISSUER]

        # Assert
        self.assertIsNotNone(sbs)
        self.assertEquals(sbs.service_namespace,
                          credentials.getServiceBusNamespace())
        self.assertEquals(sbs.account_key, credentials.getServiceBusKey())
        self.assertEquals(sbs.issuer, 'owner')
Exemple #7
0
    def setUp(self):
        self.sbs = ServiceBusService(credentials.getServiceBusNamespace(),
                                     credentials.getServiceBusKey(), 'owner')

        proxy_host = credentials.getProxyHost()
        proxy_port = credentials.getProxyPort()
        if proxy_host:
            self.sbs.set_proxy(proxy_host, proxy_port)

        __uid = getUniqueTestRunID()

        queue_base_name = u'mytestqueue%s' % (__uid)
        topic_base_name = u'mytesttopic%s' % (__uid)

        self.queue_name = getUniqueNameBasedOnCurrentTime(queue_base_name)
        self.topic_name = getUniqueNameBasedOnCurrentTime(topic_base_name)

        self.additional_queue_names = []
        self.additional_topic_names = []
    def test_get_namespace(self):
        # Arrange
        name = credentials.getServiceBusNamespace()
        
        # Act
        result = self.sms.get_namespace(name)

        # Assert
        self.assertIsNotNone(result)
        self.assertEqual(result.name, name)
        self.assertIsNotNone(result.region)
        self.assertIsNotNone(result.default_key)
        self.assertIsNotNone(result.status)
        self.assertIsNotNone(result.created_at)
        self.assertIsNotNone(result.acs_management_endpoint)
        self.assertIsNotNone(result.servicebus_endpoint)
        self.assertIsNotNone(result.connection_string)
        self.assertEqual(result.subscription_id, credentials.getSubscriptionId().replace('-', ''))
        self.assertTrue(result.enabled)
    def setUp(self):
        self.sbs = ServiceBusService(credentials.getServiceBusNamespace(), 
                                     credentials.getServiceBusKey(), 
                                     'owner')

        proxy_host = credentials.getProxyHost()
        proxy_port = credentials.getProxyPort()
        if proxy_host:
            self.sbs.set_proxy(proxy_host, proxy_port)

        __uid = getUniqueTestRunID()

        queue_base_name = u'mytestqueue%s' % (__uid)
        topic_base_name = u'mytesttopic%s' % (__uid)

        self.queue_name = getUniqueNameBasedOnCurrentTime(queue_base_name)
        self.topic_name = getUniqueNameBasedOnCurrentTime(topic_base_name)

        self.additional_queue_names = []
        self.additional_topic_names = []
    def test_get_namespace(self):
        # Arrange
        name = credentials.getServiceBusNamespace()

        # Act
        result = self.sms.get_namespace(name)

        # Assert
        self.assertIsNotNone(result)
        self.assertEqual(result.name, name)
        self.assertIsNotNone(result.region)
        self.assertIsNotNone(result.default_key)
        self.assertIsNotNone(result.status)
        self.assertIsNotNone(result.created_at)
        self.assertIsNotNone(result.acs_management_endpoint)
        self.assertIsNotNone(result.servicebus_endpoint)
        self.assertIsNotNone(result.connection_string)
        self.assertEqual(result.subscription_id,
                         credentials.getSubscriptionId().replace('-', ''))
        self.assertTrue(result.enabled)