Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos.libnetworkcache
Commits
848d552e
Commit
848d552e
authored
Sep 02, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cover cases of bad response from shadir.
parent
ec8f2d45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
slapos/libnetworkcachetests.py
slapos/libnetworkcachetests.py
+53
-1
No files found.
slapos/libnetworkcachetests.py
View file @
848d552e
...
...
@@ -581,10 +581,62 @@ class OnlineTest(OnlineMixin, unittest.TestCase):
try
:
nc
.
select
(
key
)
except
slapos
.
libnetworkcache
.
DirectoryNotFound
,
msg
:
# empty content in shadir so usual exception is raised
self
.
assertTrue
(
str
(
msg
).
startswith
(
'It was impossible to parse json '
'response'
))
def
test_select_json_no_in_json_response
(
self
):
key
=
'somekey'
+
str
(
random
.
random
())
urlmd5
=
str
(
random
.
random
())
file_name
=
'my file'
test_data
=
tempfile
.
TemporaryFile
()
test_string
=
str
(
random
.
random
())
test_data
.
write
(
test_string
)
test_data
.
seek
(
0
)
key_file
=
tempfile
.
NamedTemporaryFile
()
key_file
.
write
(
self
.
key
)
key_file
.
flush
()
key_file
.
seek
(
0
)
nc
=
slapos
.
libnetworkcache
.
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
self
.
assertEqual
(
True
,
nc
.
upload
(
self
.
test_data
,
key
,
urlmd5
=
urlmd5
,
file_name
=
file_name
))
f
=
os
.
path
.
join
(
self
.
tree
,
'shadir'
,
key
)
# now remove the entry from shacache
open
(
f
,
'w'
).
write
(
json
.
dumps
([[
'This is not a json.'
,
'signature'
]]))
try
:
nc
.
select
(
key
)
except
slapos
.
libnetworkcache
.
DirectoryNotFound
,
msg
:
self
.
assertTrue
(
str
(
msg
).
startswith
(
'It was impossible to parse '
'json-in-json response'
))
def
test_select_json_in_json_no_dict
(
self
):
key
=
'somekey'
+
str
(
random
.
random
())
urlmd5
=
str
(
random
.
random
())
file_name
=
'my file'
test_data
=
tempfile
.
TemporaryFile
()
test_string
=
str
(
random
.
random
())
test_data
.
write
(
test_string
)
test_data
.
seek
(
0
)
key_file
=
tempfile
.
NamedTemporaryFile
()
key_file
.
write
(
self
.
key
)
key_file
.
flush
()
key_file
.
seek
(
0
)
nc
=
slapos
.
libnetworkcache
.
NetworkcacheClient
(
self
.
shacache
,
self
.
shadir
)
self
.
assertEqual
(
True
,
nc
.
upload
(
self
.
test_data
,
key
,
urlmd5
=
urlmd5
,
file_name
=
file_name
))
f
=
os
.
path
.
join
(
self
.
tree
,
'shadir'
,
key
)
# now remove the entry from shacache
open
(
f
,
'w'
).
write
(
json
.
dumps
([[
json
.
dumps
(
'This is a string'
),
'signature'
]]))
try
:
nc
.
select
(
key
)
except
slapos
.
libnetworkcache
.
DirectoryNotFound
,
msg
:
self
.
assertTrue
(
str
(
msg
).
startswith
(
'It was impossible to fetch sha512 '
'from directory response'
))
def
test_select_signed_content_server_hacked
(
self
):
key
=
'somekey'
+
str
(
random
.
random
())
urlmd5
=
str
(
random
.
random
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment