예제 #1
0
    def test_quicksight_link(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION'
        )
        link = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            identifier='5d75e131-20f4-48f8-b0eb-f4ebf36434f4',
            visualisation_catalogue_item=vis,
        )

        quicksight = mocker.patch(
            'dataworkspace.apps.applications.views.get_quicksight_dashboard_name_url'
        )
        quicksight.return_value = (
            'my-dashboard',
            'https://my.dashboard.quicksight.amazonaws.com',
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 200
        assert (
            'https://my.dashboard.quicksight.amazonaws.com'
            in response.content.decode(response.charset)
        )
        assert (
            'frame-src https://eu-west-2.quicksight.aws.amazon.com'
            in response['content-security-policy']
        )
예제 #2
0
    def test_metabase_link(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION'
        )
        link = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            identifier='123456789',
            visualisation_catalogue_item=vis,
        )

        jwt_encode = mocker.patch('dataworkspace.apps.applications.views.jwt.encode')
        jwt_encode.return_value = b'my-token'

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 200
        assert (
            '//metabase.dataworkspace.test:8000/embed/dashboard/my-token#bordered=false&titled=false'
            in response.content.decode(response.charset)
        )
        assert (
            'frame-src metabase.dataworkspace.test'
            in response['content-security-policy']
        )
예제 #3
0
    def test_shows_links_to_visualisations(self, client):
        vis = VisualisationCatalogueItemFactory.create(
            visualisation_template__host_basename='visualisation'
        )
        link1 = VisualisationLinkFactory.create(
            visualisation_type='DATASTUDIO',
            visualisation_catalogue_item=vis,
            name='Visualisation datastudio',
            identifier='https://www.data.studio.test',
        )
        link2 = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            visualisation_catalogue_item=vis,
            name='Visualisation quicksight',
            identifier='5d75e131-20f4-48f8-b0eb-f4ebf36434f4',
        )
        link3 = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            visualisation_catalogue_item=vis,
            name='Visualisation metabase',
            identifier='123456789',
        )

        response = client.get(vis.get_absolute_url())
        body = response.content.decode(response.charset)

        assert response.status_code == 200
        assert '//visualisation.dataworkspace.test:8000/' in body
        assert f'/visualisations/link/{link1.id}' in body
        assert f'/visualisations/link/{link2.id}' in body
        assert f'/visualisations/link/{link3.id}' in body
예제 #4
0
    def test_user_needs_access_via_catalogue_item(self, mocker):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHORIZATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='QUICKSIGHT',
            identifier=str(uuid4()),
            visualisation_catalogue_item=vis,
        )
        quicksight = mocker.patch(
            'dataworkspace.apps.applications.views.get_quicksight_dashboard_name_url'
        )
        quicksight.return_value = (
            'my-dashboard',
            'https://my.dashboard.quicksight.amazonaws.com',
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())
        assert response.status_code == 403

        VisualisationUserPermissionFactory.create(visualisation=vis, user=user)

        response = client.get(link.get_absolute_url())
        assert response.status_code == 200
예제 #5
0
    def test_datastudio_link(self):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHENTICATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='DATASTUDIO',
            identifier='https://www.data.studio',
            visualisation_catalogue_item=vis,
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())

        assert response.status_code == 302
        assert response['location'] == 'https://www.data.studio'
예제 #6
0
    def test_unauthorised_visualisation(self, has_access):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            visualisation_template__user_access_type='REQUIRES_AUTHORIZATION')

        if has_access:
            ApplicationTemplateUserPermissionFactory.create(
                application_template=vis.visualisation_template, user=user)

        client = Client(**get_http_sso_data(user))
        response = client.get(vis.get_absolute_url())

        assert response.status_code == 200
        assert vis.name in response.content.decode(response.charset)
        assert ("You do not have permission to access this data visualisation."
                in response.content.decode(response.charset)) is not has_access
예제 #7
0
    def test_user_needs_access_via_catalogue_item(self):
        user = UserFactory.create()
        vis = VisualisationCatalogueItemFactory.create(
            user_access_type='REQUIRES_AUTHORIZATION')
        link = VisualisationLinkFactory.create(
            visualisation_type='METABASE',
            identifier='123',
            visualisation_catalogue_item=vis,
        )

        client = Client(**get_http_sso_data(user))
        response = client.get(link.get_absolute_url())
        assert response.status_code == 403

        VisualisationUserPermissionFactory.create(visualisation=vis, user=user)

        response = client.get(link.get_absolute_url())
        assert response.status_code == 200