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

Start adding some functionality to Mask #158

Closed
wants to merge 2 commits into from

Conversation

kashike
Copy link
Member

@kashike kashike commented Nov 7, 2016

@codecov-io
Copy link

codecov-io commented Nov 7, 2016

Codecov Report

Merging #158 into next will increase coverage by 0.86%.
The diff coverage is 86.36%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...org/kitteh/irc/client/library/util/StringUtil.java 88.88% <100%> (+4.51%) 20 <5> (+5) ⬆️
...c/client/library/implementation/ActorProvider.java 8.55% <100%> (-0.27%) 5 <2> (ø)
.../java/org/kitteh/irc/client/library/util/Mask.java 82.35% <82.35%> (+82.35%) 15 <15> (+15) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2500b91...ca95af5. Read the comment docs.

@@ -31,6 +31,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
Copy link
Member

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) {
Copy link
Member

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?

@lol768
Copy link
Member

lol768 commented Nov 7, 2016

There's one coverage miss introduced by this... is it feasible to cover it?

Copy link
Member

@lol768 lol768 left a 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.
Copy link
Member

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);
Copy link
Member

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 {
Copy link
Member

@Zarthus Zarthus Nov 7, 2016

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)

Copy link
Member

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)

Copy link
Member

@Zarthus Zarthus Nov 7, 2016

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 ?)

Copy link
Member

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

Copy link
Member

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 = '*';
Copy link
Member

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 .?
Copy link
Member

@Zarthus Zarthus Nov 8, 2016

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());
Copy link
Member

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

private Mask(@Nonnull String string) {
this.string = string;
/**
* Creates a Mask from the given user.
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

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

@Nonnull User user

@mbax mbax modified the milestones: 3.0.0, 3.1.0 Dec 29, 2016
@kashike kashike force-pushed the feature/mask branch 3 times, most recently from 353b3f0 to 804ee4f Compare January 25, 2017 10:07
@mbax mbax modified the milestones: 3.1.0, Future! Feb 9, 2017
@kashike
Copy link
Member Author

kashike commented Oct 8, 2017

Superseded by #207.

@kashike kashike closed this Oct 8, 2017
@mbax mbax removed this from the Future! milestone Jan 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants