-
Notifications
You must be signed in to change notification settings - Fork 359
[ENG-10340] Check for flag #11792
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
Open
bodintsov
wants to merge
9
commits into
CenterForOpenScience:feature/pbs-26-13
Choose a base branch
from
bodintsov:fix/use-account-get-disabled
base: feature/pbs-26-13
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+295
−19
Open
[ENG-10340] Check for flag #11792
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d0c735e
fix REGEX
bodintsov 243dcda
revert REGEX, add tests, improve validator
bodintsov 9d2a552
Flake8
bodintsov baa5c5f
revert regex change, add tests, add urlsplit
bodintsov 8445fc7
apply new logic, add check for notable domains, add tests
bodintsov 35ee1be
flake8
bodintsov 088b98c
consistent naming
bodintsov f90791a
logic improve, fix tests
bodintsov 10b3ec3
flake8
bodintsov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2081,11 +2081,34 @@ def test_validate_domains_field(self): | |
| self.user.save() | ||
| self.user.refresh_from_db() | ||
|
|
||
| assert self.user.is_spammy is True | ||
| assert self.user.is_spammy is False | ||
| self.user.unspam(save=True) | ||
| setattr(self.user, field, 'not a url') | ||
| self.user.save() | ||
|
|
||
| def test_validate_domain_fields_unregistered_contributor(self): | ||
| user = OSFUser.create_unregistered(fullname='google.com') | ||
| with pytest.raises(ValidationError): | ||
| user.save() | ||
| assert user.is_spammy is True | ||
| assert user.is_hammy is False | ||
|
|
||
| def test_validate_domain_fields_notable_domain_in_field_unregistered_contributor(self): | ||
| NotableDomain.objects.get_or_create(domain='google.com', note=NotableDomain.Note.IGNORED) | ||
| user = OSFUser.create_unregistered(fullname='google.com') | ||
| user.save() | ||
| assert user.is_spammy is False | ||
| assert user.is_hammy is True | ||
|
Comment on lines
+2096
to
+2101
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this should be true. |
||
|
|
||
| def test_validate_domain_fields_for_real(self): | ||
| user = OSFUser.create_unregistered(fullname='Sandhya N.Sathesh') | ||
| for field in user.DOMAIN_VALIDATION_FIELDS: | ||
| setattr(user, field, 'Sandhya N.Sathesh') | ||
| user.save() | ||
| user.refresh_from_db() | ||
|
|
||
| assert user.is_spammy is False | ||
| assert user.is_hammy is False | ||
|
|
||
| class TestUserGdprDelete: | ||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,21 @@ | ||
| import pytest | ||
| from osf.exceptions import ValidationValueError | ||
|
|
||
| from osf.models import validators | ||
| from types import SimpleNamespace | ||
| from osf.models import validators, OSFUser, NotableDomain, SpamStatus | ||
| from osf.models.validators import has_domain_in_user_fields_for_names | ||
| from osf_tests.factories import SubjectFactory | ||
|
|
||
|
|
||
| # Ported from tests/framework/test_mongo.py | ||
|
|
||
| def mock_user(user_data): | ||
| user = SimpleNamespace() | ||
| user.DOMAIN_VALIDATION_FIELDS = OSFUser.DOMAIN_VALIDATION_FIELDS | ||
| for field in user.DOMAIN_VALIDATION_FIELDS: | ||
| setattr(user, field, user_data.get(field, '')) | ||
| return user | ||
|
|
||
| def test_string_required_passes_with_string(): | ||
| assert validators.string_required('Hi!') is True | ||
|
|
||
|
|
@@ -50,3 +60,183 @@ def test_validate_expand_subject_hierarchy(): | |
| subject_list = [fruit._id, '12345_bad_id'] | ||
| with pytest.raises(ValidationValueError): | ||
| validators.expand_subject_hierarchy(subject_list) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'user_data', | ||
| [ | ||
| { | ||
| 'fullname': 'Judith Sarah Preuss, M.Sc.', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Preuss', | ||
| 'middle_names': 'Sarah', | ||
| 'suffix': 'M.Sc.', | ||
| }, | ||
| { | ||
| 'fullname': 'J.H. van Hateren', | ||
| 'given_name': 'J.H.', | ||
| 'family_name': 'van Hateren', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Sami-Egil Ahonen', | ||
| 'given_name': 'Sami-Egil', | ||
| 'family_name': 'Ahonen', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Giovanni Luca Ciampaglia', | ||
| 'given_name': 'Giovanni Luca', | ||
| 'family_name': 'Ciampaglia', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Joseph P.R.O. Orgel', | ||
| 'given_name': 'Joseph', | ||
| 'family_name': 'Orgel', | ||
| 'middle_names': 'P.R.O.', | ||
| }, | ||
| { | ||
| 'fullname': 'Andrew Daoust', | ||
| 'given_name': 'Andrew', | ||
| 'family_name': 'Daoust', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Aidan G.C. Wright', | ||
| 'given_name': 'Aidan', | ||
| 'family_name': 'Wright', | ||
| 'middle_names': 'G.C.', | ||
| }, | ||
| { | ||
| 'fullname': 'Guillermo Perez Algorta', | ||
| 'given_name': 'Guillermo', | ||
| 'family_name': 'Perez Algorta', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Sarah Wojkowski, MSc.PT, PhD.', | ||
| 'given_name': 'Sarah', | ||
| 'family_name': 'Wojkowski', | ||
| 'middle_names': 'MSc.PT', | ||
| }, | ||
| { | ||
| 'fullname': 'Brockmann, L.C. (Leon)', | ||
| 'given_name': 'Leon', | ||
| 'family_name': 'Brockmann', | ||
| 'middle_names': 'L.C.', | ||
| }, | ||
| { | ||
| 'fullname': 'Gragnolati, G.M. (Gaia Mariavittoria)', | ||
| 'given_name': 'Gaia', | ||
| 'family_name': 'Gragnolati', | ||
| 'middle_names': 'G.M.', | ||
| }, | ||
| { | ||
| 'fullname': 'F.H. Leeuwis', | ||
| 'given_name': 'F.H.', | ||
| 'family_name': 'Leeuwis', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Grauss, S.E. (Sophie)', | ||
| 'given_name': 'Sophie', | ||
| 'family_name': 'Grauss', | ||
| 'middle_names': 'S.E.', | ||
| }, | ||
| { | ||
| 'fullname': 'Sandhya N.Sathesh', | ||
| 'given_name': 'Sandhya', | ||
| 'family_name': 'N.Sathesh', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'John Doe', | ||
| 'given_name': 'John', | ||
| 'family_name': 'Doe', | ||
| 'middle_names': '', | ||
| } | ||
| ] | ||
| ) | ||
| def test_has_domain_in_user_fields(user_data): | ||
| user = mock_user(user_data) | ||
| has_domain, status = has_domain_in_user_fields_for_names(user) | ||
| assert has_domain is False | ||
| assert status == SpamStatus.UNKNOWN | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'user_data', | ||
| [ | ||
| { | ||
| 'fullname': 'Judith Sarah', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Preuss', | ||
| 'middle_names': 'https://www.google.com', | ||
| 'suffix': 'M.Sc.', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is problematic. |
||
| }, | ||
| { | ||
| 'fullname': 'J.H. van Hateren', | ||
| 'given_name': 'J.H.', | ||
| 'family_name': 'https://google.com', | ||
| 'middle_names': '', | ||
| }, | ||
| { | ||
| 'fullname': 'Judith Sarah', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Preuss', | ||
| 'middle_names': 'www.google.com', | ||
| 'suffix': 'M.Sc.', | ||
| }, | ||
| { | ||
| 'fullname': 'Judith Hateren', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Hateren', | ||
| 'middle_names': 'google.com', | ||
| 'suffix': 'M.Sc.', | ||
| }, | ||
| ] | ||
| ) | ||
| def test_has_domain_in_user_fields_fail(user_data): | ||
| user = mock_user(user_data) | ||
| has_domain, status = has_domain_in_user_fields_for_names(user) | ||
| assert has_domain is True | ||
| assert status == SpamStatus.SPAM | ||
|
|
||
| @pytest.mark.parametrize( | ||
| 'user_data', | ||
| [ | ||
| { | ||
| 'fullname': 'Judith Sarah', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Preuss', | ||
| 'middle_names': 'osf.io', | ||
| 'suffix': 'M.Sc.', | ||
| }, | ||
| ] | ||
| ) | ||
| def test_has_notable_domain_in_user_fields(user_data): | ||
| NotableDomain.objects.get_or_create(domain='osf.io', note=NotableDomain.Note.IGNORED) | ||
| user = mock_user(user_data) | ||
| has_domain, status = has_domain_in_user_fields_for_names(user) | ||
| assert has_domain is False | ||
| assert status == SpamStatus.HAM | ||
|
|
||
| @pytest.mark.parametrize( | ||
| 'user_data', | ||
| [ | ||
| { | ||
| 'fullname': 'Judith Sarah', | ||
| 'given_name': 'Judith', | ||
| 'family_name': 'Preuss', | ||
| 'middle_names': 'osf.io', | ||
| 'suffix': 'M.Sc.', | ||
| }, | ||
| ] | ||
| ) | ||
| def test_has_no_notable_domain_in_user_fields(user_data): | ||
| NotableDomain.objects.get_or_create(domain='google.com', note=NotableDomain.Note.IGNORED) | ||
| user = mock_user(user_data) | ||
| has_domain, status = has_domain_in_user_fields_for_names(user) | ||
| assert has_domain is True | ||
| assert status == SpamStatus.SPAM | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced about this logic. I don't think we want to mark the user as ham if they have an ignored domain in their user parts. I think we just want to ignore domains that are presumed ham or are ignored.