Skip to content

Commit

Permalink
Add warning for too many associated sites
Browse files Browse the repository at this point in the history
  • Loading branch information
sjledoux committed May 2, 2024
1 parent ad13c03 commit e5b0295
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/rws-submissions-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ jobs:
CONTENTS: ${{ steps.read_results.outputs.contents }}
run: echo "$CONTENTS"
- name: Create Comment
if: steps.read_results.outputs.contents != 'success'
if: steps.read_results.outputs.contents != 'success' && ${{ !startsWith(steps.read_results.outputs.contents, 'Warning')}}
run: |
echo "It appears you have failed some tests. Here are your results:" > message.txt
cat results.txt >> message.txt
- name: Comment if sucess
- name: Comment if success
if: steps.read_results.outputs.contents == 'success'
run: echo "Looks like you've passed all of the checks!" >> message.txt
- name: Comment if warning
if: startsWith(steps.read_results.outputs.contents, 'Warning')
run: |
echo "You have passed all of the checks, but there are one or more warnings associated with your submission." > message.txt
cat results.txt >> message.txt
- name: Write Comment on PR
uses: mshick/add-pr-comment@v2
with:
Expand Down
19 changes: 19 additions & 0 deletions RwsCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from publicsuffix2 import PublicSuffixList

WELL_KNOWN = "/.well-known/related-website-set.json"
ASSOCIATED_LIMIT = 5

class RwsCheck:

Expand All @@ -45,6 +46,7 @@ def __init__(self, rws_sites: json, etlds: PublicSuffixList, icanns: set):
self.etlds = etlds
self.icanns = icanns
self.error_list = []
self.associated_warning = []

def validate_schema(self, schema_file):
"""Validates the canonical sites list
Expand Down Expand Up @@ -170,6 +172,23 @@ def check_exclusivity(self, check_sets):
else:
site_list.update(aliases)

def check_associated_count(self, check_sets):
"""This method checks for RwsSets that exceed the associated limit
Creates a warning for each set passed in the check_sets list that has
more associatedSites than the ASSOCIATED_LIMIT
Args:
check_sets: Dict[string, RwsSet]
Returns:
None
"""
for primary, rws in check_sets.items():
if len(rws.associated_sites) > ASSOCIATED_LIMIT:
self.associated_warning.append(
f"Warning: the set for {primary} contains more than {ASSOCIATED_LIMIT} associated sites."
)

def url_is_https(self, site):
"""A function that checks for https://
Expand Down
8 changes: 6 additions & 2 deletions check_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def main():
# Run rest of checks
check_list = [
rws_checker.has_all_rationales,
rws_checker.find_non_https_urls,
rws_checker.find_non_https_urls,
rws_checker.check_associated_count,
rws_checker.find_invalid_eTLD_Plus1,
rws_checker.find_invalid_well_known,
rws_checker.find_invalid_alias_eSLDs,
Expand All @@ -150,7 +151,10 @@ def main():
print(checker_error)
for error_text in error_texts:
print(error_text)
else:
elif rws_checker.associated_warning:
for warning in rws_checker.associated_warning:
print(warning)
else:
print("success", end='')


Expand Down
78 changes: 78 additions & 0 deletions tests/rws_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,84 @@ def test_expected_rationales_case(self):
loaded_sets = rws_check.load_sets()
self.assertEqual(rws_check.error_list, [])

class TestCheckAssociatedCount(unittest.TestCase):
def test_within_limit(self):
json_dict = {
"sets":
[
{
"primary": "https://primary.com",
"associatedSites": ["https://associated1.com"],
"rationaleBySite": {}
}
]
}
rws_check = RwsCheck(rws_sites=json_dict,
etlds=None,
icanns=set())
loaded_sets = rws_check.load_sets()
rws_check.check_associated_count(loaded_sets)
self.assertEqual(rws_check.associated_warning, [])

def test_over_limit(self):
json_dict = {
"sets":
[
{
"primary": "https://primary.com",
"associatedSites": ["https://associated1.com",
"https://associated2.com",
"https://associated3.com",
"https://associated4.com",
"https://associated5.com",
"https://associated6.com"],
"rationaleBySite": {}
}
]
}
rws_check = RwsCheck(rws_sites=json_dict,
etlds=None,
icanns=set())
loaded_sets = rws_check.load_sets()
rws_check.check_associated_count(loaded_sets)
self.assertEqual(rws_check.associated_warning,
["Warning: the set for https://primary.com contains more than 5 associated sites."])

def test_multi_over_limit(self):
json_dict = {
"sets":
[
{
"primary": "https://primary.com",
"associatedSites": ["https://associated1.com",
"https://associated2.com",
"https://associated3.com",
"https://associated4.com",
"https://associated5.com",
"https://associated6.com"],
"rationaleBySite": {}
},
{
"primary": "https://primary2.com",
"associatedSites": ["https://associated7.com",
"https://associated8.com",
"https://associated9.com",
"https://associated10.com",
"https://associated11.com",
"https://associated12.com"],
"rationaleBySite": {}
}
]
}
rws_check = RwsCheck(rws_sites=json_dict,
etlds=None,
icanns=set())
loaded_sets = rws_check.load_sets()
rws_check.check_associated_count(loaded_sets)
self.assertEqual(rws_check.associated_warning,
["Warning: the set for https://primary.com contains more than 5 associated sites.",
"Warning: the set for https://primary2.com contains more than 5 associated sites."])

class TestCheckExclusivity(unittest.TestCase):
def test_servicesets_overlap(self):
json_dict = {
Expand Down

0 comments on commit e5b0295

Please sign in to comment.