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

9100-evilham-pop3-spaces-in-pass #769

Closed
wants to merge 32 commits into from

Conversation

evilham
Copy link
Contributor

@evilham evilham commented Apr 20, 2017

@codecov
Copy link

codecov bot commented Apr 20, 2017

Codecov Report

Merging #769 into trunk will decrease coverage by 0.57%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##            trunk     #769      +/-   ##
==========================================
- Coverage   91.82%   91.25%   -0.58%     
==========================================
  Files         840      840              
  Lines      148582   147378    -1204     
  Branches    12978    12892      -86     
==========================================
- Hits       136436   134485    -1951     
- Misses      10031    10672     +641     
- Partials     2115     2221     +106

Copy link
Member

@exarkun exarkun left a comment

Choose a reason for hiding this comment

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

Thanks! This is quite a good contribution, particularly for your first. I've left a few comments inline. Sorry they're not all for things you could have discovered on your own by looking at developer docs. I hope they're all clear and reasonable. Please let me know if the case appears to be otherwise.

Apart from the inline comments, I'd also like to suggest that formatting changes (like inserting blank lines and re-wrapping lines to <80 columns) are better done as a separate patch - either before or after the more interesting change you want to submit. It makes the review of both pieces easier.

Thanks again.

@@ -36,7 +36,7 @@
from twisted import cred

##
## Authentication
# Authentication
Copy link
Member

Choose a reason for hiding this comment

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

Probably should leave the comment style alone unless you want to make a case for changing it throughout the module.

@@ -855,7 +858,13 @@ def do_PASS(self, password):

@type password: L{bytes}
@param password: A password.

@type args: L{tuple} or L{None}
@param args: Other words composing the password.
Copy link
Member

Choose a reason for hiding this comment

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

It can't actually be None because it's *args. It can be any tuple, including an empty tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I copied the description from do_AUTH where that of processCommand would have been much better. Will change to:

@type args: L{tuple} of L{bytes}
@param args: Other words composing the password to be joined with a space.

@@ -565,7 +565,8 @@ def state_COMMAND(self, line):
return self.processCommand(*line.split(' '))
except (ValueError, AttributeError, POP3Error, TypeError) as e:
log.err()
self.failResponse('bad protocol or server: %s: %s' % (e.__class__.__name__, e))
self.failResponse(
'bad protocol or server: %s: %s' % (e.__class__.__name__, e))
Copy link
Member

Choose a reason for hiding this comment

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

If you want to change these lines, I'd suggest this style:

self.failResponse(
            'bad protocol or server: %s: %s' % (e.__class__.__name__, e)
)

"""
if args:
password += ' ' + ' '.join(args)
Copy link
Member

Choose a reason for hiding this comment

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

Or password = " ".join((password,) + args).

Regardless of that, b" " - not ' '. Byte strings need to be explicit now.

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 brings me down a rabbit hole: doesn't that mean stuff like return self.processCommand(*line.split(' ')) in line 565 should use b' ' as well? On a quick check, I see this overall in pop3.py.
If that's the case, am I correct to assume we should open a new ticket and fix it there?

Copy link
Member

Choose a reason for hiding this comment

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

Those are also good changes to make. And filing a new ticket to handle those changes is the right idea, yea. These particular strings should probably still change since they're new in this branch (but you could also leave them as long as you promise to fix the whole module after this branch is merged 😄 ).

@@ -1,3 +1,4 @@
# -*- test-case-name: twisted.mail.pop3 -*-
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 backwards. twisted.mail.test.test_pop3 is the test-case-name for twisted/mail/pop3.py. Declaring this variable with this value here won't do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:-D I wasn't sure at all with this one, this needs to be better in the Wiki! What does it do when properly set up anyway?

Copy link
Member

Choose a reason for hiding this comment

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

It does a few things:

  • It defines a buffer-local variable when the file is opened in emacs. The variable name is test-case-name and the value is twisted.mail.pop3.
  • This, in turn, advises emacs' twisted-dev-mode that when you hit F9 to run the test suite for this file it should pass twisted.mail.pop3 to trial (this is why it doesn't make sense - trial twisted.mail.pop3 won't run any tests).
  • It also advises the trial itself what tests to run (see the --testmodule option).
  • And this is also used by the BuildBot "quick" builder to run a subset of the test suite related to files being changed to try to get some results back more quickly than if you have to run the whole test suite. However, I think the "quick" builder was removed a long time ago.

def _cbTestAuthListing(self, ignored, client):
self.assertTrue(client.response[1].startswith('+OK'))
self.assertEqual(sorted(client.response[2:5]),
["AUTH1", "AUTHLAST", "SECONDAUTH"])
self.assertEqual(client.response[5], ".")


def testIllegalPASS(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring for this modified test and rename it to follow the naming convention - test_illegalPASS.

'+OK '])


def testWhiteSpaceInPASS(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring for this new test method and rename it to follow the naming convention. Also, please add more test coverage for the new functionality. For example, multiple words separated by a space and multiple consecutive spaces. Other kinds of whitespace would also be an interesting thing to test (I don't think that's broken but having the test coverage would be beneficial).

Also, a positive-path test where passwords with spaces in them lead to an authentication success would be good. Otherwise the test suite just shows it isn't a parse error - it doesn't show it actually works.

class POP3MiscTests(unittest.TestCase):
"""
Miscellaneous tests more to do with module/package structure than
anything to do with the Post Office Protocol.
"""
def test_all(self):
def testAll(self):
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 a transformation in the wrong direction. 😄 Please revert.

@@ -0,0 +1 @@
twisted.mail.pop3 now accepts passwords that contain spaces.
Copy link
Member

Choose a reason for hiding this comment

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

Very nice. I'd say twisted.mail.pop3.POP3 ... or The POP3 server implemented by twisted.mail.pop3 ... though to avoid client/server confusion

@evilham
Copy link
Contributor Author

evilham commented Apr 20, 2017

Great! Thanks for the comments, will fix 'em later.
However:
some of the changes I had done, were a direct consequence of running twistedchecker and trying to kill some Warnings / Errors it was giving. Does that mean, we should file a bug (or maybe even a couple) against twistedchecker?
I mean it particularly because of the POP3MiscTests.testAll / test_all naming thingy :).

I clarify, I picked this bug as an easy one to get to know Twisted's ways of contributing, and maybe even improving the documentation for that ;).

@exarkun
Copy link
Member

exarkun commented Apr 20, 2017

Does that mean, we should file a bug (or maybe even a couple) against twistedchecker?
I mean it particularly because of the POP3MiscTests.testAll / test_all naming thingy :).

Hmmm yes, sounds like it. twistedchecker should definitely not be telling people to rename things like test_all to things like testAll.

@evilham
Copy link
Contributor Author

evilham commented Apr 25, 2017

@exarkun: can we merge this branch and close this ticket?

I feel like I'm fixing other stuff due to the rookie mistake of messing up with coding standards on the same PR :).

Also, I think the pop3 module is simple enough for me to haunt some of its bugs listed here.

Incidentally, I just opened Trac Issue 9120 referring to this module's Python3 support and coding standards.

I guess it's a good idea to bring up some of the issues we detected in the mailing list?

@evilham evilham closed this Apr 25, 2017
@evilham evilham reopened this Apr 25, 2017
@glyph
Copy link
Member

glyph commented Jun 7, 2017

The one remaining problem here is the minor gap in diff coverage; it looks like tried_user is always passed in https://codecov.io/gh/twisted/twisted/compare/d3a7f6a5f8f673e52398f630566a303edf6e82d3...05f23e3c0ff5cd0ef5ff84c404c1dd6b88603f5c/diff#D1-521 and this log.err call is never invoked: https://codecov.io/gh/twisted/twisted/compare/d3a7f6a5f8f673e52398f630566a303edf6e82d3...05f23e3c0ff5cd0ef5ff84c404c1dd6b88603f5c/diff#D2-792

Can you address these two minor issues, and merge trunk, so we can land? Thanks!

@evilham
Copy link
Contributor Author

evilham commented Jun 7, 2017

Hi @glyph,

As for the tried_user argument:
that should not be the case, on line pop3.py:521 there is a test calling self.run_PASS(b'testuser', b'fooz barz'); which means it should branch into that line.
My local run of trial --coverage does not show an issue here.

I reverted the indentation change that was causing the coverage gap. As mentioned before, that was being caused by the rookie mistake of mixing coding standards fix and bug fix on the same PR.

I'd think this is acceptable, as the thing keeping me from working on Trac Issue 9120 is precisely that this hasn't landed :-). 9120 should result in Python3 support in t.m.pop3 and better tests and coverage for the module.

PS: Travis says 4190.6 fails because of topfile and there is a topfile, am I doing this wrong?

@evilham
Copy link
Contributor Author

evilham commented Jun 7, 2017

My bad, I was also interpreting it as tried_user never being passed, turns out, the case that was not covered was it being passed :).

Just added a test to account for a wrong user being passed and that should solve the partial hit.

@glyph
Copy link
Member

glyph commented Jun 8, 2017

PS: Travis says 4190.6 fails because of topfile and there is a topfile, am I doing this wrong?

The topfile has changed recently with our recent conversion from our newsfiles stuff to towncrier. You just need to put it in a different directory now.

https://twistedmatrix.com/trac/ticket/8133

@evilham
Copy link
Contributor Author

evilham commented Jun 8, 2017

Thank you, I had missed that and didn't think to re-check the docs.
Build is fine now in addition to yesterday's coverage-related changes.

@@ -565,7 +565,9 @@ def state_COMMAND(self, line):
return self.processCommand(*line.split(' '))
except (ValueError, AttributeError, POP3Error, TypeError) as e:
log.err()
self.failResponse('bad protocol or server: %s: %s' % (e.__class__.__name__, e))
self.failResponse(
'bad protocol or server: %s: %s' % (e.__class__.__name__, e)
Copy link
Member

Choose a reason for hiding this comment

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

I am trying to understand what are the rules for this indentation... I see this double indentation in other parts of this PR.

@adiroiban
Copy link
Member

wow... GitHub with "Update this branch" allows me to trigger a merge in others repos.

I hope that with the updated twistedchecker, this PR will get all the errors related to the coding convention

Copy link
Contributor

@rodrigc rodrigc left a comment

Choose a reason for hiding this comment

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

@evilham Can you close this PR, and submit a new one based on latest trunk?

The code changed a lot in trunk after #878

@adiroiban
Copy link
Member

I assume that you can just update with trunk and fix the conflicts and push a new change to this same PR. no need to close this one and open a new one

@rodrigc
Copy link
Contributor

rodrigc commented Oct 11, 2017

@adiroiban No, actually in this case I prefer a new PR, thanks.

@exarkun
Copy link
Member

exarkun commented Oct 17, 2017

@adiroiban No, actually in this case I prefer a new PR, thanks.

Why? Updating the branch behind a PR is standard practice.

@rodrigc
Copy link
Contributor

rodrigc commented Oct 17, 2017

@exarkun Normally I agree but in this case, @evilham made a lot of style changes which overlap with other changes made elsewhere, so to make a clean start, I'm requesting a new patch.

While it may be a "standard practice", I don't believe in one size fits all practices, and it isn't too hard to submit a new PR, which is why I asked.

@evilham
Copy link
Contributor Author

evilham commented Oct 17, 2017

Great, will close now and open a new one with only the code changes.
Note to self: update trac.

@evilham evilham closed this Oct 17, 2017
@evilham evilham deleted the 9100-evilham-pop3-spaces-in-pass branch July 23, 2019 12:00
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

5 participants