chore: Migrating reports to AuthWebdriverProxy (#10567)

* Migrating reports to AuthWebdriverProxy

* Extracting out webdriver proxy / Adding thumbnail tests to CI

* Adding license

* Adding license again

* Empty commit

* Adding thumbnail tests to CI

* Switching thumbnail test to Postgres

* Linting

* Adding mypy:ignore / removing thumbnail tests from CI

* Putting ignore statement back

* Updating docs

* First cut at authprovider

* First cut at authprovider mostly working - still needs more tests

* Auth provider tests added

* Linting

* Linting again...

* Linting again...

* Busting CI cache

* Reverting workflow change

* Fixing dataclasses

* Reverting back to master

* linting?

* Reverting installation.rst

* Reverting package-lock.json

* Addressing feedback

* Blacking

* Lazy logging strings

* UPDATING.md note
This commit is contained in:
Craig Rueda
2020-08-12 13:28:41 -07:00
committed by GitHub
parent 8fb304d665
commit 2aaa4d92d9
15 changed files with 376 additions and 240 deletions

View File

@@ -100,6 +100,7 @@ class SupersetTestCase(TestCase):
assert user_to_create
user_to_create.roles = [security_manager.find_role(r) for r in roles]
db.session.commit()
return user_to_create
@staticmethod
def create_user(

View File

@@ -40,8 +40,7 @@ from superset.tasks.schedules import (
)
from superset.models.slice import Slice
from tests.base_tests import SupersetTestCase
from .utils import read_fixture
from tests.utils import read_fixture
class TestSchedules(SupersetTestCase):
@@ -172,7 +171,6 @@ class TestSchedules(SupersetTestCase):
mock_driver_class.return_value = mock_driver
mock_driver.find_elements_by_id.side_effect = [True, False]
create_webdriver()
create_webdriver()
mock_driver.add_cookie.assert_called_once()

View File

@@ -16,7 +16,6 @@
# under the License.
# from superset import db
# from superset.models.dashboard import Dashboard
import subprocess
import urllib.request
from unittest import skipUnless
from unittest.mock import patch
@@ -24,15 +23,11 @@ from unittest.mock import patch
from flask_testing import LiveServerTestCase
from sqlalchemy.sql import func
import tests.test_app
from superset import db, is_feature_enabled, security_manager, thumbnail_cache
from superset.extensions import machine_auth_provider_factory
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from superset.utils.screenshots import (
ChartScreenshot,
DashboardScreenshot,
get_auth_cookies,
)
from superset.utils.screenshots import ChartScreenshot, DashboardScreenshot
from superset.utils.urls import get_url_path
from tests.test_app import app
@@ -45,10 +40,7 @@ class TestThumbnailsSeleniumLive(LiveServerTestCase):
def url_open_auth(self, username: str, url: str):
admin_user = security_manager.find_user(username=username)
cookies = {}
for cookie in get_auth_cookies(admin_user):
cookies["session"] = cookie
cookies = machine_auth_provider_factory.instance.get_auth_cookies(admin_user)
opener = urllib.request.build_opener()
opener.addheaders.append(("Cookie", f"session={cookies['session']}"))
return opener.open(f"{self.get_server_url()}/{url}")

16
tests/util/__init__.py Normal file
View File

@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

View File

@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from unittest.mock import call, Mock, patch
from superset.extensions import machine_auth_provider_factory
from tests.base_tests import SupersetTestCase
class MachineAuthProviderTests(SupersetTestCase):
def test_get_auth_cookies(self):
user = self.get_user("admin")
auth_cookies = machine_auth_provider_factory.instance.get_auth_cookies(user)
self.assertIsNotNone(auth_cookies["session"])
@patch("superset.utils.machine_auth.MachineAuthProvider.get_auth_cookies")
def test_auth_driver_user(self, get_auth_cookies):
user = self.get_user("admin")
driver = Mock()
get_auth_cookies.return_value = {
"session": "session_val",
"other_cookie": "other_val",
}
machine_auth_provider_factory.instance.authenticate_webdriver(driver, user)
driver.add_cookie.assert_has_calls(
[
call({"name": "session", "value": "session_val"}),
call({"name": "other_cookie", "value": "other_val"}),
]
)
@patch("superset.utils.machine_auth.request")
def test_auth_driver_request(self, request):
driver = Mock()
request.cookies = {"session": "session_val", "other_cookie": "other_val"}
machine_auth_provider_factory.instance.authenticate_webdriver(driver, None)
driver.add_cookie.assert_has_calls(
[
call({"name": "session", "value": "session_val"}),
call({"name": "other_cookie", "value": "other_val"}),
]
)