-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Start adding some functionality to Mask #158
Conversation
Codecov Report
@@ Coverage Diff @@
## next #158 +/- ##
============================================
+ Coverage 32.58% 33.44% +0.86%
- Complexity 465 485 +20
============================================
Files 192 192
Lines 4125 4180 +55
Branches 445 449 +4
============================================
+ Hits 1344 1398 +54
Misses 2726 2726
- Partials 55 56 +1
Continue to review full report at Codecov.
|
@@ -31,6 +31,7 @@ | |||
import java.util.Collection; | |||
import java.util.HashSet; | |||
import java.util.Objects; | |||
import java.util.Optional; |
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.
Nice.
* @return collection of users that match this mask | ||
*/ | ||
@Nonnull | ||
public Collection<User> getMatches(@Nonnull Channel channel) { |
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.
Are duplicates possible? Why not return a Set
?
There's one coverage miss introduced by this... is it feasible to cover it? |
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.
We need to be careful about how we present these methods and make it clear they aren't equivalent to the authoritative answer as given with TESTMASK
or similar.
} | ||
|
||
/** | ||
* Gets a collection of users that match this mask in the provided channel. |
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.
You should note about the shortcomings of this method and how it's not the same as the set of users the IRCd would ban for a +b
set with the exact same mask.
final Channel channel = Mockito.mock(Channel.class); | ||
final User mbaxter = new TestUser("mbaxter", "~mbax", "kitten.institute", null); | ||
final User kashike = new TestUser("kashike", "kashike", "is.a.miserable.ninja", null); | ||
final User lol768 = new TestUser("lol768", "lol768", "catastrophe.esper.net", null); |
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.
ideally use a host different than *.esper.net, I'm fine with using lynvie.com for mine or just somethinf spoofed.
/** | ||
* It's a mask test. | ||
*/ | ||
public class MaskTest { |
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.
add a test for spoofed masks? freenode/staff/potato
comes to mind and lol
(invalid hostname, valid spoof/mask), or catbot is catbot@�4,1nyan�7nyan�8nyan�3nyan�11nyan�10nyan�12nyan�13nyan� * nyan catbot
(colors in hostnames, yay quakenet)
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.
also a case insensitivity test (Zarthus@potato == zarThus@potAto)
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.
also wildcards (? and *, I see some for * - none for ?)
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.
and CIDR-style ban support would be nice as well
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.
and CIDR-style ban support would be nice as well
Would need to be restricted to IP based hostmasks.
// Let's just do it assuming no IRCD can handle following the rules. | ||
// New pattern: ([^!@]+)!([^!@]+)@([^!@]+) | ||
public static final Pattern NICK_PATTERN = Pattern.compile("([^!@]+)!([^!@]+)@([^!@]+)"); | ||
public static final char WILDCARD_CHARACTER = '*'; |
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.
What about ?
switch (character) { | ||
case '*': | ||
case '?': | ||
builder.append('.').append(character); // * to .* and ? to .? |
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.
That's not how a wildcard-?
works, a wildcard-? translates to regex .
, a wildcard-*
translates to regex .*
Regex .?
would be "zero or one of any", When in reality wildcard-?
matches exactly one of any.
Case in point:
+b ????*!*@*
Bans all four-or-more letter nicks.
With your regex, this would ban all 0 or more letter nicks.
} | ||
builder.insert(0, '^'); | ||
builder.append('$'); | ||
return Pattern.compile(builder.toString()); |
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.
Should include the case insensitivity flag Pattern.CASE_INSENSITIVE
2f2237f
to
63669e6
Compare
private Mask(@Nonnull String string) { | ||
this.string = string; | ||
/** | ||
* Creates a Mask from the given user. |
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.
Perhaps "given user string"
* @return true if user matches this mask | ||
*/ | ||
@Override | ||
public boolean test(User user) { |
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.
@Nonnull User user
353b3f0
to
804ee4f
Compare
Bippity boppity boop
Superseded by #207. |
#130