Fixed HTTP Digest backend unauthenticated user being added as reviewer issue- Bug-4929

Review Request #11980 — Created Jan. 22, 2022 and updated

sheenaNg
Review Board
release-4.0.x
reviewboard

Currently, non-existing username is allowed to be added as a reviewer in Review Board review request even though the username does not exist in the HTTP Digest .htpasswd file.
The fix involves creating a new helper function that checks if the username is found in the .htpasswd file and have both the authenticate and get_or_create_user functions call this helper function. It will not create a user if the username is not found, and hence it will not allow non-existing username to be added as a reviewer.

Added a test suite for the HTTPDigestBackend class that covers the three methods in the class.

As for manual checking, I attached a couple of files to show the output on the review request.
The first screenshot shows error when adding non-exsiting user as a reviewer.
The second screenshot shows that an existing user is added as a reviewer successfully.
The third screenshot shows all the users I have on the list.

Summary Author
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
Removed commented-out code
sng06
Fixed styling issues
sng06
Changed the argument name to match what
sng06
Changed method name
sng06
Added docstrings to htpasswd_get_user method
sng06
Deleted unecessary text in docstrings
sng06
Added unit test suite for HTTPDigestBackend class
sng06
Fixed over-indented linting issue
sng06
Addressed code review feedback
sng06
Changed the htpassword_user_info type to dict in the method parameter
sng06

Description From Last Updated

E265 block comment should start with '# '

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

E501 line too long (92 > 79 characters)

reviewbotreviewbot

E501 line too long (103 > 79 characters)

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

E501 line too long (84 > 79 characters)

reviewbotreviewbot

E501 line too long (90 > 79 characters)

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

W391 blank line at end of file

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

E501 line too long (92 > 79 characters)

reviewbotreviewbot

E501 line too long (103 > 79 characters)

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

E501 line too long (84 > 79 characters)

reviewbotreviewbot

E501 line too long (90 > 79 characters)

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

W293 blank line contains whitespace

reviewbotreviewbot

W391 blank line at end of file

reviewbotreviewbot

We need to use the same name for the argument as what's used in the method definition itself (htpassword_user_info).

mike_conleymike_conley

E127 continuation line over-indented for visual indent

reviewbotreviewbot

E127 continuation line over-indented for visual indent

reviewbotreviewbot

E127 continuation line over-indented for visual indent

reviewbotreviewbot

We need to add an entry for the new htpassword_user_info arg.

daviddavid

This should be shortened so it can fit in one line. If you need additional detail, add another paragraph.

daviddavid

Since this is unused, let's just get rid of it. It's needed in the get_or_create_user method because that's the API …

daviddavid

dictionary -> dict

daviddavid

Please put full-module imports above from imports within the section.

daviddavid

When we have to wrap the docstring for test cases, please put the final """ on its own line.

daviddavid

These can be condensed: self.spy_on(self.backend._htpasswd_get_user, call_fake=lambda obj: _user_info) self.spy_on(self.backend.get_or_create_user, call_fake=lambda obj, username, request: \ User(username=username))

daviddavid

When we have to wrap the docstring for test cases, please put the final """ on its own line.

daviddavid

Similar thing here as above.

daviddavid

These can use lambdas too.

daviddavid

These can use lambdas too

daviddavid

If you create this with NamedTemporaryFile(mode='w'), you don't need to mark these as bytestrings.

daviddavid

Same here.

daviddavid
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

sheenaNg
Review request changed

Commits:

Summary Author
-
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
+
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
+
Removed commented-out code
sng06

Diff:

Revision 2 (+113 -71)

Show changes

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

sheenaNg
mike_conley
  1. Thanks, Sheena! Looking good so far - looking forward to seeing those tests. Just one note below.

  2. We need to use the same name for the argument as what's used in the method definition itself (htpassword_user_info).

  3. 
      
sheenaNg
sheenaNg
Review request changed

Change Summary:

Changed the method name, added docstrings to htpasswd_get_user method, and added test suite for the HTTPDigestBackend class.

Testing Done:

~  

Will be adding some unit tests after the code sprint.

  ~

Added a test suite for the HTTPDigestBackend class that covers the three methods in the class.

   
   

As for manual checking, I attached a couple of files to show the output on the review request.

    The first screenshot shows error when adding non-exsiting user as a reviewer.
    The second screenshot shows that an existing user is added as a reviewer successfully.
    The third screenshot shows all the users I have on the list.

Commits:

Summary Author
-
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
-
Removed commented-out code
sng06
-
Fixed styling issues
sng06
-
Changed the argument name to match what
sng06
+
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
+
Removed commented-out code
sng06
+
Fixed styling issues
sng06
+
Changed the argument name to match what
sng06
+
Changed method name
sng06
+
Added docstrings to htpasswd_get_user method
sng06
+
Deleted unecessary text in docstrings
sng06
+
Added unit test suite for HTTPDigestBackend class
sng06

Diff:

Revision 5 (+617 -93)

Show changes

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

sheenaNg
david
  1. 
      
  2. reviewboard/accounts/backends/http_digest.py (Diff revision 6)
     
     
     
     

    We need to add an entry for the new htpassword_user_info arg.

  3. This should be shortened so it can fit in one line. If you need additional detail, add another paragraph.

  4. Since this is unused, let's just get rid of it. It's needed in the get_or_create_user method because that's the API contract that this class is fulfilling, but here this is just a helper method.

  5. dictionary -> dict

  6. Please put full-module imports above from imports within the section.

  7. When we have to wrap the docstring for test cases, please put the final """ on its own line.

  8. reviewboard/accounts/tests/test_http_digest_auth_backend.py (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
     
     
     

    These can be condensed:

    self.spy_on(self.backend._htpasswd_get_user,
                call_fake=lambda obj: _user_info)
    self.spy_on(self.backend.get_or_create_user,
                call_fake=lambda obj, username, request: \
                    User(username=username))
    
  9. When we have to wrap the docstring for test cases, please put the final """ on its own line.

  10. reviewboard/accounts/tests/test_http_digest_auth_backend.py (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
     
     
     

    Similar thing here as above.

  11. These can use lambdas too.

  12. These can use lambdas too

  13. If you create this with NamedTemporaryFile(mode='w'), you don't need to mark these as bytestrings.

  14. 
      
sheenaNg
Review request changed

Change Summary:

Addressed code review feedback.

Commits:

Summary Author
-
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
-
Removed commented-out code
sng06
-
Fixed styling issues
sng06
-
Changed the argument name to match what
sng06
-
Changed method name
sng06
-
Added docstrings to htpasswd_get_user method
sng06
-
Deleted unecessary text in docstrings
sng06
-
Added unit test suite for HTTPDigestBackend class
sng06
-
Fixed over-indented linting issue
sng06
+
Fixed HTTP Digest backend unauthenticated user being added as reviewer issue
sng06
+
Removed commented-out code
sng06
+
Fixed styling issues
sng06
+
Changed the argument name to match what
sng06
+
Changed method name
sng06
+
Added docstrings to htpasswd_get_user method
sng06
+
Deleted unecessary text in docstrings
sng06
+
Added unit test suite for HTTPDigestBackend class
sng06
+
Fixed over-indented linting issue
sng06
+
Addressed code review feedback
sng06
+
Changed the htpassword_user_info type to dict in the method parameter
sng06

Diff:

Revision 7 (+640 -174)

Show changes

Checks run (2 succeeded)

flake8 passed.
JSHint passed.
Loading...