8000 gh-543 Update regex to include hyphens in username by jmathai · Pull Request #544 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

gh-543 Update regex to include hyphens in username #544

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

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion github3/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ def pubsubhubbub(self, mode, topic, callback, secret=''):
:returns: bool
"""
from re import match
m = match('https?://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
m = match('https?://[\w\d\-\.\:]+/\w[\w-]+\w/[\w\._-]+/events/\w+',
topic)
status = False
if mode and topic and callback and m:
data = [('hub.mode', mode), ('hub.topic', topic),
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,32 @@ def test_pubsubhubbub(self):
}
)

def test_pubsubhubbub_invalid_username(self):
"""Verify a valid call with invalid username does not call post."""
topic = (
'hub.topic',
'https://github.com/-octocat/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False

def test_pubsubhubbub_valid_username(self):
"""Verify a valid call with valid username calls post."""
topic = (
'hub.topic',
'https://github.com/o-cto-ca-t/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is True

Copy link
Owner

Choose a reason for hiding this comment

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

Please don't change existing tests, simply add new ones

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Should I duplicate that test with this single change?

Copy link
Owner

Choose a reason for hiding this comment

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

Duplicate it with a new test name and docstring and this change, yes.

def test_pubsubhubbub_secret(self):
"""Verify the request for creating a pubsubhubbub hook."""
topic = (
Expand Down
0