コード例 #1
0
def test_bbox():
    workspace = 'test_bbox_workspace'
    map = 'test_bbox_map'

    process_client.publish_workspace_map(
        workspace,
        map,
    )

    with app.app_context():
        info = util.get_map_info(workspace, map)
    assert_util.assert_same_bboxes(info['bounding_box'],
                                   test_data.SMALL_MAP_BBOX, 0.00001)

    process_client.patch_workspace_map(workspace,
                                       map,
                                       file_paths=[
                                           'test/data/bbox/map_3_3-5_5.json',
                                       ])

    with app.app_context():
        info = util.get_map_info(workspace, map)
    assert_util.assert_same_bboxes(info['bounding_box'],
                                   [3000, 3000, 5000, 5000], 0.1)

    process_client.delete_workspace_map(workspace, map)
コード例 #2
0
def test_migrate_metadata_records_map():
    workspace = 'test_migrate_metadata_records_map_workspace'
    map = 'test_migrate_metadata_records_map_map'
    process_client.publish_workspace_map(workspace, map)
    with app.app_context():
        upgrade_v1_10.migrate_metadata_records(workspace)
    process_client.delete_workspace_map(workspace, map)
コード例 #3
0
def prepare_publications():
    process_client.publish_workspace_layer(USERNAME, LAYERNAME)
    process_client.publish_workspace_map(USERNAME, MAPNAME)
    yield
    process_client.delete_workspace_layer(USERNAME, LAYERNAME)
    process_client.delete_workspace_map(USERNAME, MAPNAME)

    with app.app_context():
        pubs = pub_util.get_publication_infos(USERNAME)
        assert len(pubs) == 0
コード例 #4
0
 def provide_data(self):
     for workspace, layer in self.layers:
         process_client.publish_workspace_layer(workspace, layer)
     for file in os.listdir(self.directory):
         mapname = os.path.splitext(file)[0]
         file_path = os.path.join(self.directory, file)
         process_client.publish_workspace_map(self.workspace,
                                              mapname,
                                              file_paths=[file_path])
         self.maps.add((self.workspace, mapname))
     yield
     for map_workspace, map_name in self.maps:
         process_client.delete_workspace_map(map_workspace, map_name)
     for workspace, layer in self.layers:
         process_client.delete_workspace_layer(workspace, layer)
コード例 #5
0
ファイル: util_auth_test.py プロジェクト: index-git/layman
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)
コード例 #6
0
def test_map_refresh_after_layer_change():
    workspace = 'test_map_refresh_after_layer_change_workspace'
    layer = 'test_map_refresh_after_layer_change_layer'
    map = 'test_map_refresh_after_layer_change_map'
    bbox = (1571000.0, 6268800.0, 1572590.8542062, 6269876.33561699)

    process_client.publish_workspace_layer(workspace, layer)

    map_file = map_data.create_map_with_internal_layers_file(
        [(workspace, layer)], extent_3857=bbox)
    process_client.publish_workspace_map(workspace, map, file_paths=[map_file])

    assert_map_thumbnail(
        workspace, map,
        f'/code/test/data/thumbnail/map_with_internal_layer_basic.png')

    # Test refresh map thumbnail after layer WFS-T query
    data_xml = data_wfs.get_wfs20_insert_points(
        workspace,
        layer,
    )
    process_client.post_wfst(data_xml)
    process_client.wait_for_publication_status(workspace,
                                               process_client.LAYER_TYPE,
                                               layer)
    assert_map_thumbnail(
        workspace, map,
        f'/code/test/data/thumbnail/map_with_internal_layer_basic_after_wfst.png'
    )

    # Test refresh map thumbnail after patch layer
    process_client.patch_workspace_layer(
        workspace,
        layer,
        file_paths=['sample/layman.layer/small_layer.geojson'])
    process_client.wait_for_publication_status(workspace,
                                               process_client.LAYER_TYPE,
                                               layer)
    assert_map_thumbnail(
        workspace, map,
        f'/code/test/data/thumbnail/map_with_internal_layer_basic.png')

    process_client.delete_workspace_map(workspace, map)
    process_client.delete_workspace_layer(workspace, layer)
コード例 #7
0
def test_get_maps():
    username = '******'
    mapname = 'test_get_maps_map'

    process_client.publish_workspace_map(username, mapname, title=mapname)

    with app.app_context():
        url_get = url_for('rest_workspace_maps.get', workspace=username)
    # maps.GET
    response = requests.get(url_get)
    assert response.status_code == 200, response.json()

    assert response.json()[0]['name'] == mapname
    assert response.json()[0]['title'] == mapname
    with app.app_context():
        assert response.json()[0]['url'] == url_for('rest_workspace_map.get', workspace=username, mapname=mapname,
                                                    internal=False)

    process_client.delete_workspace_map(username, mapname)
コード例 #8
0
def test_adjust_prime_db_schema_for_last_change_search():
    workspace = 'test_adjust_prime_db_schema_for_last_change_search_workspace'
    layer = 'test_adjust_prime_db_schema_for_last_change_search_layer'
    map = 'test_adjust_prime_db_schema_for_last_change_search_map'

    timestamp1 = datetime.datetime.now(datetime.timezone.utc)
    process_client.publish_workspace_layer(workspace, layer)
    process_client.publish_workspace_map(workspace, map)
    timestamp2 = datetime.datetime.now(datetime.timezone.utc)
    with app.app_context():
        statement = f'ALTER TABLE {db_schema}.publications ALTER COLUMN updated_at DROP NOT NULL;'
        db_util.run_statement(statement)
        statement = f'update {db_schema}.publications set updated_at = null;'
        db_util.run_statement(statement)

        query = f'select p.id from {db_schema}.publications p where p.updated_at is not null;'
        results = db_util.run_query(query)
        assert not results, results

        upgrade_v1_12.adjust_data_for_last_change_search()

        query = f'''
select p.updated_at
from {db_schema}.publications p inner join
     {db_schema}.workspaces w on p.id_workspace = w.id
where w.name = %s
  and p.type = %s
  and p.name = %s
;'''
        results = db_util.run_query(query, (workspace, 'layman.layer', layer))
        assert len(results) == 1 and len(results[0]) == 1, results
        layer_updated_at = results[0][0]
        assert timestamp1 < layer_updated_at < timestamp2

        results = db_util.run_query(query, (workspace, 'layman.map', map))
        assert len(results) == 1 and len(results[0]) == 1, results
        map_updated_at = results[0][0]
        assert timestamp1 < map_updated_at < timestamp2

        assert layer_updated_at < map_updated_at

    process_client.delete_workspace_layer(workspace, layer)
    process_client.delete_workspace_map(workspace, map)
コード例 #9
0
ファイル: authz_test.py プロジェクト: index-git/layman
 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)
コード例 #10
0
ファイル: publications_test.py プロジェクト: index-git/layman
def test_publications_same_name():
    publ_name = 'test_publications_same_name_publ'
    username = '******'
    username2 = 'test_publications_same_name_user2'

    process_client.publish_workspace_layer(username, publ_name)
    process_client.publish_workspace_map(username, publ_name)
    process_client.publish_workspace_layer(username2, publ_name)
    process_client.publish_workspace_map(username2, publ_name)

    with app.app_context():
        pubs = publications.get_publication_infos(username)
        assert len(pubs) == 2
        pubs = publications.get_publication_infos(username2)
        assert len(pubs) == 2
        pubs = publications.get_publication_infos()
        assert len(pubs) >= 4

    process_client.delete_workspace_layer(username, publ_name)
    process_client.delete_workspace_map(username, publ_name)
    process_client.delete_workspace_layer(username2, publ_name)
    process_client.delete_workspace_map(username2, publ_name)
コード例 #11
0
def test_get_map_title():
    username = '******'
    maps = [("c_test_get_map_title_map", "C Test get map title - map title íářžý"),
            ("a_test_get_map_title_map", "A Test get map title - map title íářžý"),
            ("b_test_get_map_title_map", "B Test get map title - map title íářžý")
            ]
    sorted_maps = sorted(maps)

    for (name, title) in maps:
        process_client.publish_workspace_map(username, name, title=title)

    with app.app_context():
        url_get = url_for('rest_workspace_maps.get', workspace=username)
    # maps.GET
    response = requests.get(url_get)
    assert response.status_code == 200, response.json()

    for i in range(0, len(sorted_maps) - 1):
        assert response.json()[i]["name"] == sorted_maps[i][0]
        assert response.json()[i]["title"] == sorted_maps[i][1]

    for (name, title) in maps:
        process_client.delete_workspace_map(username, name)
コード例 #12
0
def test_migrate_maps_on_wms_workspace(ensure_map):
    layer_workspace = 'test_migrate_maps_on_wms_workspace_layer_workspace'
    layer = 'test_migrate_maps_on_wms_workspace_layer'
    workspace = 'test_migrate_maps_on_wms_workspace_workspace'
    map = 'test_migrate_maps_on_wms_workspace_map'
    expected_file = 'sample/style/test_sld_style_applied_in_map_thumbnail_map.png'

    ensure_map(workspace, map, layer_workspace, layer)

    with app.app_context():
        map_json = input_file.get_map_json(workspace, map)
        assert map_json['layers'][0]['url'] == 'http://localhost:8000/geoserver/test_migrate_maps_on_wms_workspace_layer_workspace/ows',\
            map_json
        thumbnail_path = thumbnail.get_map_thumbnail_path(workspace, map)
    diffs_before = util.compare_images(expected_file, thumbnail_path)
    shutil.copyfile(
        thumbnail_path,
        '/code/tmp/artifacts/upgrade_v1_10_map_thumbnail_before.png')
    assert 28000 < diffs_before < 35000

    with app.app_context():
        upgrade_v1_10.migrate_maps_on_wms_workspace()

    with app.app_context():
        map_json = input_file.get_map_json(workspace, map)
        assert map_json['layers'][0][
            'url'] == 'http://localhost:8000/geoserver/test_migrate_maps_on_wms_workspace_layer_workspace_wms/ows', map_json
        thumbnail.generate_map_thumbnail(workspace, map, '')
    diffs_after = util.compare_images(expected_file, thumbnail_path)
    shutil.copyfile(
        thumbnail_path,
        '/code/tmp/artifacts/upgrade_v1_10_map_thumbnail_after.png')
    assert diffs_after < 1000

    process_client.delete_workspace_layer(layer_workspace, layer)
    process_client.delete_workspace_map(workspace, map)
コード例 #13
0
ファイル: oauth2_test.py プロジェクト: index-git/layman
def test_patch_current_user_without_username():

    username1 = 'test_patch_current_user_user1'
    username2 = 'test_patch_current_user_user2'

    user1_authn_headers = process_client.get_authz_headers(username1)
    user2_authn_headers = process_client.get_authz_headers(username2)

    # reserve username
    with app.app_context():
        rest_path = url_for('rest_current_user.patch', adjust_username='******')
    response = requests.patch(rest_path, headers=user1_authn_headers)
    assert response.status_code == 200, response.text

    # check if it was reserved
    with app.app_context():
        rest_path = url_for('rest_current_user.get')
    response = requests.get(rest_path, headers=user1_authn_headers)
    assert response.status_code == 200, response.text
    resp_json = response.json()
    assert resp_json['authenticated'] is True
    assert 'username' in resp_json
    exp_username = '******'
    exp_sub = '20142'
    assert resp_json['username'] == exp_username
    assert resp_json['claims']['sub'] == exp_sub

    iss_id = liferay.__name__
    from layman.authn.redis import _get_issid_sub_2_username_key
    rds_key = _get_issid_sub_2_username_key(iss_id, exp_sub)
    rds = settings.LAYMAN_REDIS
    assert rds.get(rds_key) == exp_username

    from layman.authn.filesystem import get_authn_info
    authn_info = get_authn_info(exp_username)
    assert authn_info['iss_id'] == iss_id
    assert authn_info['sub'] == exp_sub

    # re-reserve username
    with app.app_context():
        rest_path = url_for('rest_current_user.patch', adjust_username='******')
    response = requests.patch(rest_path, headers=user1_authn_headers)
    assert response.status_code == 400, response.text
    r_json = response.json()
    assert r_json['code'] == 34
    assert r_json['detail']['username'] == exp_username

    # reserve same username by other user
    with app.app_context():
        rest_path = url_for('rest_current_user.patch')
    response = requests.patch(rest_path,
                              data={
                                  'username': exp_username,
                              },
                              headers=user2_authn_headers)
    assert response.status_code == 409, response.text
    r_json = response.json()
    assert r_json['code'] == 35
    assert 'detail' not in r_json

    # reserve other username by other user
    with app.app_context():
        rest_path = url_for('rest_current_user.patch')
    exp_username2 = 'test_patch_current_user_user2'
    exp_sub2 = '20143'
    response = requests.patch(rest_path,
                              data={
                                  'username': exp_username2,
                              },
                              headers=user2_authn_headers)
    assert response.status_code == 200, response.text
    resp_json = response.json()
    assert 'username' in resp_json
    assert resp_json['username'] == exp_username2
    assert resp_json['claims']['sub'] == exp_sub2

    # test map metadata
    workspace = exp_username
    exp_email = 'test_patch_current_user_user1_email' + '@liferay.com'
    exp_name = 'FirstName MiddleName LastName'
    mapname = 'map1'
    process_client.publish_workspace_map(workspace,
                                         mapname,
                                         headers=user1_authn_headers)

    with app.app_context():
        rest_path = url_for('rest_workspace_map_file.get',
                            workspace=workspace,
                            mapname=mapname)
    response = requests.get(rest_path, headers=user1_authn_headers)
    assert response.status_code == 200, response.text
    resp_json = response.json()
    assert resp_json['name'] == mapname
    user_info = resp_json['user']
    assert {'email', 'name'} == set(user_info.keys())
    assert user_info['name'] == exp_name
    assert user_info['email'] == exp_email

    process_client.delete_workspace_map(workspace,
                                        mapname,
                                        headers=user1_authn_headers)
コード例 #14
0
def test_update_style_type_in_db():
    workspace = 'test_update_style_type_in_db_workspace'
    map = 'test_update_style_type_in_db_map'
    TestLayerDef = namedtuple('TestLayerDef', [
        'name',
        'style_file',
        'expected_style',
    ])
    layers = [
        TestLayerDef(
            'test_update_style_type_in_db_none_layer',
            '',
            'sld',
        ),
        TestLayerDef(
            'test_update_style_type_in_db_sld_layer',
            'sample/style/generic-blue_sld.xml',
            'sld',
        ),
        TestLayerDef(
            'test_update_style_type_in_db_sld110_layer',
            'sample/style/sld_1_1_0.xml',
            'sld',
        ),
        # This should not happened, because before this release, it was not possible to upload QGIS files
        TestLayerDef(
            'test_update_style_type_in_db_qgis_layer',
            'sample/style/small_layer.qml',
            'sld',
        ),
    ]

    process_client.publish_workspace_map(workspace, map)
    for layer in layers:
        process_client.publish_workspace_layer(
            workspace,
            layer.name,
            style_file=layer.style_file,
        )

    set_column_null = f"""update {DB_SCHEMA}.publications set style_type = null"""

    with app.app_context():
        db_util.run_statement(set_column_null)
        map_info = map_util.get_map_info(workspace, map)
        assert map_info['style_type'] is None
        for layer in layers:
            layer_info = layer_util.get_layer_info(workspace, layer.name)
            assert layer_info['style_type'] is None

        upgrade_v1_10.update_style_type_in_db()

        map_info = map_util.get_map_info(workspace, map)
        assert map_info['style_type'] is None
        for layer in layers:
            layer_info = layer_util.get_layer_info(workspace, layer.name)
            assert layer_info['style_type'] == layer.expected_style

    process_client.delete_workspace_map(workspace, map)
    for layer in layers:
        process_client.delete_workspace_layer(
            workspace,
            layer.name,
        )
コード例 #15
0
def test_map_with_unauthorized_layer():
    username1 = 'test_map_with_unauthorized_layer_user1'
    layername1 = 'test_map_with_unauthorized_layer_layer1'
    mapname1 = 'test_map_with_unauthorized_layer_map1'
    username2 = 'test_map_with_unauthorized_layer_user2'
    layername2 = 'test_map_with_unauthorized_layer_layer2'

    user1_authz_headers = process_client.get_authz_headers(username1)
    user2_authz_headers = process_client.get_authz_headers(username2)

    process_client.reserve_username(username1, headers=user1_authz_headers)
    process_client.reserve_username(username2, headers=user2_authz_headers)

    process_client.publish_workspace_layer(username1,
                                           layername1,
                                           headers=user1_authz_headers)
    process_client.publish_workspace_layer(username2,
                                           layername2,
                                           headers=user2_authz_headers)

    # assert users have access only to their own layer
    process_client.assert_workspace_layers(username1, [layername1],
                                           headers=user1_authz_headers)
    process_client.assert_workspace_layers(username1, [],
                                           headers=user2_authz_headers)
    process_client.assert_workspace_layers(username2, [layername2],
                                           headers=user2_authz_headers)
    process_client.assert_workspace_layers(username2, [],
                                           headers=user1_authz_headers)

    # publish map composed of layers of both users, read for everyone
    process_client.publish_workspace_map(
        username1,
        mapname1,
        file_paths=['sample/layman.map/internal_url_unauthorized_layer.json'],
        access_rights={
            'read': 'EVERYONE',
            'write': f"{username1},{username2}",
        },
        headers=user1_authz_headers,
    )
    process_client.assert_workspace_maps(username1, [mapname1],
                                         headers=user1_authz_headers)
    process_client.assert_workspace_maps(username1, [mapname1],
                                         headers=user2_authz_headers)

    layer1_uuid = process_client.get_workspace_layer(
        username1, layername1, headers=user1_authz_headers)['uuid']
    layer2_uuid = process_client.get_workspace_layer(
        username2, layername2, headers=user2_authz_headers)['uuid']

    # assert that metadata property operates_on contains only layers visible to publisher, whoever is asking and has read access to the map
    assert_operates_on(username1,
                       mapname1, [(layer1_uuid, layername1)],
                       authz_headers=user1_authz_headers)
    assert_operates_on(username1,
                       mapname1, [(layer1_uuid, layername1)],
                       authz_headers=user2_authz_headers)

    process_client.patch_workspace_map(username1,
                                       mapname1,
                                       headers=user2_authz_headers)

    # assert that metadata property operates_on contains only layers visible to last publisher, whoever is asking and has read access to the map
    assert_operates_on(username1,
                       mapname1, [(layer2_uuid, layername2)],
                       authz_headers=user1_authz_headers)
    assert_operates_on(username1,
                       mapname1, [(layer2_uuid, layername2)],
                       authz_headers=user2_authz_headers)

    # clean up
    process_client.delete_workspace_map(username1,
                                        mapname1,
                                        headers=user1_authz_headers)
    process_client.delete_workspace_layer(username1,
                                          layername1,
                                          headers=user1_authz_headers)
    process_client.delete_workspace_layer(username2,
                                          layername2,
                                          headers=user2_authz_headers)