Beispiel #1
0
    def test_07(self):
        """
        Test creating 3 subscriptions then doing a status

        :return:
        """

        sr = tm11.ManageCollectionSubscriptionRequest(message_id=generate_message_id(),
                                                      collection_name='default',
                                                      action=ACT_SUBSCRIBE)

        msg1 = make_request('/collection-management/', sr.to_xml(), get_headers(VID_TAXII_SERVICES_11, False))

        sr.subscription_parameters.response_type = RT_COUNT_ONLY

        msg2 = make_request('/collection-management/', sr.to_xml(), get_headers(VID_TAXII_SERVICES_11, False))

        sr.subscription_parameters.content_bindings = [CB_STIX_XML_11,
                CB_STIX_XML_10]

        msg3 = make_request('/collection-management/', sr.to_xml(), get_headers(VID_TAXII_SERVICES_11, False))

        sr.action = ACT_STATUS

        msg = make_request('/collection-management/',
                           sr.to_xml(),
                           get_headers(VID_TAXII_SERVICES_11, False),
                           MSG_MANAGE_COLLECTION_SUBSCRIPTION_RESPONSE,
                           num_subscription_instances=3,
                           subscription_status=SS_ACTIVE)
        return msg
Beispiel #2
0
    def test_02(self):
        """
        Test creating a subscription
        :return:
        """
        sr = tm11.ManageCollectionSubscriptionRequest(message_id=generate_message_id(),
                                                      collection_name='default',
                                                      action=ACT_SUBSCRIBE)
        msg = make_request('/collection-management/',
                           sr.to_xml(),
                           get_headers(VID_TAXII_SERVICES_11, False),
                           MSG_MANAGE_COLLECTION_SUBSCRIPTION_RESPONSE,
                           num_subscription_instances=1,
                           subscription_status=SS_ACTIVE)

        return msg
Beispiel #3
0
    def test_01(self):
        """
        Do a basic status
        :return:
        """

        sr = tm11.ManageCollectionSubscriptionRequest(message_id=generate_message_id(),
                                                      collection_name='default',
                                                      action=ACT_STATUS)
        msg = make_request('/collection-management/',
                           sr.to_xml(),
                           get_headers(VID_TAXII_SERVICES_11, False),
                           MSG_MANAGE_COLLECTION_SUBSCRIPTION_RESPONSE)

        if len(msg.subscription_instances) != 0:
            raise ValueError("Expected zero subscription instances in response!")
Beispiel #4
0
    def __subscription_status_request(self,
                                      action,
                                      collection_name,
                                      subscription_id=None,
                                      uri=None):

        request_params = dict(message_id=self._generate_id(),
                              action=action,
                              collection_name=collection_name,
                              subscription_id=subscription_id)

        request = tm11.ManageCollectionSubscriptionRequest(**request_params)
        response = self._execute_request(
            request, uri=uri, service_type=const.SVC_COLLECTION_MANAGEMENT)

        return to_subscription_response_entity(response, version=11)
Beispiel #5
0
 def test_06(self):
     """
     Test creating a subscription, unsubscribing, then statusing
     :return:
     """
     msg = self.test_05()
     subs_id = msg.subscription_instances[0].subscription_id
     sr = tm11.ManageCollectionSubscriptionRequest(message_id=generate_message_id(),
                                                   collection_name='default',
                                                   action=ACT_STATUS,
                                                   subscription_id=subs_id)
     msg = make_request('/collection-management/',
                        sr.to_xml(),
                        get_headers(VID_TAXII_SERVICES_11, False),
                        MSG_MANAGE_COLLECTION_SUBSCRIPTION_RESPONSE,
                        num_subscription_instances=1,
                        subscription_status=SS_UNSUBSCRIBED,
                        subscription_id=subs_id)
     return msg
Beispiel #6
0
    def subscribe(s, path="/", collection="default", query=None,
                  inbox="http://localhost:8888"):

        if query != None:
            query = s.create_query(query)
        else:
            query = None

        params = tm11.SubscriptionParameters(query=query)

        deliv = tm11.PushParameters(
            inbox_protocol=t.VID_TAXII_HTTP_10,
            inbox_address=inbox,
            delivery_message_binding=t.VID_TAXII_XML_11)

        # Create request
        msg_id=tm11.generate_message_id()
        req = tm11.ManageCollectionSubscriptionRequest(
            message_id=msg_id,
            collection_name=collection,
            action=tm11.ACT_SUBSCRIBE,
            subscription_parameters=params,
            push_parameters=deliv
        )

        # Convert to XML for request body
        req_xml = req.to_xml()
        
        # Create HTTP client
        client = tc.HttpClient()
        client.setProxy('noproxy') 

        # Call TAXII service, using the body
        resp = client.callTaxiiService2(s.host, path, t.VID_TAXII_XML_11,
                                        req_xml, s.port)

        # Get response
        resp = t.get_message_from_http_response(resp, '0')

        print(resp.to_xml())
Beispiel #7
0
    def perform_manage_collection_subscription(path="/", act="status",
                                               collection="default"):
        
        if act == "subscribe":
            action = tm11.ACT_SUBSCRIBE
        elif act == "unsubscribe":
            action = tm11.ACT_UNSUBSCRIBE
        elif act == "pause":
            action = tm11.ACT_PAUSE
        elif act == "resume":
            action = tm11.ACT_RESUME
        elif act == "status":
            action = tm11.ACT_STATUS
        else:
            print("Need a subscription action I recognise")
            sys.exit(1)

        # Create request
        msg_id=tm11.generate_message_id()
        req = tm11.ManageCollectionSubscriptionRequest(message_id=msg_id,
                                                       collection_name=collection,
                                                       action=action)

        # Convert to XML for request body
        req_xml = req.to_xml()

        # Create HTTP client
        client = tc.HttpClient()
        client.setProxy('noproxy') 

        # Call TAXII service, using the body
        resp = client.callTaxiiService2(host, path, t.VID_TAXII_XML_11,
                                        req_xml, port)

        # Get response
        resp = t.get_message_from_http_response(resp, '0')

        print(resp.to_xml())
Beispiel #8
0
    def subscribe(
        self,
        collection_name,
        count_only=False,
        inbox_service=None,
        content_bindings=None,
        uri=None,
    ):
        """Create a subscription.

        Sends a subscription request with action `SUBSCRIBE`.

        if ``uri`` is not provided, client will try to discover services and
        find Collection Management Service among them.

        :param str collection_name: target collection name
        :param bool count_only: subscribe only to counts and not full content
        :param `cabby.entities.InboxService` inbox_service:
                Inbox Service that will accept content pushed by TAXII Server
                in the context of this subscription
        :param list content_bindings: a list of strings or
                :py:class:`cabby.entities.ContentBinding` entities
        :param str uri: URI path to a specific Collection Management service

        :return: subscription information response
        :rtype: :py:class:`cabby.entities.SubscriptionResponse`

        :raises ValueError:
                if URI provided is invalid or schema is not supported
        :raises `cabby.exceptions.HTTPError`:
                if HTTP error happened
        :raises `cabby.exceptions.UnsuccessfulStatusError`:
                if Status Message received and status_type is not `SUCCESS`
        :raises `cabby.exceptions.ServiceNotFoundError`:
                if no service found
        :raises `cabby.exceptions.AmbiguousServicesError`:
                more than one service with type specified
        :raises `cabby.exceptions.NoURIProvidedError`:
                no URI provided and client can't discover services
        """

        response_type = const.RT_COUNT_ONLY if count_only else const.RT_FULL

        sparams = tm11.SubscriptionParameters(
            response_type=response_type,
            content_bindings=pack_content_bindings(content_bindings,
                                                   version=11),
        )
        rparams = dict(
            message_id=self._generate_id(),
            action=const.ACT_SUBSCRIBE,
            collection_name=collection_name,
            subscription_parameters=sparams,
        )

        if inbox_service:
            binding = (inbox_service.message_bindings[0]
                       if inbox_service.message_bindings else "")

            rparams["push_parameters"] = tm11.PushParameters(
                inbox_protocol=inbox_service.protocol,
                inbox_address=inbox_service.address,
                delivery_message_binding=binding,
            )

        request = tm11.ManageCollectionSubscriptionRequest(**rparams)
        response = self._execute_request(
            request, uri=uri, service_type=const.SVC_COLLECTION_MANAGEMENT)

        return to_subscription_response_entity(response, version=11)