Ejemplo n.º 1
0
    def discover(self, *args, **kwargs):
        """

        :param args: request object
        :param kwargs: dictionary with parameters
        """
        if len(args) > 0:
            request = args[0]
            assert(isinstance(request, Request))
            endpoint = request.destination
            ip, port = endpoint
        else:
            request = Request()
            path = kwargs['path']
            assert(isinstance(path, str))
            ip, port, path = self.parse_path(path)
            request.destination = (ip, port)
            if path == "":
                path = defines.DISCOVERY_URL
            request.uri_path = path
            endpoint = (ip, port)
        request.code = defines.inv_codes["GET"]
        self.send(request, endpoint)
        self.condition.acquire()
        self.condition.wait()
        message = self._response
        key = hash(str(ip) + str(port) + str(message.mid))
        if message.type == defines.inv_types["ACK"] and message.code == defines.inv_codes["EMPTY"] \
                and key in self.sent.keys():
            # Separate Response
            self.send(request, endpoint)
            self.condition.acquire()
            self.condition.wait()
            message = self._response
        return message
Ejemplo n.º 2
0
 def post(self, client_callback, *args, **kwargs):
     if isinstance(args, tuple):
         path, payload = args
         req = Request()
         req.uri_path = path
         req._payload = payload
         if "Token" in kwargs.keys():
             req.token = kwargs.get("Token")
             del kwargs["Token"]
         if "MID" in kwargs.keys():
             req.mid = kwargs.get("MID")
             del kwargs["MID"]
         if "Server" in kwargs.keys():
             req.destination = kwargs.get("Server")
             del kwargs["Server"]
     else:
         req = args[0]
     for key in kwargs:
         try:
             o = Option()
             o.number = defines.inv_options[key]
             o.value = kwargs[key]
             req.add_option(o)
         except KeyError:
             pass
     req.code = defines.inv_codes['POST']
     req.type = defines.inv_types["CON"]
     self.send_callback(req, self.post_results, client_callback)
Ejemplo n.º 3
0
 def discover(self, client_callback, *args, **kwargs):
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
     req.code = defines.inv_codes['GET']
     req.uri_path = ".well-known/core"
     req.type = defines.inv_types["CON"]
     self.send_callback(req, self.discover_results, client_callback)
Ejemplo n.º 4
0
    def test_delete(self):
        print("Delete")
        client = HelperClient(self.server_address)
        path = "rd?ep=endpoint1&lt=500&con=coap://local-proxy-old.example.com:5683&et=oic.d.sensor"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        response = client.post(path, payload, None, None, **ct)
        loc_path = response.location_path
        client.stop()

        path = loc_path
        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.DELETED.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 5
0
    def test_lookup_expired_ep(self):
        print("Expired endpoint lookup")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd-lookup/ep?ep=node1&rt=temperature-c"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types[
            "application/link-format"]
        expected.payload = None

        self.current_mid += 1
        # After 61 seconds the resource will be expired
        self._test_check([(req, expected)], 61)
Ejemplo n.º 6
0
    def test_wrong_ep(self):
        print("Endpoint name already exists")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.SERVICE_UNAVAILABLE.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 7
0
 def map(self, request):
     path = request.uri_path
     if request.uri_path == defines.DISCOVERY_URL:
         response = Response()
         response.destination = request.source
         response = self._resource_layer.discover(request, response)
         self.result_forward(response, request)
     server = self.root.find_complete(path)
     if server is not None:
         new_request = Request()
         segments = server.find_path().split("/")
         path = segments[2:]
         path = "/".join(path)
         segments = segments[1].split(":")
         host = segments[0]
         port = int(segments[1])
         # new_request.destination = (host, port)
         new_request.source = request.source
         new_request.type = request.type
         new_request._mid = (self._currentMID + 1) % (1 << 16)
         new_request.code = request.code
         new_request.proxy_uri = "coap://" + str(host) + ":" + str(port) + "/" + path
         new_request.payload = request.payload
         for option in request.options:
             if option.name == defines.inv_options["Uri-Path"]:
                 continue
             if option.name == defines.inv_options["Uri-Query"]:
                 continue
             if option.name == defines.inv_options["Uri-Host"]:
                 continue
             new_request.add_option(option)
         return new_request
     return None
Ejemplo n.º 8
0
    def test_td_coap_core_07(self):
        print "TD_COAP_CORE_07"
        path = "/test"
        req = Request()

        req.code = defines.inv_codes['PUT']
        req.uri_path = path
        req.type = defines.inv_types["NON"]
        o = Option()
        o.number = defines.inv_options["Content-Type"]
        o.value = defines.inv_content_types["application/xml"]
        req.add_option(o)
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.inv_types["NON"]
        expected._mid = None
        expected.code = defines.responses["CHANGED"]
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_plugtest(req, expected)
Ejemplo n.º 9
0
    def test_etag_deserialize(self):
        req = Request()
        req.type = defines.Types["CON"]
        req._mid = 1
        req.etag = bytearray([0xc5])

        serializer = Serializer()
        serialized = serializer.serialize(req)
        received_message = serializer.deserialize(serialized, ("127.0.0.1", 5683))

        self.assertEqual(req.etag, received_message.etag)
Ejemplo n.º 10
0
    def test_etag_deserialize(self):
        req = Request()
        req.type = defines.Types["CON"]
        req._mid = 1
        req.etag = bytearray([0xC5])

        serializer = Serializer()
        serialized = serializer.serialize(req)
        received_message = serializer.deserialize(serialized, ("127.0.0.1", 5683))

        self.assertEqual(req.etag, received_message.etag)
Ejemplo n.º 11
0
 def delete(self, path, callback=None, timeout=None):  # pragma: no cover
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.DELETE.number
     request.uri_path = path
     if callback is not None:
         thread = threading.Thread(target=self._thread_body, args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True, timeout=timeout)
         return response
Ejemplo n.º 12
0
 def delete(self, path, callback=None):  # pragma: no cover
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.DELETE.number
     request.uri_path = path
     if callback is not None:
         thread = threading.Thread(target=self._thread_body, args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True)
         return response
Ejemplo n.º 13
0
 def discover(self, callback=None):
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.GET.number
     request.uri_path = defines.DISCOVERY_URL
     if callback is not None:
         thread = threading.Thread(target=self._thread_body, args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True)
         return response
Ejemplo n.º 14
0
    def get(self, *args, **kwargs):
        """

        :param args: request object
        :param kwargs: dictionary with parameters
        """
        if len(args) > 0:
            request = args[0]
            assert isinstance(request, Request)
            endpoint = request.destination
            ip, port = endpoint
        else:
            request = Request()
            path = kwargs["path"]
            assert isinstance(path, str)
            ip, port, path = self.parse_path(path)
            request.destination = (ip, port)
            request.uri_path = path
            endpoint = (ip, port)
        request.code = defines.inv_codes["GET"]
        self.send(request, endpoint)
        future_time = random.uniform(defines.ACK_TIMEOUT, (defines.ACK_TIMEOUT * defines.ACK_RANDOM_FACTOR))
        retransmit_count = 0
        self.condition.acquire()
        while True:
            self.condition.wait(timeout=future_time)
            if self._response is not None:
                break
            if request.type == defines.inv_types["CON"]:
                if retransmit_count < defines.MAX_RETRANSMIT and (not request.acknowledged and not request.rejected):
                    print ("retransmit")
                    retransmit_count += 1
                    future_time *= 2
                    self.send(request, endpoint)
                else:
                    print ("Give up on message: " + str(request.mid))
                    self.stop = True
                    break
        message = self._response
        self._response = None
        key = hash(str(ip) + str(port) + str(message.mid))
        if (
            message.type == defines.inv_types["ACK"]
            and message.code == defines.inv_codes["EMPTY"]
            and key in self.sent.keys()
        ):
            # Separate Response
            self.condition.acquire()
            self.condition.wait()
            message = self._response
            self._response = None
        return message
Ejemplo n.º 15
0
 def put(self, path, payload, callback=None):
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.PUT.number
     request.uri_path = path
     request.payload = payload
     if callback is not None:
         thread = threading.Thread(target=self._thread_body, args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True)
         return response
Ejemplo n.º 16
0
    def mk_request(self, method, path):
        """
        Create a request.

        :param method: the CoAP method
        :param path: the path of the request
        :return:  the request
        """
        request = Request()
        request.destination = self.server
        request.code = method.number
        request.uri_path = path
        return request
    def mk_request(self, method, path):
        """
        Create a request.

        :param method: the CoAP method
        :param path: the path of the request
        :return:  the request
        """
        request = Request()
        request.destination = self.server
        request.code = method.number
        request.uri_path = path
        return request
 def discover(self, callback=None):  # pragma: no cover
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.GET.number
     request.uri_path = defines.DISCOVERY_URL
     if callback is not None:
         thread = threading.Thread(target=self._thread_body,
                                   args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True)
         return response
Ejemplo n.º 19
0
    def test_get_separate(self):
        print "\nGET /separate\n"
        args = ("/separate",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["CON"]
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Separate"

        self.current_mid += 1
        self._test_separate(req, expected)
Ejemplo n.º 20
0
    def test_get_not_found(self):
        print "\nGET /not_found\n"
        args = ("/not_found",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["NOT_FOUND"]
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test(req, expected)
Ejemplo n.º 21
0
    def test_wrong_ep(self):
        print("Endpoint name already exists")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.SERVICE_UNAVAILABLE.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 22
0
    def test_lookup_expired_ep(self):
        print("Expired endpoint lookup")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683&lt=60"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        client.post(path, payload, None, None, **ct)
        client.stop()

        path = "rd-lookup/ep?ep=node1&rt=temperature-c"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types["application/link-format"]
        expected.payload = None

        self.current_mid += 1
        # After 61 seconds the resource will be expired
        self._test_check([(req, expected)], 61)
Ejemplo n.º 23
0
    def test_delete(self):
        print("Delete")
        client = HelperClient(self.server_address)
        path = "rd?ep=endpoint1&lt=500&con=coap://local-proxy-old.example.com:5683&et=oic.d.sensor"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        response = client.post(path, payload, None, None, **ct)
        loc_path = response.location_path
        client.stop()

        path = loc_path
        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.DELETED.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 24
0
    def test_td_coap_obs_01(self):
        print("TD_COAP_OBS_01")
        path = "/obs"
        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.observe = 0

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = "Observable Resource"
        expected.observe = 1

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Observable Resource"
        expected2.observe = 1

        self.current_mid += 1
        self.server_mid += 1
        self._test_plugtest([(req, expected), (None, expected2)])
Ejemplo n.º 25
0
    def test_long(self):
        print "\nGET /long\n"
        args = ("/long",)
        kwargs = {}
        path = args[0]
        req = Request()
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Long Time"

        self.current_mid += 1
        self._test_modular([(req, expected), (None, expected2)])
    def get(self, path, callback=None):  # pragma: no cover
        request = Request()
        request.destination = self.server
        request.code = defines.Codes.GET.number
        request.uri_path = path
        #request.token = generate_random_token(5)

        if callback is not None:
            thread = threading.Thread(target=self._thread_body,
                                      args=(request, callback))
            thread.start()
        else:
            self.protocol.send_message(request)
            response = self.queue.get(block=True)
            return response
Ejemplo n.º 27
0
    def _send_hello_sequence(self, client):
        ownIp = self._get_ip()

        header = self._create_icmp_header()
        data = self._create_icmp_data(ownIp, self.port, self.server, self.port)
        packet = header + data
        packet = self._create_icmp_header(self._checksum_icmp(packet)) + data

        self._send_over_socket(self.server, packet)
        
        # that is needed to give device time to open coap port, otherwise it may not respond properly
        time.sleep(0.5)

        request = Request()
        request.destination = server=(self.server, self.port)
        request.code = defines.Codes.EMPTY.number
        client.send_empty(request)
Ejemplo n.º 28
0
    def test_duplicate_not_completed(self):
        print("TEST_DUPLICATE_NOT_COMPLETED")
        path = "/long"

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = None
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None

        self.current_mid += 1

        self._test_plugtest([(req, None), (req, expected), (None, expected2)])
Ejemplo n.º 29
0
    def test_no_response(self):
        print("TEST_NO_RESPONSE")
        path = "/long"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = None
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2),
                             (None, expected2), (None, expected2)])
Ejemplo n.º 30
0
    def test_td_coap_core_09(self):
        print("TD_COAP_CORE_09")
        path = "/separate"
        req = Request()

        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2)])
Ejemplo n.º 31
0
    def _forward_request(transaction, destination, path):
        """
        Forward requests.

        :type transaction: Transaction
        :param transaction: the transaction that owns the request
        :param destination: the destination of the request (IP, port)
        :param path: the path of the request.
        :rtype : Transaction
        :return: the edited transaction
        """
        client = HelperClient(destination)
        request = Request()
        request.options = copy.deepcopy(transaction.request.options)
        del request.block2
        del request.block1
        del request.uri_path
        del request.proxy_uri
        del request.proxy_schema
        # TODO handle observing
        del request.observe
        # request.observe = transaction.request.observe

        request.uri_path = path
        request.destination = destination
        request.payload = transaction.request.payload
        request.code = transaction.request.code
        response = client.send_request(request)
        client.stop()
        transaction.response.payload = response.payload
        transaction.response.code = response.code
        transaction.response.options = response.options
        return transaction
Ejemplo n.º 32
0
    def test_retrasnmissions(self):
        six.print_("Retransmissions")
        path = "/separate"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2), (None, expected2), (None, expected2)])
Ejemplo n.º 33
0
    def test_td_coap_obs_01(self):
        print "TD_COAP_OBS_01"
        path = "/obs"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.observe = 0

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.responses["CONTENT"]
        expected.token = None
        expected.payload = "Observable Resource"
        expected.observe = 1

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Observable Resource"
        expected2.observe = 2

        self.current_mid += 1
        self.server_mid += 1
        self._test_plugtest([(req, expected), (None, expected2)])
Ejemplo n.º 34
0
    def observe(self, *args, **kwargs):
        """

        :param args: request object
        :param kwargs: dictionary with parameters
        """
        if len(args) > 0:
            request = args[0]
            assert isinstance(request, Request)
            endpoint = request.destination
        else:
            request = Request()
            path = kwargs["path"]
            assert isinstance(path, str)
            ip, port, path = self.parse_path(path)
            request.destination = (ip, port)
            request.uri_path = path
            endpoint = (ip, port)
        request.code = defines.inv_codes["GET"]
        request.observe = 0
        self.send(request, endpoint)
Ejemplo n.º 35
0
    def _handle_request(self, transaction, new_resource):
        """
        Forward requests. Used by reverse proxies to also create new virtual resources on the proxy 
        in case of created resources
        
        :type new_resource: bool
        :type transaction: Transaction
        :param transaction: the transaction that owns the request
        :rtype : Transaction
        :param new_resource: if the request will generate a new resource 
        :return: the edited transaction
        """
        client = HelperClient(transaction.resource.remote_server)
        request = Request()
        request.options = copy.deepcopy(transaction.request.options)
        del request.block2
        del request.block1
        del request.uri_path
        del request.proxy_uri
        del request.proxy_schema
        # TODO handle observing
        del request.observe
        # request.observe = transaction.request.observe

        request.uri_path = "/".join(
            transaction.request.uri_path.split("/")[1:])
        request.destination = transaction.resource.remote_server
        request.payload = transaction.request.payload
        request.code = transaction.request.code
        logger.info("forward_request - " + str(request))
        response = client.send_request(request)
        client.stop()
        logger.info("forward_response - " + str(response))
        transaction.response.payload = response.payload
        transaction.response.code = response.code
        transaction.response.options = response.options
        if response.code == defines.Codes.CREATED.number:
            lp = transaction.response.location_path
            del transaction.response.location_path
            transaction.response.location_path = transaction.request.uri_path.split(
                "/")[0] + "/" + lp
            # TODO handle observing
            if new_resource:
                resource = RemoteResource('server',
                                          transaction.resource.remote_server,
                                          lp,
                                          coap_server=self,
                                          visible=True,
                                          observable=False,
                                          allow_children=True)
                self._server.add_resource(transaction.response.location_path,
                                          resource)
        if response.code == defines.Codes.DELETED.number:
            del self._server.root["/" + transaction.request.uri_path]
        return transaction
Ejemplo n.º 36
0
    def send(self, data, timestamp, iv):
        self.responses = {}
        self.received = 0

        client = HelperClient(server=("224.0.1.187", 5001))

        #Setup request and content
        dict = {
            "data": str(data)[2:-1],
            "timestamp": timestamp,
            "iv": str(iv)[2:-1]
        }
        jsonStr = json.dumps(dict)

        request = Request()
        request.destination = client.server
        request.code = defines.Codes.GET.number
        request.uri_path = 'info/'
        request.payload = jsonStr

        self.timeOutStamp = time.time()

        client.send_request(request)
        self.checkIfShouldSend()
        client.stop()

        return json.dumps(self.responses)
Ejemplo n.º 37
0
    def test_retrasnmissions(self):
        print "Retransmissions"
        path = "/separate"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.Types["CON"]
        expected2._mid = self.server_mid
        expected2.code = defines.Codes.CONTENT.number
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest([(req, expected), (None, expected2), (None, expected2), (None, expected2)])
Ejemplo n.º 38
0
 def discover_remote(self, destination):
     request = Request()
     assert (isinstance(destination, str))
     split = destination.split(":", 1)
     host = split[0]
     port = int(split[1])
     server = (host, port)
     request.destination = (host, port)
     request.type = defines.inv_types["CON"]
     request._mid = (self._currentMID + 1) % (1 << 16)
     request.code = defines.inv_codes["GET"]
     uri = "/" + defines.DISCOVERY_URL
     request.proxy_uri = uri
     client = HelperClient(server, True)
     token = self.generate_token()
     function = client.protocol.get
     args = (uri,)
     kwargs = {"Token": str(token)}
     callback = self.discover_remote_results
     err_callback = self.discover_remote_error
     operations = [(function, args, kwargs, (callback, err_callback))]
     key = hash(str(host) + str(port) + str(token))
     self._forward[key] = request
     key = hash(str(host) + str(port) + str((client.starting_mid + 1) % (1 << 16)))
     self._forward_mid[key] = request
     client.start(operations)
Ejemplo n.º 39
0
    def test_td_coap_core_09(self):
        print "TD_COAP_CORE_09"
        path = "/separate"
        req = Request()

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.type = defines.inv_types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.inv_types["ACK"]
        expected._mid = self.current_mid
        expected.code = None
        expected.token = None
        expected.payload = None

        expected2 = Response()
        expected2.type = defines.inv_types["CON"]
        expected2._mid = None
        expected2.code = defines.responses["CONTENT"]
        expected2.token = None
        expected2.payload = "Separate Resource"

        self.current_mid += 1
        self._test_plugtest_separate(req, expected, expected2)
Ejemplo n.º 40
0
    def put(self, *args, **kwargs):
        """

        :param args: request object
        :param kwargs: dictionary with parameters
        """
        if len(args) > 0:
            request = args[0]
            assert isinstance(request, Request)
            endpoint = request.destination
            ip, port = endpoint
            payload = request.payload
        else:
            request = Request()
            path = kwargs["path"]
            payload = kwargs["payload"]
            assert isinstance(path, str)
            ip, port, path = self.parse_path(path)
            request.destination = (ip, port)
            request.uri_path = path
            endpoint = (ip, port)
        request.code = defines.inv_codes["PUT"]
        request.payload = payload
        self.send(request, endpoint)
        self.condition.acquire()
        self.condition.wait()
        message = self._response
        key = hash(str(ip) + str(port) + str(message.mid))
        if (
            message.type == defines.inv_types["ACK"]
            and message.code == defines.inv_codes["EMPTY"]
            and key in self.sent.keys()
        ):
            # Separate Response
            self.send(request, endpoint)
            self.condition.acquire()
            self.condition.wait()
            message = self._response
        return message
Ejemplo n.º 41
0
    def multicast_discover(self):  # pragma: no cover
        request = Request()
        request.destination = self.server
        request.code = defines.Codes.GET.number
        request.uri_path = defines.DISCOVERY_URL

        self.protocol.send_message(request)
        first_response = self.queue.get(block=True)

        if first_response is None:
            # The message timed out
            return []

        responses = [first_response]
        try:
            # Keep trying to get more responses if they come in
            while self.running:
                responses.append(self.queue.get(block=True, timeout=10))
        except Empty:
            pass

        return responses
Ejemplo n.º 42
0
 def put(self, client_callback, *args, **kwargs):
     path, payload = args
     req = Request()
     if "Token" in kwargs.keys():
         req.token = kwargs.get("Token")
         del kwargs["Token"]
     for key in kwargs:
         o = Option()
         o.number = defines.inv_options[key]
         o.value = kwargs[key]
         req.add_option(o)
     req.code = defines.inv_codes['PUT']
     req.uri_path = path
     req.type = defines.inv_types["CON"]
     req.payload = payload
     self.send_callback(req, self.put_results, client_callback)
Ejemplo n.º 43
0
    def test_td_coap_block_01_client(self):
        print("TD_COAP_BLOCK_01")
        path = "/large"

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = None
        req.destination = self.server_address
        req.block2 = (0, 0, 1024)

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = None
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed.
"You gettee in," he added, motioning to me with his tomahawk, and throwing the clothes to one side. He really did this
in not only a civil but a really kind and charitable way. I stood looking at him a moment. For all his tattooings
he was on the whole a clean, comely looking cannibal. What's all this fuss I have been making about, thought I to
myself—the man's a human being just as I am: he has just as much reason to fear me, as I have to be afraid of him.
Better sleep with a sober cannibal than a drunken Christian.
"Landlord," said I, "tell him to stash his tomahawk there, or pipe, or whatever you call it; tell him to stop smoking,
in short, and I will turn in with him. But I don't fancy having a man smoking in bed with me. It's dangerous. Besides,
I ain't insured."
This being told to Queequeg, he at once complied, and again politely motioned me to get into bed—rolling over to one
side as much as to say—"I won't touch a leg of ye."
"Good night, landlord," said I, "you may go."
I turned in, and never slept better in my life.
Upon waking next morning about daylight, I found Queequeg's arm thrown over me in the most loving and affectionate
manner. You had almost thought I had been his wife. The counterpane was of patchwork, full of odd little
parti-coloured squares and triangles; and this arm of his tattooed all over with an interminable Cretan labyrinth
of a figure, no two parts of which were of one precise shade—owing I suppose to his keeping his arm at sea
unmethodically in sun and shade, his shirt sleeves irregularly rolled up at various times—this same arm of his,
I say, looked for all the world like a strip of that same patchwork quilt. Indeed, partly lying on it as the arm did
 when I first awoke, I could hardly tell it from the quilt, they so blended their hues together; and it was only by
 the sense of weight and pressure that I could tell that Queequeg was hugging"""
        expected.block2 = (1, 0, 1024)
        expected.size2 = 1990

        exchange1 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        self._test_with_client([exchange1])
Ejemplo n.º 44
0
def setup():
	
	db = open("db", "w+")

	serial = 'serial' + str(sys.argv[1])
	nonce = str(base64.b32encode(sys.argv[1].encode('utf-8')))[2:-1]

	db.write('serial:' + str(serial) + '\n')
	db.write('nonce:' + nonce + '\n')
	db.write('info2:' + 'a'*2 + '\n')
	db.write('info4:' + 'a'*4 + '\n')
	db.write('info8:' + 'a'*8 + '\n')
	db.write('info16:' + 'a'*16 + '\n')
	db.write('info32:' + 'a'*32 + '\n')
	db.write('info64:' + 'a'*64 + '\n')
	db.write('info128:' + 'a'*128 + '\n')

	gatewayAddress = '172.0.17.5'
	gatewayPort = 1337

	client = HelperClient(server=(gatewayAddress, int(gatewayPort)))
			
	request = Request()
	request.destination = client.server
	request.code = defines.Codes.GET.number
	request.uri_path = 'setup/'
	request.payload = serial

	response = client.send_request(request)
	client.stop()

	#Decrypt
	payload = response.payload
	dict = json.loads(payload)

	#Check for error
	if 'error' in dict.keys():
		print("Error: " + dict['error'])
	else:
		m = hashlib.md5()
		m.update(nonce.encode("UTF-8"))
		hashKey = m.hexdigest()[:16]
		
		IV = binascii.unhexlify(dict['iv'])
		data = binascii.unhexlify(dict['data'])

		decipher = AES.new(hashKey, AES.MODE_CBC, IV=IV)
		jsonStr = decipher.decrypt(data)
		jsonStr = jsonStr[:-jsonStr[-1]]

		dict = json.loads(jsonStr.decode('utf-8'))

		db.write("dtlsk:" + dict['dtlsk'] + '\n')
		db.write("gnonce:" + dict['gnonce'] + '\n')

		print("Setup complete")
Ejemplo n.º 45
0
    def observe(self, client_callback, *args, **kwargs):
        path = args[0]
        req = Request()
        if "Token" in kwargs.keys():
            req.token = kwargs.get("Token")
            del kwargs["Token"]
        for key in kwargs:
            o = Option()
            o.number = defines.inv_options[key]
            o.value = kwargs[key]
            req.add_option(o)

        req.code = defines.inv_codes['GET']
        req.uri_path = path
        req.observe = 0
        req.type = defines.inv_types["CON"]
        self.send_callback(req, self.observe_results, client_callback)
Ejemplo n.º 46
0
    def render_POST_advanced(self, request, response):
        logger.debug("entrou no post advanced login")
        self.payload = request.payload
        par = Request()
        device = request.payload
        adevice = device.split(",")

        for d in adevice:
            logger.debug("dados:", d)

        from coapthon.messages.response import Response
        assert (isinstance(response, Response))
        response.payload = "Response changed through POST :" + device
        response.code = defines.Codes.CREATED.number

        return self, response
 def introspect(self, path, bearer, callback=None, access_path=None):
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.GET.number
     request.uri_path = path
     request.bearer = bearer
     # request.token = generate_random_token(5)
     # request.observe = 0
     request.token_type_hint = "code"
     request.scope = access_path
     if callback is not None:
         thread = threading.Thread(target=self._thread_body,
                                   args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True)
         return response
Ejemplo n.º 48
0
    def test_td_coap_core_07(self):
        print("TD_COAP_CORE_07")
        path = "/test"
        req = Request()

        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["NON"]
        req.content_type = defines.Content_types["application/xml"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.Types["NON"]
        expected._mid = None
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 49
0
    def test_delete_res_not_found(self):
        print("Resource not found on delete")
        path = "rd/4521"
        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.NOT_FOUND.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 50
0
    def _send(self, source, path, code, payload, rtime):
        client = HelperClient(server=(source, 1337))
        #client = HelperClient(server=('172.0.17.5', 1337))

        request = Request()
        request.destination = client.server
        request.code = code
        request.uri_path = path
        request.payload = payload

        client.send_request(request)
        client.stop()
Ejemplo n.º 51
0
    def test_wildcard_ep(self):
        print("Use wildcard * to find endpoints")
        client = HelperClient(self.server_address)
        path = "rd?ep=node1&con=coap://local-proxy-old.example.com:5683"
        ct = {'content_type': defines.Content_types["application/link-format"]}
        payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";anchor="coap://spurious.example.com:5683",' \
                  '</sensors/light>;ct=41;rt="light-lux";if="sensor"'
        response = client.post(path, payload, None, None, **ct)
        loc_path1 = response.location_path
        path = "rd?ep=node2&con=coap://[2001:db8:3::123]:61616"
        payload = '</temp>;rt="temperature";anchor="coap://[2001:db8:3::123]:61616"'
        response = client.post(path, payload, None, None, **ct)
        loc_path2 = response.location_path
        client.stop()

        path = "rd-lookup/ep?rt=temp*"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types[
            "application/link-format"]
        expected.payload = '</' + loc_path1 + '>;con="coap://local-proxy-old.example.com:5683";ep="node1";lt=500,' \
                                              '</' + loc_path2 + '>;con="coap://[2001:db8:3::123]:61616";' \
                                                                 'ep="node2";lt=500'

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 52
0
    def test_no_ep(self):
        print("Registration without endpoint name")
        path = "rd?con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.BAD_REQUEST.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 53
0
    def test_uri_discovery(self):
        print("Uri discovery")
        path = ".well-known/core"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types["application/link-format"]
        expected.payload = '</rd-lookup/res>;rt="core.rd-lookup-res";ct=40,</rd>;rt="core.rd";ct=40,' \
                           '</rd-lookup/ep>;rt="core.rd-lookup-ep";ct=40'

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 54
0
    def test_td_coap_link_02(self):
        print("TD_COAP_LINK_02")
        path = "/.well-known/core"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.uri_query = "rt=Type1"

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.content_type = defines.Content_types[
            "application/link-format"]
        expected.payload = """</query>;rt="Type1";sz="13",</seg1>;rt="Type1";sz="13",</seg1/seg2>;rt="Type1";sz="13",</seg1/seg2/seg3>;rt="Type1";sz="13",</test>;rt="Type1";sz="13","""
        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 55
0
    def test_td_coap_block_01_client(self):
        print "TD_COAP_BLOCK_01"
        path = "/large"

        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = None
        req.destination = self.server_address
        req.block2 = (0, 0, 1024)

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = None
        expected.code = defines.Codes.CONTENT.number
        expected.token = None
        expected.payload = """"Me sabbee plenty"—grunted Queequeg, puffing away at his pipe and sitting up in bed.
"You gettee in," he added, motioning to me with his tomahawk, and throwing the clothes to one side. He really did this
in not only a civil but a really kind and charitable way. I stood looking at him a moment. For all his tattooings
he was on the whole a clean, comely looking cannibal. What's all this fuss I have been making about, thought I to
myself—the man's a human being just as I am: he has just as much reason to fear me, as I have to be afraid of him.
Better sleep with a sober cannibal than a drunken Christian.
"Landlord," said I, "tell him to stash his tomahawk there, or pipe, or whatever you call it; tell him to stop smoking,
in short, and I will turn in with him. But I don't fancy having a man smoking in bed with me. It's dangerous. Besides,
I ain't insured."
This being told to Queequeg, he at once complied, and again politely motioned me to get into bed—rolling over to one
side as much as to say—"I won't touch a leg of ye."
"Good night, landlord," said I, "you may go."
I turned in, and never slept better in my life.
Upon waking next morning about daylight, I found Queequeg's arm thrown over me in the most loving and affectionate
manner. You had almost thought I had been his wife. The counterpane was of patchwork, full of odd little
parti-coloured squares and triangles; and this arm of his tattooed all over with an interminable Cretan labyrinth
of a figure, no two parts of which were of one precise shade—owing I suppose to his keeping his arm at sea
unmethodically in sun and shade, his shirt sleeves irregularly rolled up at various times—this same arm of his,
I say, looked for all the world like a strip of that same patchwork quilt. Indeed, partly lying on it as the arm did
 when I first awoke, I could hardly tell it from the quilt, they so blended their hues together; and it was only by
 the sense of weight and pressure that I could tell that Queequeg was hugging"""
        expected.block2 = (1, 0, 1024)

        exchange1 = (req, expected)
        self.current_mid += 1
        self.server_mid += 1

        self._test_with_client([exchange1])
Ejemplo n.º 56
0
 def post(self, path, payload, callback=None, timeout=None):  # pragma: no cover
     request = Request()
     request.destination = self.server
     request.code = defines.Codes.POST.number
     request.token = generate_random_token(2)
     request.uri_path = path
     request.payload = payload
     if callback is not None:
         thread = threading.Thread(target=self._thread_body, args=(request, callback))
         thread.start()
     else:
         self.protocol.send_message(request)
         response = self.queue.get(block=True, timeout=timeout)
         return response
Ejemplo n.º 57
0
    def test_duplicate(self):
        print("TEST_DUPLICATE")
        path = "/test"
        req = Request()
        req.code = defines.Codes.GET.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.CONTENT.number
        expected.token = None

        self.current_mid += 1
        self._test_plugtest([(req, expected), (req, expected)])
Ejemplo n.º 58
0
    def test_delete_res_not_found(self):
        print("Resource not found on delete")
        path = "rd/4521"
        req = Request()
        req.code = defines.Codes.DELETE.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = 0
        req.payload = None

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.NOT_FOUND.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])
Ejemplo n.º 59
0
    def test_td_coap_core_07(self):
        print "TD_COAP_CORE_07"
        path = "/test"
        req = Request()

        req.code = defines.Codes.PUT.number
        req.uri_path = path
        req.type = defines.Types["NON"]
        req.content_type = defines.Content_types["application/xml"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.payload = "<value>test</value>"

        expected = Response()
        expected.type = defines.Types["NON"]
        expected._mid = None
        expected.code = defines.Codes.CHANGED.number
        expected.token = None
        expected.payload = None

        self.current_mid += 1
        self._test_with_client([(req, expected)])
Ejemplo n.º 60
0
    def test_no_ep(self):
        print("Registration without endpoint name")
        path = "rd?con=coap://local-proxy-old.example.com:5683"
        req = Request()
        req.code = defines.Codes.POST.number
        req.uri_path = path
        req.type = defines.Types["CON"]
        req._mid = self.current_mid
        req.destination = self.server_address
        req.content_type = defines.Content_types["application/link-format"]
        req.payload = '</sensors/temp>;ct=41;rt="temperature-c";if="sensor";' \
                      'anchor="coap://spurious.example.com:5683",</sensors/light>;ct=41;rt="light-lux";if="sensor"'

        expected = Response()
        expected.type = defines.Types["ACK"]
        expected._mid = self.current_mid
        expected.code = defines.Codes.BAD_REQUEST.number
        expected.token = None
        expected.content_type = 0
        expected.payload = None

        self.current_mid += 1
        self._test_check([(req, expected)])