def test3_register_duplicate_token(self):
        req = POST(config.ui_host, config.ui_port, "/notifications/fcm")
        req.authorize(self.session)
        req.body(json.dumps({"id": "TESTING_FCM_TOKEN"}))
        response, _ = req()

        self.assertEqual(204, response.status)
예제 #2
0
    def setUp(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        req.body(config.PERMIT_LOGIN)
        response, content = req()

        self.assertEqual(200, response.status)

        result = json.loads(content)
        self.assertEqual("success", result["status"])
        self.session = result["data"]["id"]

        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "Testing Gateway",
                "timezone_id": "Europe/Prague"
            }))
        response, _ = req()

        self.assertEqual(201, response.status)

        self.ws = websocket.WebSocket()
        self.ws.connect(config.gws_ws_uri)
        registerGateway(self, self.ws, config.gateway_id)
    def test3_discover(self):
        req = POST(config.ui_host, config.ui_port,
                   "/gateways/" + config.gateway_id + "/discovery")
        req.authorize(self.session)
        req.body(json.dumps({"time_limit": 1}))
        response, content = req()

        self.assertEqual(202, response.status)

        data = json.loads(content)
        self.assertEqual("success", data["status"])

        scan_uri = response.getheader("Location")
        self.assertEqual("/gateways/" + config.gateway_id + "/discovery",
                         scan_uri)

        for i in range(10):
            req = GET(config.ui_host, config.ui_port, scan_uri)
            req.authorize(self.session)
            response, content = req()

            self.assertEqual(200, response.status)

            result = json.loads(content)
            self.assertTrue("success", result["status"])

            if result["data"]["state"]["name"] == "finished":
                break

            self.assertTrue("started" in result["data"])
            self.assertTrue("duration" in result["data"])
            self.assertEqual(1, result["data"]["duration"])

            time.sleep(1)
    def test1_too_big_content_length(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        req.body("x" * (1024 * 1024))
        response, content = req()

        self.assertEqual(400, response.status)
        self.assertEqual(0, len(content))
예제 #5
0
	def assignGateway(self, gwId, name):
		req = POST("localhost", globalConfig.uiPort, "/gateways")
		req.authorize(self.session)
		req.body(json.dumps({
			"id": gwId,
			"name": name,
			"timezone_id": "Europe/Prague"
		}))

		response, content = req()
		self.assertEqual(201, response.status)
		self.assertEqual("/gateways/" + gwId,
				response.getheader("Location"))

		# check the gateway's contents
		resultLink = response.getheader("Location")
		req = GET("localhost", globalConfig.uiPort, resultLink)
		req.authorize(self.session)

		response, content = req()
		self.assertEqual(200, response.status)

		result = json.loads(content)
		self.assertEqual("success", result["status"])
		self.assertEqual("My Home", result["data"]["name"])
		self.assertEqual(gwId, result["data"]["id"])
		self.assertEqual("Europe/Prague", result["data"]["timezone"]["id"])
		return resultLink
예제 #6
0
	def deviceDiscovery(self, gwId, timeLimit = "10"):
		req = POST("localhost", globalConfig.uiPort, "/gateways/" + str(gwId) + "/discovery")
		req.authorize(self.session)
		req.body(json.dumps({
			"time_limit": timeLimit,
		}))

		response, content = req()
		self.assertEqual(202, response.status)
    def setUp(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        req.body(config.PERMIT_LOGIN)
        response, content = req()

        self.assertEqual(200, response.status)
        result = json.loads(content)
        self.assertEqual("success", result["status"])

        self.session = result["data"]["id"]
예제 #8
0
	def requestChange(self, gwId, deviceId, moduleId, value):
		req = POST("localhost", globalConfig.uiPort, "/gateways/" + str(gwId) + "/devices/" + str(deviceId) + "/controls/"+str(moduleId)+"/current")
		req.authorize(self.session)
		req.body(json.dumps({
			"value": value,
		}))

		response, content = req()
		self.assertEqual(200, response.status)
		print("CONTENT: " + str(content))
예제 #9
0
def login(body):
	req = POST(config.ui_host, config.ui_port, "/auth")
	req.body(body)

	response, data = req()
	result = json.loads(data)

	if result["status"] == "success":
		return response, result["data"]["id"]
	else:
		return response, result["message"]
    def test2_fail_on_create_read_only_firmware(self):
        req = POST(
            config.ui_host, config.ui_port, "/gateways/" + config.gateway_id +
            "/devices/0xa335d00019f5234e/properties/firmware")
        req.authorize(self.session)
        req.body(json.dumps({"value": "super firmware"}))
        response, content = req()

        self.assertEqual(405, response.status)
        result = json.loads(content)
        self.assertEqual("Method Not Allowed", result["status"])
    def test2_too_long_input(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        login = json.loads(config.PERMIT_LOGIN)
        login["bloat"] = ("x" * (1024 * 1024))
        req.body(json.dumps(login))
        req["Content-Length"] = 1024
        response, content = req()

        self.assertEqual(401, response.status)

        result = json.loads(content)
        self.assertEqual("error", result["status"])
예제 #12
0
	def test3_simple_xss_attempt(self):
		req = POST(config.ui_host, config.ui_port, "/gateways")
		req.authorize(self.session)
		req.body(json.dumps(
			{"id": config.gateway_id, "name": "My <script>attack()</script>", "timezone_id": "Europe/Prage"}
		))
		response, content = req()

		self.assertEqual(400, response.status)
		result = json.loads(content)
		self.assertEqual("error", result["status"])
		self.assertEqual(400, result["code"])
		self.assertEqual("invalid input data", result["message"])
    def test2_register_unregister_token(self):
        req = POST(config.ui_host, config.ui_port, "/notifications/fcm")
        req.authorize(self.session)
        req.body(json.dumps({"id": config.fcm_token}))
        response, _ = req()

        self.assertEqual(204, response.status)

        req = DELETE(config.ui_host, config.ui_port,
                     "/notifications/fcm/" + config.fcm_token)
        req.authorize(self.session)
        response, _ = req()

        self.assertEqual(204, response.status)
    def test1_add_and_delete(self):
        req = POST(config.ui_host, config.ui_port,
                   "/gateways/" + config.gateway_id + "/locations")
        req.authorize(self.session)
        req.body(json.dumps({"name": "New location", "type": 0}))
        response, content = req()

        self.assertEqual(201, response.status)

        req = DELETE(config.ui_host, config.ui_port,
                     response.headers["Location"])

        req.authorize(self.session)
        response, content = req()
        self.assertEqual(204, response.status)
예제 #15
0
    def test1_assign_unassign(self):
        # assign a prepared gateway
        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "My Home",
                "timezone_id": "Europe/Prague"
            }))

        response, content = req()
        self.assertEqual(201, response.status)
        self.assertEqual("/gateways/" + config.gateway_id,
                         response.getheader("Location"))

        # check the gateway's contents
        resultLink = response.getheader("Location")
        req = GET(config.ui_host, config.ui_port, resultLink)
        req.authorize(self.session)

        response, content = req()
        self.assertEqual(200, response.status)

        result = json.loads(content)
        self.assertEqual("success", result["status"])
        self.assertEqual("My Home", result["data"]["name"])
        self.assertEqual(config.gateway_id, result["data"]["id"])
        self.assertEqual("Europe/Prague", result["data"]["timezone"]["id"])

        # unassign the gateway
        req = DELETE(config.ui_host, config.ui_port,
                     "/gateways/" + config.gateway_id)
        req.authorize(self.session)
        response, content = req()

        self.assertEqual(204, response.status)

        # test the gateway is inaccessible
        req = GET(config.ui_host, config.ui_port, resultLink)
        req.authorize(self.session)

        response, content = req()
        self.assertEqual(403, response.status)
        result = json.loads(content)
        self.assertEqual(403, result["code"])
        self.assertEqual("not enough permission to access the resource",
                         result["message"])
예제 #16
0
    def test2_assign_gateway_invalid_name(self):
        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "My New Line \n",
                "timezone_id": "Europe/Prague"
            }))

        response, content = req()
        self.assertEqual(400, response.status)

        result = json.loads(content)
        self.assertEqual(400, result["code"])
        self.assertEqual("error", result["status"])
예제 #17
0
	def setUp(self):
		super().setUp()
		try:
			req = POST("localhost", globalConfig.uiPort, "/auth")
			req.body(globalConfig.PERMIT_LOGIN)
			response, content = req()

			self.assertEqual(200, response.status)
			result = json.loads(content)

			self.assertEqual("success", result["status"])

			self.session = result["data"]["id"]
		except Exception as ex:
			self.tearDown()
			raise ex
예제 #18
0
    def setUp(self):
        req = POST(config.ui_host, config.ui_port, "/auth")
        req.body(config.PERMIT_LOGIN)
        response, content = req()

        self.assertEqual(200, response.status)

        result = json.loads(content)
        self.assertEqual("success", result["status"])
        self.session = result["data"]["id"]

        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": config.gateway_id,
                "name": "Testing Gateway",
                "timezone_id": "Europe/Prague"
            }))
        response, _ = req()

        self.assertEqual(201, response.status)

        req = POST(config.ui_host, config.ui_port, "/gateways")
        req.authorize(self.session)
        req.body(
            json.dumps({
                "id": "1334886476281298",
                "name": "Availability Gateway",
                "timezone_id": "Europe/Prague"
            }))
        response, _ = req()

        self.assertEqual(201, response.status)
    def test9_create_properties(self):
        properties = {"ip-address": "10.0.0.1", "password": "******"}

        for key, value in properties.items():
            req = POST(
                config.ui_host, config.ui_port,
                "/gateways/" + config.gateway_id +
                "/devices/0xa371959aad24618e/properties/" + key)
            req.authorize(self.session)
            req.body(json.dumps({"value": "10.0.0.1"}))
            response, content = req()

            self.assertEqual(200, response.status)

            req = DELETE(
                config.ui_host, config.ui_port,
                "/gateways/" + config.gateway_id +
                "/devices/0xa371959aad24618e/properties/" + key)
            req.authorize(self.session)
            response, content = req()

            self.assertEqual(204, response.status)
예제 #20
0
 def test3_http_auth_POST_401(self):
     req = POST(config.ui_host, config.ui_port, "/auth")
     req.body("")
     response, _ = req()
     self.assertEqual(401, response.status)