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

Fix: versions in conditions are not validated #266

Merged
merged 1 commit into from
Dec 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions bananas_api/helpers/api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ def validate_conditions(self, data, **kwargs):
f"Condition can only mark the first client-version this version does or doesn't work for;"
f" expected '>= VERSION' or '< VERSION', got '{data[0]}'."
)

if data[0].startswith(">="):
condition = data[0][3:]
else:
condition = data[0][2:]

# Check if all parts of the version are integers
try:
[int(p) for p in condition.split(".")]
except ValueError:
raise ValidationError(
f"Versions in a condition should be a stable release in the form of '12.0' or '1.8.0',"
f" got '{condition}'."
)
else:
if not data[0].startswith(">= "):
raise ValidationError(
Expand All @@ -156,6 +170,24 @@ def validate_conditions(self, data, **kwargs):
f" expected '< VERSION', got '{data[0]}'."
)

# Check if all parts of the version are integers
try:
[int(p) for p in data[0][3:].split(".")]
except ValueError:
raise ValidationError(
f"Versions in a condition should be a stable release in the form of '12.0' or '1.8.0',"
f" got '{data[0][3:]}'."
)

# Check if all parts of the version are integers
try:
[int(p) for p in data[1][2:].split(".")]
except ValueError:
raise ValidationError(
f"Versions in a condition should be a stable release in the form of '12.0' or '1.8.0',"
f" got '{data[1][2:]}'."
)


class VersionMinimized(Global):
read_only = ["upload_date", "md5sum_partial", "filesize", "license", "availability"]
Expand Down
10 changes: 10 additions & 0 deletions regression/002_success_new_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ steps:
tags:
- "tag1"
- "tag2"
compatibility:
- name: vanilla
conditions:
- ">= 12.0"
- "< 13.0"
- file-upload: valid2.grf
- file-upload: readme.txt
- file-upload: changelog.txt
Expand All @@ -22,6 +27,11 @@ steps:
tags:
- "tag1"
- "tag2"
compatibility:
- name: vanilla
conditions:
- ">= 12.0"
- "< 13.0"
md5sum-partial: "fc03854a"
content-type: "newgrf"
unique-id: "4e4d4c01"
Expand Down
11 changes: 11 additions & 0 deletions regression/953_condition_invalid_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
- api: user/login
- api: new-package/start
- file-upload: valid.grf
- api: new-package/update
compatibility:
- name: vanilla
conditions:
- ">= 1.9.0rc1"
error:
compatibility.conditions: "Versions in a condition should be a stable release in the form of '12.0' or '1.8.0', got '1.9.0rc1'."
12 changes: 12 additions & 0 deletions regression/954_condition_invalid_version_second.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
steps:
- api: user/login
- api: new-package/start
- file-upload: valid.grf
- api: new-package/update
compatibility:
- name: vanilla
conditions:
- ">= 1.8.0"
- "< 1.9.0rc1"
error:
compatibility.conditions: "Versions in a condition should be a stable release in the form of '12.0' or '1.8.0', got '1.9.0rc1'."