Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify travis tests to create user with password for mysql and postgres #1092

Conversation

dennisobrien
Copy link
Contributor

Modify the Travis CI tests to create a database user with a password and use these in the SQLALCHEMY_DATABASE_URI for the tests for mysql and postgres.

This is related to #1070 and I expect this PR to have failing Travis tests.

It's fine to reject this PR -- I just wanted to verify that the tests will fail.

…es and use these in the SQLALCHEMY_DATABASE_URI
@xrmx
Copy link
Contributor

xrmx commented Sep 12, 2016

@dennisobrien please do experiments on your own fork instead of here

…e 'sqlalchemy_uri' field and the encrypted password in the 'password' field.

Modified 'testconn' to work with this.  If the passed uri is different from the masked uri, use the passed uri.  Otherwise, use the decrypted uri associated with this database.
@dennisobrien
Copy link
Contributor Author

The original intent was to test SQLALCHEMY_DATABASE_URI with a username and password as a test for #1070 (sorry @xrmx -- I only realized after that I could have run the same tests Travis runs on my own machine).

The follow up commits address #1070

  • At initialization utils.get_or_create_main_db calls dbobj.set_sqlalchemy_uri(config.get("SQLALCHEMY_DATABASE_URI"))
  • caravel.models.Database.set_sqlalchemy_uri stores the password-masked uri in the field sqlalchemy_uri and the encrypted password in password.
  • That logic was removed from caravel.views.DatabaseView.pre_add.
    • There is still one line in pre_add that I did not move because I don't know where it belongs: utils.merge_perm(sm, 'database_access', db.perm)
  • This refactor broke testconn so I made some changes here:
    • Include database_name in the json payload.
    • If uri is the same as database.safe_sqlalchemy_uri(), use the stored database.sqlalchemy_uri_decrypted().
    • Otherwise, assume the user is trying a different connection string and test that.
    • I really don't know if this is an important feature but it's probably good to respect the user's intent and give accurate feedback.

@xrmx
Copy link
Contributor

xrmx commented Sep 15, 2016

@dennisobrien If you are going to poke with testconn please cherry-pick whatever seems sensible (the test at least) from this pull request:
#694

Also my logic in views seems a bit easier to follow i think.

@dennisobrien
Copy link
Contributor Author

Thanks @xrmx -- I wasn't aware of that test. I brought in the test but I didn't use git cherry-pick since I needed just part of the commit. I still don't have tests running properly on my dev machine so I'm committing the changes with the hopes that the tests will pass.

Do you recommend that this PR supercedes #694 or that I merge that branch into this one and deal with the merge conflicts?

@xrmx
Copy link
Contributor

xrmx commented Sep 15, 2016

@dennisobrien no need to do that, i am going to close #694 if all the relevant pieces are included there :)

response = self.client.post('/caravel/testconn', data=data, content_type='application/json')
assert response.status_code == 200

database = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you checked this return something with a password?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has three parts, but now that I think of it, it should really just use the last two since some of the test cases are against a sqlite db and others use mysql or postgres. So I think I should remove the hard-coded uri here and just rely on the other two tests. One of those two tests with the password masked, the other with the password included in the uri.

This leaves two tests: one that uses the password-masked uri, and the other that uses the uri with the password included.
.query(models.Database)
.filter_by(database_name=database_name)
.first()
)
request_uri = request.json.get('uri')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri = request.json.get('uri')

so that you can save a couple of assigments later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring here just as you posted this comment. I could skip creating request_uri but I thought I'd be explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the forking paths here in 8c91119
Thanks for the advice!

@dennisobrien
Copy link
Contributor Author

Hmm, I'm getting a new test failure that has me scratching my head. This passed in the previous Travis run so I'm not sure what's happening here.

======================================================================
ERROR: test_run_async_query (tests.celery_tests.CeleryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/airbnb/caravel/tests/celery_tests.py", line 235, in test_run_async_query
    df1 = pd.read_sql_query(query1.select_sql, con=eng)
  File "/home/travis/build/airbnb/caravel/.tox/py27-postgres/lib/python2.7/site-packages/pandas/io/sql.py", line 431, in read_sql_query
    parse_dates=parse_dates, chunksize=chunksize)
  File "/home/travis/build/airbnb/caravel/.tox/py27-postgres/lib/python2.7/site-packages/pandas/io/sql.py", line 1190, in read_query
    result = self.execute(*args)
  File "/home/travis/build/airbnb/caravel/.tox/py27-postgres/lib/python2.7/site-packages/pandas/io/sql.py", line 1081, in execute
    return self.connectable.execute(*args, **kwargs)
  File "/home/travis/build/airbnb/caravel/.tox/py27-postgres/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1991, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/home/travis/build/airbnb/caravel/.tox/py27-postgres/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 912, in execute
    type(object))
InvalidRequestError: Unexecutable object type: <type 'NoneType'>
-------------------- >> begin captured logging << --------------------
flask_appbuilder.security.sqla.manager: INFO: Updated user admin  user
--------------------- >> end captured logging << ---------------------

@dennisobrien
Copy link
Contributor Author

The remaining questions I have:

  • Why is DatabaseView.pre_add not called? Is it called for others? Was it called at one point then some dependency changed?
  • DatabaseView.pre_add is still there but only has a call to utils.merge_perm. Should this be moved to utils.get_or_create_main_db?

@xrmx
Copy link
Contributor

xrmx commented Sep 17, 2016

Il 17/09/2016 02:16, dennisobrien ha scritto:

The remaining questions I have:

  • Why is |DatabaseView.pre_add| not called? Is it called for others? Was it
    called at one point then some dependency changed?

I've upgraded my test caravel instance to a recent master and it broke
connections to the database, updating my connection uri and saving the database
model fixed the issue. So it looks like the hooks works fine before the password
is clear but not if it's masked?

@dennisobrien
Copy link
Contributor Author

#694 was merged into master. I'm dealing with the merge conflicts in this branch and will push something shortly.

mistercrunch and others added 9 commits September 18, 2016 23:11
* Single quote filter values with comma

* refactor for codeclimate limite

* Added unit tests and tooltip
* [sql lab] specify schema name when generating vanila query

* Fixing some react warnings
* Add time grain support for time columnd in unix timestamp

* Fix datetime parsing for unix epoch

Since we've already converted unix epoch to datetime type,
we shouldn't specify 'unit' parameter in pandas.to_datetime

* Fix SQLite timestamp to datetime conversion
…e#1120)

margin_size does not apply. Also nvd3 auto-adjust font-size of axis
labels.
Temporary solution here: Setting a fixed font-size on nvd3 axis labels
and a minimum threshold for label size.
mistercrunch and others added 11 commits September 18, 2016 23:11
* When the label size is too short, the constant for calculating
margin_size does not apply. Also nvd3 auto-adjust font-size of axis
labels.
Temporary solution here: Setting a fixed font-size on nvd3 axis labels
and a minimum threshold for label size.

* Only stretch margin for dist_bar
* [explore] giving more room to Slice title

* h2->h3 for slice title
* [security] prevent XSS on FAB list views

* addressing comments
If ddtm_expr is an expression with special characters then timestamp_grain escapes
the special characters already escaped.

Solution discussed with sqlalchemy upstream:
https://bitbucket.org/zzzeek/sqlalchemy/issues/3737/literal_column-given-a-specific-sql

Fix apache#617
…e 'sqlalchemy_uri' field and the encrypted password in the 'password' field.

Modified 'testconn' to work with this.  If the passed uri is different from the masked uri, use the passed uri.  Otherwise, use the decrypted uri associated with this database.
…e 'sqlalchemy_uri' field and the encrypted password in the 'password' field.

Modified 'testconn' to work with this.  If the passed uri is different from the masked uri, use the passed uri.  Otherwise, use the decrypted uri associated with this database.
@dennisobrien
Copy link
Contributor Author

I've found myself in an endless loop of git rebase in order to try to deal with these branch conflicts but I'm afraid I'm making a bigger mess. If it is simpler to close this PR and have me open another I'm happy to do that.

@xrmx
Copy link
Contributor

xrmx commented Sep 19, 2016

@dennisobrien do whatever you feel more comfortable with :)

@dennisobrien
Copy link
Contributor Author

Closing this PR and starting a clean PR.

@dennisobrien dennisobrien deleted the dennisobrien/unitests_db_username_password branch September 19, 2016 19:24
@dpgaspar dpgaspar mentioned this pull request Sep 5, 2019
12 tasks
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this pull request Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants