Skip to content

Commit 3dcc68c

Browse files
authored
Merge pull request #94 from atlassian-labs/fix-validator-io
Fix validator io
2 parents f17e2ef + a868e3a commit 3dcc68c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"key": "confluence-helloworld-addon",
3+
"name": "Hello World",
4+
"description": "My very first add-on",
5+
"vendor": {
6+
"name": "Angry Nerds",
7+
"url": "https://www.atlassian.com/angrynerds"
8+
},
9+
"baseUrl": "https://foo.bar.io",
10+
"links": {
11+
"self": "https://atlassian.com/atlassian-connect.json",
12+
"homepage": "https://atlassian.com/atlassian-connect.json"
13+
},
14+
"authentication": {
15+
"type": "none"
16+
},
17+
"lifecycle": {
18+
"installed": "/installed"
19+
},
20+
"scopes": ["READ"],
21+
"modules": {
22+
"dynamicContentMacros": [
23+
{
24+
"key": "helloworld-macro",
25+
"name": {
26+
"value": "<svg/onload=prompt(2)>"
27+
},
28+
"url": "/macro",
29+
"description": {
30+
"value": "Says 'Hello World'."
31+
},
32+
"outputType": "block",
33+
"bodyType": "none"
34+
}
35+
]
36+
}
37+
}

tests/test_app_validator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_missing_keys():
5252

5353
def test_invalid_base_url():
5454
descriptor_file = 'tests/examples/descriptor_invalid_base_url.json'
55+
# avoid calling constructor
5556
validator = object.__new__(AppValidator)
5657
validator.session = None
5758
validator.descriptor_url = 'https://example.com'
@@ -65,6 +66,15 @@ def test_invalid_base_url():
6566
assert wrapped_e.type == SystemExit
6667
assert wrapped_e.value.code == 1
6768

69+
def test_invalid_base_url():
70+
descriptor_file = 'tests/examples/descriptor_io_base_url.json'
71+
validator = object.__new__(AppValidator)
72+
validator.session = None
73+
validator.descriptor_url = 'https://example.com'
74+
validator.descriptor = json.loads(open(descriptor_file, 'r').read())
75+
validator.timeout = 30
76+
77+
assert validator._validate_base_url()
6878

6979
def test_invalid_remote_descriptor():
7080
# Test for exceptions on non-JSON responses and when a descriptor returns an error HTTP status code

utils/app_validator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def _get_and_request_descriptor(self) -> Optional[dict]:
2828
return descriptor
2929

3030
def _validate_base_url(self) -> bool:
31-
res = validators.url(self.descriptor['baseUrl'], rfc_1034=True)
31+
url = self.descriptor['baseUrl']
32+
# optional trailing dot not handled correctly for .io domains
33+
res = validators.url(url, rfc_1034=True) or validators.url(url)
3234
if not res:
3335
logging.error(f"{self.descriptor['baseUrl']} was not a valid URL.")
3436
return bool(res)

0 commit comments

Comments
 (0)