-
Notifications
You must be signed in to change notification settings - Fork 111
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
Fix domain_is_in?
for deeply nested subdomain
#270
Open
cm-dyoshikawa
wants to merge
5
commits into
micke:main
Choose a base branch
from
cm-dyoshikawa:fix-domains_is_in
base: main
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.
+62
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
36ab1e9
fix domain checking logic in address.rb
cm-dyoshikawa faa6875
feat: Add support for domain hierarchy depth in disposable domain che…
cm-dyoshikawa 34dd381
fix: Adjust domain hierarchy depth check to start from 3
cm-dyoshikawa 980e198
fix: Update domain hierarchy max depth to 3 and adjust related tests
cm-dyoshikawa f052d7f
fix: Correct domain hierarchy token handling in address.rb
cm-dyoshikawa 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 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 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 |
---|---|---|
|
@@ -56,6 +56,53 @@ | |
end | ||
end | ||
|
||
describe "#disposable_domain?" do | ||
phoet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let(:domain_hierarchy_max_depth) { 10 } | ||
|
||
context "when the disposable domain does not have subdomains" do | ||
let(:disposable_domain) { ValidEmail2.disposable_emails.find { |domain| domain.count(".") == 1 } } | ||
|
||
it "is true if the domain is in the disposable_emails list" do | ||
address = described_class.new("foo@#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
|
||
it "is true if the domain is a subdomain of a disposable domain" do | ||
address = described_class.new("foo@sub.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
|
||
it "is true if the domain is a deeply nested subdomain of a disposable domain" do | ||
address = described_class.new("[email protected].#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
|
||
it "is false if the domain is not in the disposable_emails list" do | ||
address = described_class.new("[email protected]", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq false | ||
end | ||
end | ||
|
||
context "when the disposable domain has subdomains" do | ||
let(:disposable_domain) { ValidEmail2.disposable_emails.find { |domain| domain.count(".") > 1 } } | ||
|
||
it "is true if the domain is in the disposable_emails list" do | ||
address = described_class.new("foo@#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
|
||
it "is true if the domain is a subdomain of a disposable domain" do | ||
address = described_class.new("foo@sub.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
|
||
it "is true if the domain is a deeply nested subdomain of a disposable domain" do | ||
address = described_class.new("[email protected].#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:) | ||
expect(address.disposable_domain?).to eq true | ||
end | ||
end | ||
end | ||
|
||
describe "caching" do | ||
let(:email_address) { "[email protected]" } | ||
let(:email_instance) { described_class.new(email_address) } | ||
|
@@ -181,7 +228,7 @@ | |
email_instance.valid_strict_mx? | ||
end | ||
|
||
it "calls the the MX servers lookup" do | ||
it "calls the the MX servers lookup" do | ||
Comment on lines
-184
to
+231
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. This has been automatically fixed by my code editor. Removing unnecessary spaces. |
||
email_instance.valid_strict_mx? | ||
|
||
expect(Resolv::DNS).to have_received(:open).once | ||
|
@@ -308,8 +355,8 @@ | |
stub_const("ValidEmail2::DnsRecordsCache::MAX_CACHE_SIZE", 0) | ||
end | ||
|
||
it "prunes the cache" do | ||
expect(dns_records_cache_instance).to receive(:prune_cache).once | ||
it "prunes the cache" do | ||
expect(dns_records_cache_instance).to receive(:prune_cache).once | ||
|
||
email_instance.valid_mx? | ||
end | ||
|
@@ -331,7 +378,7 @@ | |
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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.
hmhmmm, i guess it has always been truethy? i mean domains typically contain a dot. 🤔
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.
@micke was it on purpose, that in any case, the TLD so
com
fromexample.com
was checked against the list? i guess we can speed up the lib significantly by getting rid of this.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.
To me as well, the TLD check seems unnecessary.
Shall I remove the TLD check while we have this opportunity? I think it's possible.
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.
The implementation might look something like this:
This implementation includes this discussion.
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 have not tested this thoroughly, but maybe you get the basic idea here and can finish it off
there is no iteration over parts, so this is faster and we get rid of the while.
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 see, so there are such cases. If that's the case, the current implementation that allows users to select
max_depth
optionally doesn't seem like a bad idea (Default is3
).I'll wait for your judgment regarding the current implementation.
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've only recently joined as a maintainer, so i'd wait a bit for @micke to add some context information before changing any of the semantics.
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.
Okay, I'll also wait for @micke . Thanks.
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.
Looks like it was introduced in #137, i honestly don't know why it's there 😅 This sounds good to me!
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.
@micke Thank you for your comment. I guess #137 overlooked deeply nested subdomains case.
So, again, I believe this PR will improve the disposable_domain search function.
Could you please review this again, thanks.