Skip to content

Commit

Permalink
Fix: versions in conditions are not validated
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 c5040f4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bananas_api/helpers/api_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ 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', got '{condition}'."
)
else:
if not data[0].startswith(">= "):
raise ValidationError(
Expand All @@ -156,6 +169,22 @@ 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', 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', got '{data[1][2:]}'."
)


class VersionMinimized(Global):
read_only = ["upload_date", "md5sum_partial", "filesize", "license", "availability"]
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 '1.2.3', 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 '1.2.3', got '1.9.0rc1'."

0 comments on commit c5040f4

Please sign in to comment.