Skip to content

validate plotly_(api)_domain - HTTPS, not HTTP #997

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

Merged
merged 11 commits into from
May 4, 2018
Merged

Conversation

Kully
Copy link
Contributor

@Kully Kully commented Apr 25, 2018

Addresses #996

Notes:

  1. This error message does not get triggered if the original url in the request starts with zhttp://.... A separate error message is thrown for that.
  2. The original url sent by a user is getting coerced into all lowercase, so a lowercase to lowercase comparison is not necessary.

@Kully
Copy link
Contributor Author

Kully commented Apr 25, 2018

cc @BRONSOLO @cldougl

@BRONSOLO
Copy link
Member

BRONSOLO commented Apr 25, 2018

Thanks @Kully!

@Kully @cldougl what do y'all think of approaching this fix as a validation on the .config file as opposed to error handling on a failed request?

Perhaps a helper function like validated_config_file can be written and called in the get/set_config_file helper functions to make sure the structure of the domains are valid (in this case, set to use HTTPS).

@Kully
Copy link
Contributor Author

Kully commented Apr 25, 2018

what do y'all think of approaching this fix as a validation on the .config file as opposed to error handling on a failed request?

I like this approach. What about we have both just in case? I don't know why the helper function could be bypassed if we set it up correctly though

@BRONSOLO
Copy link
Member

What about we have both just in case?

I think the validation will be sufficient, personally!

@cldougl
Copy link
Member

cldougl commented Apr 25, 2018

Yep I think the config validation could be more beneficial for the user.
Also we suggest that on-premise users set only their plotly_domain rather than both plotly_domain and plotly_api_domain (https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users) so I think it would be confusing to mention the plotly_api_domain in a message returned to the user.

@BRONSOLO
Copy link
Member

@Kully I think this should just be issued as a warning for now and not a full error. Though SSL/TLS is now required for On-Prem, there are some clients that still may be running older versions without SSL/TLS enabled.

@Kully
Copy link
Contributor Author

Kully commented Apr 26, 2018

@BRONSOLO I've deleted the error msg and made a warning instead.

I only placed the validate_config_file() in set_config_file() as get_config_file() appears in the set function.

There is the possibility of added a validate param in get_config that calls the validate_config_file within.

I personally think that we need to validate get_config_file without a bunch of the same error message popping up

@Kully Kully changed the title error message that catches responses with HTTP and not HTTPS validate plotly_(api)_domain - HTTPS, not HTTP Apr 27, 2018
Copy link
Member

@BRONSOLO BRONSOLO left a comment

Choose a reason for hiding this comment

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

Thanks @Kully! Could you please add a test for these changes?

plotly/tools.py Outdated
else:
return FILE_CONTENT[CONFIG_FILE]
returned_obj = FILE_CONTENT[CONFIG_FILE]
return returned_obj
Copy link
Member

Choose a reason for hiding this comment

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

Is this change necessary? Could you add it to a separate commit with a commit msg that explains why if so?

plotly/tools.py Outdated
)


def validate_config_file(*domains):
Copy link
Member

Choose a reason for hiding this comment

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

This is really just validating domains - what do you think about renaming this as validate_domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea

@Kully
Copy link
Contributor Author

Kully commented May 1, 2018

notes:

  • moved test to plotly.utils
  • new test should be passing 🎉
  • only raise UserWarning on set_config_file, not get_config_file

Waiting for tests to pass.

@Kully
Copy link
Contributor Author

Kully commented May 1, 2018

Looks like only streaming errors. We are ignoring these for now @cldougl ?

@cldougl
Copy link
Member

cldougl commented May 2, 2018

@Kully, the streaming tests should pass now

plotly/tools.py Outdated
@@ -186,12 +186,14 @@ def set_config_file(plotly_domain=None,
:param (bool) world_readable: True = public, False = private

"""
# import ipdb; ipdb.set_trace()
Copy link
Member

Choose a reason for hiding this comment

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

please remove this commented code as it is unnecessary 🔪 : )

@@ -297,6 +322,7 @@ def encode_as_decimal(obj):
else:
raise NotEncodable


Copy link
Member

Choose a reason for hiding this comment

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

Is this line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it keeps the file consistent with 2 spaces between functions

@BRONSOLO
Copy link
Member

BRONSOLO commented May 2, 2018

@Kully could you please provide a screenshot of what that warning message looks like when hit?

@Kully
Copy link
Contributor Author

Kully commented May 2, 2018

screen shot 2018-05-02 at 2 15 49 pm

plotly/utils.py Outdated
@@ -32,6 +33,30 @@
lock = threading.Lock()


http_msg = (
"The plotly_domain and plotly_api_domain of your config file must start "
"with 'https', 'http'.\n If you are not using On-Prem then run the "
Copy link
Member

@BRONSOLO BRONSOLO May 3, 2018

Choose a reason for hiding this comment

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

Why include http here? ---> "with 'https', 'http'.

Also I would suggest using On-Premise instead of On-Prem to be consistent with the rest of the codebase.

Also, this .\n If... is introducing an unnecessary space at the start of the line that could be cleaned up.

Copy link
Contributor Author

@Kully Kully May 3, 2018

Choose a reason for hiding this comment

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

That was a typo. I meant to type 'https', not 'http'. Is it fine like that?

Copy link
Member

Choose a reason for hiding this comment

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

Yep! Thanks.

plotly/utils.py Outdated
" plotly_domain='https://plot.ly',\n"
" plotly_api_domain='https://api.plot.ly'\n"
")\n\n\n"
"If you are using On-Prem then you will need to use your company's "
Copy link
Member

Choose a reason for hiding this comment

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

same here On-Prem ---> On-Premise

plotly/utils.py Outdated
"Make sure to replace `your-company.com` with the URL of your Plotly "
"On-Premise server.\nSee "
"https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users "
"for more help with getting started with On-Prem."
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
assert "plotly_domain" in str(w[-1].message)

Copy link
Member

Choose a reason for hiding this comment

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

Nice! Could you also include a test to check that no warning is issued when https is used?

@Kully
Copy link
Contributor Author

Kully commented May 3, 2018

@BRONSOLO all comments addressed. Waiting for tests again.

@Kully
Copy link
Contributor Author

Kully commented May 3, 2018

yay tests are passing 🎉

plotly/utils.py Outdated
@@ -35,15 +35,15 @@

http_msg = (
"The plotly_domain and plotly_api_domain of your config file must start "
"with 'https', 'http'.\n If you are not using On-Prem then run the "
"with 'https', not 'http'.\n If you are not using On-Premise then run the "
Copy link
Member

Choose a reason for hiding this comment

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

I believe the \n If ... spacing still needs to be fixed. I think it would look cleaner without a new line actually.

@BRONSOLO
Copy link
Member

BRONSOLO commented May 4, 2018

One small comment and then 💃 after that.

@Kully Kully merged commit ba5975f into master May 4, 2018
@Kully Kully deleted the error-msg-for-http branch May 4, 2018 19:33
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.

3 participants