Skip to content
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
2 changes: 1 addition & 1 deletion phabfive/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DEFAULTS = {"PHABFIVE_DEBUG": False, "PHAB_TOKEN": "", "PHAB_URL": ""}
REQUIRED = ["PHAB_TOKEN", "PHAB_URL"]
VALIDATORS = {
"PHAB_URL": "^http(s)?://[a-zA-Z0-9._-]+/api(/)?$",
"PHAB_URL": r"^http(s)?://([a-zA-Z0-9._-]+|\[[a-fA-F0-9:\.]+\])(:[0-9]+)?/api(/)?$",
"PHAB_TOKEN": "^[a-zA-Z0-9-]{32}$",
}
VALID_EXAMPLES = {"PHAB_URL": "example: http://127.0.0.1/api/"}
Expand Down
66 changes: 66 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,74 @@
# -*- coding: utf-8 -*-

import re


def test_status_choices():
from phabfive.constants import REPO_STATUS_CHOICES

assert "active" in REPO_STATUS_CHOICES
assert "inactive" in REPO_STATUS_CHOICES


def test_phab_url_validator_without_port():
from phabfive.constants import VALIDATORS

pattern = VALIDATORS["PHAB_URL"]

# Valid URLs without port
assert re.match(pattern, "http://127.0.0.1/api/")
assert re.match(pattern, "http://127.0.0.1/api")
assert re.match(pattern, "https://phabricator.example.com/api/")
assert re.match(pattern, "http://my-phab.domain.tld/api/")


def test_phab_url_validator_with_port():
from phabfive.constants import VALIDATORS

pattern = VALIDATORS["PHAB_URL"]

# Valid URLs with port (issue #53)
assert re.match(pattern, "http://phabricator.domain.tld:81/api/")
assert re.match(pattern, "https://localhost:8080/api/")
assert re.match(pattern, "http://127.0.0.1:3000/api")
assert re.match(pattern, "http://dev.example.com:443/api/")


def test_phab_url_validator_with_ipv6():
from phabfive.constants import VALIDATORS

pattern = VALIDATORS["PHAB_URL"]

# Valid URLs with IPv6 addresses (must be in brackets)
assert re.match(pattern, "http://[::1]/api/")
assert re.match(pattern, "https://[::1]/api/")
assert re.match(pattern, "http://[2001:db8::1]/api/")
assert re.match(pattern, "http://[fe80::1]/api/")
assert re.match(pattern, "http://[::ffff:127.0.0.1]/api/")


def test_phab_url_validator_with_ipv6_and_port():
from phabfive.constants import VALIDATORS

pattern = VALIDATORS["PHAB_URL"]

# Valid URLs with IPv6 addresses and port
assert re.match(pattern, "http://[::1]:8080/api/")
assert re.match(pattern, "https://[2001:db8::1]:443/api/")
assert re.match(pattern, "http://[fe80::1]:3000/api")


def test_phab_url_validator_invalid():
from phabfive.constants import VALIDATORS

pattern = VALIDATORS["PHAB_URL"]

# Invalid URLs
assert not re.match(pattern, "ftp://example.com/api/")
assert not re.match(pattern, "http://example.com/")
assert not re.match(pattern, "http://example.com")
assert not re.match(pattern, "http://:80/api/")
assert not re.match(pattern, "example.com/api/")
# Invalid IPv6 (missing brackets)
assert not re.match(pattern, "http://::1/api/")
assert not re.match(pattern, "http://2001:db8::1/api/")