-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'apache:master' into master
- Loading branch information
Showing
2 changed files
with
75 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,30 +14,78 @@ | |
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from typing import Optional | ||
|
||
import pytest | ||
from sqlalchemy.engine.url import make_url | ||
|
||
from superset.exceptions import SupersetSecurityException | ||
from superset.security.analytics_db_safety import check_sqlalchemy_uri | ||
from tests.integration_tests.base_tests import SupersetTestCase | ||
|
||
|
||
class TestDBConnections(SupersetTestCase): | ||
def test_check_sqlalchemy_uri_ok(self): | ||
check_sqlalchemy_uri(make_url("postgres://user:[email protected]")) | ||
|
||
def test_check_sqlalchemy_url_sqlite(self): | ||
with pytest.raises(SupersetSecurityException) as excinfo: | ||
check_sqlalchemy_uri(make_url("sqlite:///home/superset/bad.db")) | ||
assert ( | ||
str(excinfo.value) | ||
== "SQLiteDialect_pysqlite cannot be used as a data source for security reasons." | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"sqlalchemy_uri, error, error_message", | ||
[ | ||
("postgres://user:[email protected]", False, None), | ||
( | ||
"sqlite:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+pysqlite:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+aiosqlite:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+pysqlcipher:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+new+driver:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"sqlite+new+:///home/superset/bad.db", | ||
True, | ||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"shillelagh:///home/superset/bad.db", | ||
True, | ||
"shillelagh cannot be used as a data source for security reasons.", | ||
), | ||
( | ||
"shillelagh+apsw:///home/superset/bad.db", | ||
True, | ||
"shillelagh cannot be used as a data source for security reasons.", | ||
), | ||
("shillelagh+:///home/superset/bad.db", False, None), | ||
( | ||
"shillelagh+something:///home/superset/bad.db", | ||
False, | ||
None, | ||
), | ||
], | ||
) | ||
def test_check_sqlalchemy_uri( | ||
sqlalchemy_uri: str, error: bool, error_message: Optional[str] | ||
): | ||
if error: | ||
with pytest.raises(SupersetSecurityException) as excinfo: | ||
check_sqlalchemy_uri(make_url("shillelagh:///home/superset/bad.db")) | ||
assert ( | ||
str(excinfo.value) | ||
== "shillelagh cannot be used as a data source for security reasons." | ||
) | ||
check_sqlalchemy_uri(make_url(sqlalchemy_uri)) | ||
assert str(excinfo.value) == error_message | ||
else: | ||
check_sqlalchemy_uri(make_url(sqlalchemy_uri)) |