def test_wms_ows_proxy(service_endpoint): username = '******' layername = 'test_wms_ows_proxy_layer' authn_headers = get_authz_headers(username) process_client.ensure_reserved_username(username, headers=authn_headers) process_client.publish_workspace_layer(username, layername, headers=authn_headers) wms_url = geoserver_client.get_wms_url(username, service_endpoint) layer_info = process_client.get_workspace_layer(username, layername, headers=authn_headers) tn_bbox = get_square_bbox(layer_info['bounding_box']) from layman.layer.geoserver.wms import VERSION response = get_layer_thumbnail(wms_url, layername, tn_bbox, headers=authn_headers, wms_version=VERSION) response.raise_for_status() assert 'image' in response.headers['content-type'] process_client.delete_workspace_layer(username, layername, headers=authn_headers)
def test_get_users_workspaces(): public_workspace = 'test_get_users_workspaces_workspace' user = '******' publication = 'test_get_users_workspaces_publication' authz_headers = process_client.get_authz_headers(user) process_client.ensure_reserved_username(user, authz_headers) for publication_type in process_client.PUBLICATION_TYPES: process_client.publish_workspace_publication(publication_type, public_workspace, publication) all_sources = [] for type_def in util.get_publication_types(use_cache=False).values(): all_sources += type_def['internal_sources'] providers = util.get_providers_from_source_names(all_sources) for provider in providers: with app.app_context(): usernames = provider.get_usernames() assert public_workspace not in usernames, (publication_type, provider) with app.app_context(): usernames = util.get_usernames(use_cache=False) workspaces = util.get_workspaces(use_cache=False) assert user in usernames assert public_workspace not in usernames assert user in workspaces assert public_workspace in workspaces process_client.delete_workspace_publication(publication_type, public_workspace, publication)
def ensure_user(): # needs liferay_mock and ensure_layman fixtures for tmp_username in [USERNAME, USERNAME2]: authn_headers1 = client_util.get_authz_headers(tmp_username) client_util.ensure_reserved_username(tmp_username, headers=authn_headers1) assert_gs_user_and_roles(tmp_username)
def provide_data(self): process_client.ensure_reserved_username(self.workspace2, self.authn_headers_user2) prime_db_schema_client.ensure_workspace(self.workspace1) for publ_type in process_client.PUBLICATION_TYPES: for workspace, publ_name, publ_params in self.publications: prime_db_schema_client.post_workspace_publication( publ_type, workspace, publ_name, **publ_params) yield prime_db_schema_client.clear_workspaces( [self.workspace1, self.workspace2])
def prep_test_get_publication_info(): auth_header_owner = process_client.get_authz_headers(USER_OWNER) auth_header_without = process_client.get_authz_headers(USER_WITHOUT_RIGHTS) process_client.ensure_reserved_username(USER_OWNER, headers=auth_header_owner) process_client.ensure_reserved_username(USER_WITHOUT_RIGHTS, headers=auth_header_without) access_rights = {'read': USER_OWNER, 'write': USER_OWNER} process_client.publish_workspace_layer(USER_OWNER, LAYER, headers=auth_header_owner, access_rights=access_rights) process_client.publish_workspace_map(USER_OWNER, MAP, headers=auth_header_owner, access_rights=access_rights) yield process_client.delete_workspace_map(USER_OWNER, MAP, headers=auth_header_owner) process_client.delete_workspace_layer(USER_OWNER, LAYER, headers=auth_header_owner)
def provide_publications(self): username = self.username authz_headers = self.authz_headers layername = self.layername mapname = self.mapname process_client.ensure_reserved_username(username, headers=authz_headers) process_client.publish_workspace_layer(username, layername, headers=authz_headers) process_client.publish_workspace_map(username, mapname, headers=authz_headers) yield process_client.delete_workspace_layer(username, layername, headers=authz_headers) process_client.delete_workspace_map(username, mapname, headers=authz_headers)
def test_geoserver_remove_users_for_public_workspaces(): workspace = 'test_geoserver_remove_users_for_public_workspaces_workspace' user = '******' auth_headers = process_client.get_authz_headers(user) layer = 'test_geoserver_remove_users_for_public_workspaces_layer' gs_rolename = gs_util.username_to_rolename(workspace) gs_rolename2 = gs_util.username_to_rolename(user) process_client.publish_workspace_layer(workspace, layer) process_client.ensure_reserved_username(user, auth_headers) with app.app_context(): gs_provider.ensure_whole_user(workspace, auth) usernames = gs_util.get_usernames(auth) assert workspace in usernames assert user in usernames roles = gs_util.get_roles(auth) assert gs_rolename in roles assert gs_rolename2 in roles workspaces = gs_util.get_all_workspaces(auth) assert workspace in workspaces assert user in workspaces upgrade_v1_9.geoserver_remove_users_for_public_workspaces() usernames = gs_util.get_usernames(auth) assert workspace not in usernames, usernames assert user in usernames roles = gs_util.get_roles(auth) assert gs_rolename not in roles, roles assert gs_rolename2 in roles workspaces = gs_util.get_all_workspaces(auth) assert workspace in workspaces, workspaces assert user in workspaces process_client.delete_workspace_layer(workspace, layer) process_client.publish_workspace_layer(workspace, layer) process_client.delete_workspace_layer(workspace, layer) process_client.publish_workspace_layer(workspace, layer + '2') process_client.delete_workspace_layer(workspace, layer + '2')
def provide_publications(self): username = self.owner authz_headers = self.authz_headers_owner layer_both = self.layer_both layer_read = self.layer_read layer_none = self.layer_none process_client.ensure_reserved_username(username, headers=authz_headers) process_client.publish_workspace_layer(username, layer_both, headers=authz_headers, access_rights={ 'read': 'EVERYONE', 'write': 'EVERYONE' }) process_client.publish_workspace_layer(username, layer_read, headers=authz_headers, access_rights={ 'read': 'EVERYONE', 'write': username }) process_client.publish_workspace_layer(username, layer_none, headers=authz_headers, access_rights={ 'read': username, 'write': username }) yield process_client.delete_workspace_layer(username, layer_both, headers=authz_headers) process_client.delete_workspace_layer(username, layer_read, headers=authz_headers) process_client.delete_workspace_layer(username, layer_none, headers=authz_headers)
def provide_data(self): process_client.ensure_reserved_username(self.owner, self.authn_headers_owner) process_client.ensure_reserved_username(self.deleter, self.authn_headers_deleter) yield
def reserve_username(self): process_client.ensure_reserved_username(self.username, headers=self.authz_headers) yield
def test_missing_attribute(style_file, ): username = '******' layername = 'inexisting_attribute_layer' layername2 = 'inexisting_attribute_layer2' authn_headers = get_authz_headers(username) process_client.ensure_reserved_username(username, headers=authn_headers) process_client.publish_workspace_layer( username, layername, file_paths=[ 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_countries.geojson', ], style_file=style_file, headers=authn_headers, ) process_client.publish_workspace_layer( username, layername2, file_paths=[ 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_countries.geojson', ], style_file=style_file, headers=authn_headers, ) with app.app_context(): style_type = layer_util.get_layer_info(username, layername, context={ 'keys': ['style_type'], })['style_type'] def wfs_post(workspace, attr_names_list, data_xml): with app.app_context(): wfs_url = f"http://{settings.LAYMAN_SERVER_NAME}/geoserver/{workspace}/wfs" old_db_attributes = {} old_wfs_properties = {} for layer, attr_names in attr_names_list: # test that all attr_names are not yet presented in DB table old_db_attributes[layer] = db.get_all_column_names( workspace, layer) for attr_name in attr_names: assert attr_name not in old_db_attributes[ layer], f"old_db_attributes={old_db_attributes[layer]}, attr_name={attr_name}" layer_schema = get_wfs_schema(wfs_url, typename=f"{workspace}:{layer}", version=geoserver_wfs.VERSION, headers=authn_headers) old_wfs_properties[layer] = sorted( layer_schema['properties'].keys()) if style_type == 'qml': assert qgis_wms.get_layer_info(workspace, layer) old_qgis_attributes = qgis_util.get_layer_attribute_names( workspace, layer) assert all( attr_name not in old_qgis_attributes for attr_name in attr_names), (attr_names, old_qgis_attributes) process_client.post_wfst(data_xml, headers=authn_headers, workspace=username) new_db_attributes = {} new_wfs_properties = {} for layer, attr_names in attr_names_list: # test that exactly all attr_names were created in DB table new_db_attributes[layer] = db.get_all_column_names( workspace, layer) for attr_name in attr_names: assert attr_name in new_db_attributes[ layer], f"new_db_attributes={new_db_attributes[layer]}, attr_name={attr_name}" assert set(attr_names).union(set( old_db_attributes[layer])) == set(new_db_attributes[layer]) # test that exactly all attr_names were distinguished also in WFS feature type layer_schema = get_wfs_schema(wfs_url, typename=f"{workspace}:{layer}", version=geoserver_wfs.VERSION, headers=authn_headers) new_wfs_properties[layer] = sorted( layer_schema['properties'].keys()) for attr_name in attr_names: assert attr_name in new_wfs_properties[ layer], f"new_wfs_properties={new_wfs_properties[layer]}, attr_name={attr_name}" assert set(attr_names).union(set(old_wfs_properties[layer])) == set(new_wfs_properties[layer]),\ set(new_wfs_properties[layer]).difference(set(attr_names).union(set(old_wfs_properties[layer]))) if style_type == 'qml': assert qgis_wms.get_layer_info(workspace, layer) new_qgis_attributes = qgis_util.get_layer_attribute_names( workspace, layer) assert all( attr_name in new_qgis_attributes for attr_name in attr_names), (attr_names, new_qgis_attributes) else: assert not qgis_wms.get_layer_info(workspace, layer) attr_names = ['inexisting_attribute_attr', 'inexisting_attribute_attr1a'] data_xml = data_wfs.get_wfs20_insert_points_new_attr( username, layername, attr_names) wfs_post(username, [(layername, attr_names)], data_xml) attr_names2 = ['inexisting_attribute_attr2'] data_xml = data_wfs.get_wfs20_update_points_new_attr( username, layername, attr_names2) wfs_post(username, [(layername, attr_names2)], data_xml) attr_names3 = ['inexisting_attribute_attr3'] data_xml = data_wfs.get_wfs20_update_points_new_attr( username, layername, attr_names3, with_attr_namespace=True) wfs_post(username, [(layername, attr_names3)], data_xml) attr_names4 = ['inexisting_attribute_attr4'] data_xml = data_wfs.get_wfs20_update_points_new_attr(username, layername, attr_names4, with_filter=True) wfs_post(username, [(layername, attr_names4)], data_xml) attr_names5 = ['inexisting_attribute_attr5'] data_xml = data_wfs.get_wfs20_replace_points_new_attr( username, layername, attr_names5) wfs_post(username, [(layername, attr_names5)], data_xml) attr_names_i1 = ['inexisting_attribute_attr_complex_i1'] attr_names_i2 = ['inexisting_attribute_attr_complex_i2'] attr_names_u = ['inexisting_attribute_attr_complex_u'] attr_names_r = ['inexisting_attribute_attr_complex_r'] attr_names_complex = [(layername, attr_names_i1 + attr_names_r), (layername2, attr_names_i2 + attr_names_u)] data_xml = data_wfs.get_wfs20_complex_new_attr( workspace=username, layername1=layername, layername2=layername2, attr_names_insert1=attr_names_i1, attr_names_insert2=attr_names_i2, attr_names_update=attr_names_u, attr_names_replace=attr_names_r) wfs_post(username, attr_names_complex, data_xml) attr_names6 = ['inexisting_attribute_attr6'] data_xml = data_wfs.get_wfs10_insert_points_new_attr( username, layername, attr_names6) wfs_post(username, [(layername, attr_names6)], data_xml) attr_names7 = ['inexisting_attribute_attr7'] data_xml = data_wfs.get_wfs11_insert_points_new_attr( username, layername, attr_names7) wfs_post(username, [(layername, attr_names7)], data_xml) attr_names8 = ['inexisting_attribute_attr8'] data_xml = data_wfs.get_wfs10_update_points_new(username, layername, attr_names8, with_attr_namespace=True) wfs_post(username, [(layername, attr_names8)], data_xml) attr_names9 = ['inexisting_attribute_attr9'] data_xml = data_wfs.get_wfs10_update_points_new(username, layername, attr_names9, with_filter=True) wfs_post(username, [(layername, attr_names9)], data_xml) attr_names10 = ['inexisting_attribute_attr10'] data_xml = data_wfs.get_wfs11_insert_polygon_new_attr( username, layername, attr_names10) wfs_post(username, [(layername, attr_names10)], data_xml) process_client.delete_workspace_layer(username, layername, headers=authn_headers) process_client.delete_workspace_layer(username, layername2, headers=authn_headers)