Skip to content

Commit

Permalink
Fix: versions in conditions are not validated (#266)
Browse files Browse the repository at this point in the history
They should always be stable releases, so no postfixes of any kind.
  • Loading branch information
TrueBrain committed Dec 10, 2022
1 parent 5c46497 commit 71943cb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
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'."

0 comments on commit 71943cb

Please sign in to comment.