def test_http_redirection_login_uaa(self): """ <b>Description:</b> Checks if http get login uaa request is redirected to https <b>Input data:</b> Client: test user <b>Expected results:</b> Test passes when user is redirected to https page. <b>Steps:</b> 1. Get console client and configuration. 2. Log out from the console. 3. Get login uaa page using http. 4. Check https redirection. """ step("Get console client and configuration") client_configuration, client = self.get_client(HttpClientType.CONSOLE) step("Log out from the platform") client.request(method=HttpMethod.GET, url=config.uaa_url, path="logout.do") HttpClientFactory.remove(client_configuration) step("Get login page using http") uaa_login_url = self.UAA_LOGIN_URL_FORMAT.format( self.HTTP_EXTERNAL_PROTOCOL, config.tap_domain) response = client.request(method=HttpMethod.GET, url=uaa_login_url, path="", raw_response=True) step("Check https redirection") assert response.url == self.UAA_LOGIN_URL_FORMAT.format( config.external_protocol, config.tap_domain)
def get_logged_client(username=None, password=None): console_client = HttpClientFactory.get( ConsoleConfigurationProvider.get(username, password)) client = HttpClientFactory.get( ServiceToolConfigurationProvider.get(url=config.hue_url)) client.session = console_client.session client.request(method=HttpMethod.GET, path="", msg="login") return client
def test_get_should_create_only_one_instance(self): # given configuration = self._get_configuration(HttpClientType.APPLICATION) self.assertNotIn(configuration, HttpClientFactory._INSTANCES, "Invalid instance reference.") # when HttpClientFactory.get(configuration) HttpClientFactory.get(configuration) # then self.assertIn(configuration, HttpClientFactory._INSTANCES, "Missing instance reference.") self.assertEqual(1, len(HttpClientFactory._INSTANCES), "Invalid number of instances.")
def test_app_endpoints(self): step("Retrieve apps, and services on the Platform") tested_apps = { a for a in self.platform_apps if a.name in self.TESTED_APP_NAMES } step("Send GET /health request to apps: {}".format( self.TESTED_APP_NAMES)) for app in tested_apps: step("Testing app with name: {}".format(app.name)) HttpClientFactory.get( ApplicationConfigurationProvider.get(app.urls[0])).request( method=HttpMethod.GET, path="health")
def change_password(self, old_password, new_password): data = { "oldPassword": old_password, "password": new_password, } HttpClientFactory.get(ConsoleConfigurationProvider.get( self._username, old_password )).request( method=HttpMethod.PUT, path="rest/users/current/password", data=json.dumps(data), headers={"Accept": "application/json", "Content-Type": "application/json;charset=UTF-8"}, msg="Change password" )
def k8s_broker_update_secret(org_guid, key_id, username_b64=None, password_b64=None): """PUT /rest/kubernetes/{org_id}/secret/{key}""" body = { "data": {}, "metadata": { "name": key_id, "labels": { "managed_by": "TAP" } } } if username_b64 is not None: body["data"]["username"] = username_b64 if password_b64 is not None: body["data"]["password"] = password_b64 return HttpClientFactory.get( CloudFoundryConfigurationProvider.get( url=config.kubernetes_broker_url)).request( method=HttpMethod.PUT, body=body, path="rest/kubernetes/{org_guid}/secret/{key_id}", path_params={ 'org_guid': org_guid, 'key_id': key_id }, msg="K8S BROKER: update secret")
def k8s_broker_create_secret(org_guid, key_id, username_b64, password_b64): """POST /rest/kubernetes/{org_id}/secret/{key}""" body = { "apiVersion": "v1", "data": { "username": username_b64, "password": password_b64 }, "kind": "Secret", "metadata": { "name": key_id, "labels": { "managed_by": "TAP" } } } return HttpClientFactory.get( CloudFoundryConfigurationProvider.get( url=config.kubernetes_broker_url)).request( method=HttpMethod.POST, body=body, path="rest/kubernetes/{org_guid}/secret/{key_id}", path_params={ 'org_guid': org_guid, 'key_id': key_id }, msg="K8S BROKER: create secret")
def app_broker_bind_service_instance(instance_guid, application_guid): """PUT /v$/service_instances/:instanceId/service_bindings/:app_guid""" return HttpClientFactory.get(BrokerConfigurationProvider.get(TapComponent.application_broker)).request( method=HttpMethod.PUT, path="service_instances/{}/service_bindings/{}".format(instance_guid, application_guid), msg="APP BROKER: bind service instance to app", )
def test_6_add_collection(self): """ <b>Description:</b> Check that new collections and documents can be added. <b>Input data:</b> No input data. <b>Expected results:</b> Test passes if new collection can be created and populated with new documents. <b>Steps:</b> 1. Create new collection. 2. Add new documents to the created collection. 3. Check that collection was created and contains added documents. """ client = HttpClientFactory.get(ServiceToolConfigurationProvider.get(url=self.mongodb_app.urls[0])) step("Create test collection") client.request(HttpMethod.POST, path="collections", headers=self.JSON_HEADERS, body={"new_collection": self.TEST_COLLECTION_NAME}) step("Add documents to test collection") client.request(HttpMethod.POST, path="collections/{}/documents".format(self.TEST_COLLECTION_NAME), headers=self.JSON_HEADERS, body={"data": self.TEST_DATA}) step("Check collection was created properly") document = client.request(HttpMethod.GET, path="collections/{}/documents".format(self.TEST_COLLECTION_NAME), headers=self.JSON_HEADERS)["rows"][0] assert all([x in document.items() for x in self.TEST_DATA.items()]),\ "Document: {}, expected: {}".format(document, self.TEST_DATA)
def demiurge_get_clusters(): """GET /clusters""" return HttpClientFactory.get( BrokerConfigurationProvider.get(TapComponent.demiurge)).request( method=HttpMethod.GET, path="clusters", msg="DEMIURGE: get list of clusters")
def demiurge_create_cluster(cluster_name): """PUT /clusters/{cluster_name}""" return HttpClientFactory.get( BrokerConfigurationProvider.get(TapComponent.demiurge)).request( method=HttpMethod.PUT, path="clusters/{}".format(cluster_name), msg="DEMIURGE: create cluster")
def k8s_broker_delete_secret(org_guid, key_id): """DELETE /rest/kubernetes/{org_id}/secret/{key}""" return HttpClientFactory.get( KubernetesBrokerTokenConfigurationProvider.get()).request( method=HttpMethod.DELETE, path="rest/kubernetes/{}/secret/{}".format(org_guid, key_id), msg="K8S BROKER: delete secret")
def test_8_space_shuttle_anomaly_detection(self, space_shuttle_application): """ <b>Description:</b> Checks if space-shuttle-demo application anomalies are detected correctly. <b>Input data:</b> 1. space-shuttle-demo application 2. space-shuttle client <b>Expected results:</b> Anomalies are detected correctly. <b>Steps:</b> 1. Post samples. 2. Verify the anomalies. """ step('Check if anomalies are detected') client = HttpClientFactory.get( ApplicationConfigurationProvider.get( url=space_shuttle_application.urls[0])) sample_data = client.request(method=HttpMethod.GET, path="rest/space-shuttle/chart", params={ "groupBy": "1m", "since": "1h" }) assert len(sample_data) > 0
def app_broker_delete_service_instance(instance_guid): """DELETE /v$/service_instances/:instanceId""" return HttpClientFactory.get(BrokerConfigurationProvider.get(TapComponent.application_broker)).request( method=HttpMethod.DELETE, path="service_instances/{}".format(instance_guid), msg="APP BROKER: delete service instance", )
def test_1_create_and_get_table_content(self, dataset_target_uri, expected_transfer_content): """ <b>Description:</b> Check that table can be created in hive and content can be retrieved from it. <b>Input data:</b> 1. hdfs hive demo application <b>Expected results:</b> Test passes when table is created using hive and data can be retrieved from it. <b>Steps:</b> 1. Create hdfs hive client. 2. Create table. 3. Retrieve content from table. 4. Check that retrieved content is as expected. """ self.__class__.hive_client = HttpClientFactory.get( CloudFoundryConfigurationProvider.get(url="http://{}/rest/hive".format(self.hdfs_reader_app.urls[0]))) dir_path = dataset_target_uri[:dataset_target_uri.rfind("/")] step("Create hive table with csv data") self.hive_client.request(method=HttpMethod.POST, path=self.TABLE_NAME, params={"fullHdfsDirPath": dir_path, "headerFilePath": dataset_target_uri}) step("Get hive table content") hive_table_content = self.hive_client.request(method=HttpMethod.GET, path=self.TABLE_NAME) hive_table_content = [i.strip().split(" ") for i in hive_table_content.split("\n") if i] step("Check both are the same") assert hive_table_content == expected_transfer_content
def _assertHttpClientInstance(self, client_type, auth: ClientAuthBase): configuration = self._get_configuration(client_type) client = HttpClientFactory.get(configuration) self.assertIsInstance(client, HttpClient, "Invalid client class.") self.assertIsInstance(client._auth, auth, "Invalid auth class.") self.assertIn(configuration, HttpClientFactory._INSTANCES, "Missing instance reference.")
def test_1_send_message_to_gateway_instance(self, test_org_user_client): """ <b>Description:</b> Check that it's possible to send messages to gateway instance. <b>Input data:</b> 1. gateway app <b>Expected results:</b> Test passes when message is sent to gateway instance without errors. <b>Steps:</b> 1. Expose service instance url. 2. Send message to gateway instance. 3. Check that no error is raised. """ step("Expose service instance url") urls = ServiceInstance.expose_urls(service_id=self.gateway_instance.id, client=test_org_user_client) ServiceInstance.ensure_responding(url=urls[0]) step("Retrieve oauth token") http_client = HttpClientFactory.get(ServiceConfigurationProvider.get()) token = http_client._auth._token_header step("Check communication with gateway instance") header = {"Authorization": "{}".format(token)} ws_url = "{}/ws".format(urls[0].replace("http", WebsocketClient.WS)) try: ws = WebsocketClient(ws_url, headers=header) ws.send("test") ws.close() except Exception as e: raise AssertionError(str(e))
def app_broker_get_catalog(): """GET /v$/catalog""" return HttpClientFactory.get(BrokerConfigurationProvider.get(TapComponent.application_broker)).request( method=HttpMethod.GET, path="catalog", msg="APP BROKER: get catalog" )
def test_push_db_app_and_check_response(sample_db_app): """ <b>Description:</b> Checks if application pushed to the platform with postgres or mysql database service bound work. <b>Input data:</b> 1. Application names. 2. Application gzip paths. 3. Application manifest paths. <b>Expected results:</b> Test passes when application with postgres or mysql database service bound are in RUNNING state and returns OK status to HTTP GET request. <b>Steps:</b> 1. Create HTTP client. 2. Send GET request with the client. 3. Verify response is not None and response status code equals 200. """ client = HttpClientFactory.get( ApplicationConfigurationProvider.get(sample_db_app.urls[0])) response = client.request(method=HttpMethod.GET, path="", timeout=10, raw_response=True) assert response is not None assert response.status_code == 200
def test_push_sample_app_and_check_response(sample_app): """ <b>Description:</b> Checks if sample python and java applications pushed to the platform work. <b>Input data:</b> 1. Application names. 2. Application gzip paths. 3. Application manifest paths. <b>Expected results:</b> Test passes when python and java applications are in RUNNING state and return OK status to HTTP GET request. <b>Steps:</b> 1. Create HTTP client. 2. Send GET request with the client. 3. Verify response is not None and response status code equals 200. """ client = HttpClientFactory.get( ApplicationConfigurationProvider.get(sample_app.urls[0])) step("Check response for HTTP GET to the endpoint") response = client.request(method=HttpMethod.GET, path="", timeout=10, raw_response=True) assert response is not None assert response.status_code == 200
def __init__(self, context, org_uuid, space_uuid, tap_http_client): self.service_instance = ServiceInstance.api_create_with_plan_name( context, org_uuid, space_uuid, ServiceLabels.SEAHORSE, name=generate_test_object_name(short=True, prefix=ServiceLabels.SEAHORSE), service_plan_name=ServicePlan.FREE) self.service_instance.ensure_running() self.seahorse_url = "{}-{}.{}".format( self.service_instance.name.replace("_", "-"), self.service_instance.guid, self.tap_domain) self.seahorse_http_url = "https://{}".format(self.seahorse_url) http_client_configuration = HttpClientConfiguration( client_type=HttpClientType.NO_AUTH, url="https://{}".format(self.seahorse_url), username=self.username, password=self.password) self.http_client = HttpClientFactory.get(http_client_configuration) self.http_client.session = tap_http_client.session self._ensure_seahorse_accessible() self._ensure_authorized() self._ensure_wm_accessible() self._ensure_sm_accessible() self._ws = None
def k8s_broker_update_secret(org_guid, key_id, username_b64=None, password_b64=None): """PUT /rest/kubernetes/{org_id}/secret/{key}""" body = { "data": {}, "metadata": { "name": key_id, "labels": { "managed_by": "TAP" } } } if username_b64 is not None: body["data"]["username"] = username_b64 if password_b64 is not None: body["data"]["password"] = password_b64 return HttpClientFactory.get( KubernetesBrokerTokenConfigurationProvider.get()).request( method=HttpMethod.PUT, body=body, path="rest/kubernetes/{}/secret/{}".format(org_guid, key_id), msg="K8S BROKER: update secret")
def test_get_should_create_two_different_instances(self): # given url_first = "first.sample.url" url_second = "second.sample.url" configuration_first = self._get_configuration(HttpClientType.BROKER, url_first) configuration_second = self._get_configuration(HttpClientType.BROKER, url_second) # when client_first = HttpClientFactory.get(configuration_first) client_second = HttpClientFactory.get(configuration_second) # then self.assertEqual(client_first.url, url_first) self.assertEqual(client_second.url, url_second) self.assertNotEqual(client_first.url, client_second.url) self.assertEqual(2, len(HttpClientFactory._INSTANCES), "Invalid number of instances.")
def k8s_broker_get_service_status(org_guid, service_id): """GET /v$/:org_id/service/:instance_id/status""" return HttpClientFactory.get( BrokerConfigurationProvider.get( TapComponent.kubernetes_broker)).request( method=HttpMethod.GET, path="{}/service/{}/status".format(org_guid, service_id), msg="K8S BROKER: get instance status")
def get_databases(app_url): """GET listDatabases""" configuration = HttpClientConfiguration(client_type=HttpClientType.BROKER, url=app_url) return HttpClientFactory.get(configuration).request( method=HttpMethod.GET, path="listDatabases", msg="OrientDB-dashboard: get list of databases")
def k8s_broker_get_instance_list(org_guid, space_guid): """GET /rest/kubernetes/{org_guid}/{space_guid}/services""" response = HttpClientFactory.get( KubernetesBrokerTokenConfigurationProvider.get()).request( method=HttpMethod.GET, path="rest/kubernetes/{}/{}/services".format(org_guid, space_guid), msg="K8S BROKER: get instance list") return response
def __init__(self, username, password): self.username = username self.password = password self.client = HttpClientFactory.get(ApplicationConfigurationProvider.get( url=config.console_login_url, username=self.username, password=self.password ))
def k8s_broker_get_catalog(): """GET /v$/catalog""" return HttpClientFactory.get( BrokerConfigurationProvider.get( TapComponent.kubernetes_broker)).request( method=HttpMethod.GET, path="catalog", msg="K8S BROKER: get catalog")
def k8s_broker_delete_instance(instance_guid): """DELETE /v$/service_instances/:instanceId""" return HttpClientFactory.get( BrokerConfigurationProvider.get( TapComponent.kubernetes_broker)).request( method=HttpMethod.DELETE, path="service_instances/{instance_guid}", path_params={'instance_guid': instance_guid}, msg="K8S BROKER: delete instance")
def _send_request(self, url): configuration = HttpClientConfiguration( client_type=HttpClientType.BROKER, url=url) response = HttpClientFactory.get(configuration).request( method=HttpMethod.GET, path="", raw_response=True, raise_exception=False) assert response.status_code == ContainerBrokerHttpStatus.CODE_OK return response