Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Test as a Service Client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
INS Courses
AutPy
Test as a Service Client
Commits
64cfc42b
Commit
64cfc42b
authored
2 years ago
by
Florian Bruhin
Browse files
Options
Downloads
Patches
Plain Diff
Reject invalid zip files
Closes
#7
parent
2a698fd5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
taas_client/cli.py
+5
-0
5 additions, 0 deletions
taas_client/cli.py
tests/test_cli.py
+16
-4
16 additions, 4 deletions
tests/test_cli.py
with
21 additions
and
4 deletions
taas_client/cli.py
+
5
−
0
View file @
64cfc42b
import
datetime
import
sys
import
time
import
zipfile
from
pathlib
import
Path
import
httpx
...
...
@@ -86,6 +87,10 @@ def check_project_file(path: Path, force: bool) -> None:
else
:
console
.
print
(
"
Continuing submission since --force has been given.
\n
"
)
if
not
zipfile
.
is_zipfile
(
path
):
console
.
print
(
f
"
[red]
{
path
.
name
}
is not a valid .zip file.[/]
"
)
raise
typer
.
Exit
(
1
)
@app.command
()
def
upload_file
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_cli.py
+
16
−
4
View file @
64cfc42b
...
...
@@ -4,6 +4,7 @@ import os
import
io
import
pathlib
import
datetime
import
zipfile
import
rich.console
import
rich.panel
...
...
@@ -260,7 +261,8 @@ def test_project(
time_machine
.
move_to
(
FROZEN_TIME
)
project_path
=
tmp_path
/
"
project.zip
"
project_path
.
touch
()
with
zipfile
.
ZipFile
(
project_path
,
"
w
"
):
pass
result
=
runner
.
run
(
"
--project
"
,
str
(
project_path
))
...
...
@@ -298,9 +300,8 @@ def test_project_size_limit(
file_size_mb
=
2
if
hard_limit
else
1
project_path
=
tmp_path
/
"
project.zip
"
with
project_path
.
open
(
"
wb
"
)
as
f
:
f
.
seek
(
file_size_mb
*
1024
*
1024
)
f
.
write
(
b
"
\x00
"
)
with
zipfile
.
ZipFile
(
project_path
,
"
w
"
)
as
zf
:
zf
.
writestr
(
"
data.bin
"
,
"
\x00
"
*
file_size_mb
*
1024
*
1024
)
flags
=
[
"
--project
"
]
if
force
:
...
...
@@ -311,6 +312,17 @@ def test_project_size_limit(
assert
result
.
stdout
==
golden_special
.
out
[
"
output
"
]
def
test_project_invalid_zip
(
runner
:
Runner
,
tmp_path
:
pathlib
.
Path
,
):
project_path
=
tmp_path
/
"
project.zip
"
project_path
.
touch
()
result
=
runner
.
run
(
"
--project
"
,
str
(
project_path
))
assert
result
.
exit_code
==
1
assert
result
.
stdout
==
"
project.zip is not a valid .zip file.
\n
"
def
test_version
(
runner
:
Runner
,
httpx_mock
:
HTTPXMock
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment