Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
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
zhifan huang
re6stnet
Commits
179ff86e
Commit
179ff86e
authored
May 06, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update http handler
parent
45b09b5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
re6st/registry.py
re6st/registry.py
+11
-3
re6st/tests/test_unit/test_registry.py
re6st/tests/test_unit/test_registry.py
+7
-7
No files found.
re6st/registry.py
View file @
179ff86e
...
...
@@ -176,12 +176,16 @@ class RegistryServer(object):
def
recv
(
self
,
code
):
try
:
prefix
,
msg
=
self
.
sock
.
recv
(
1
<<
16
).
split
(
'
\
0
'
,
1
)
prefix
,
msg
=
self
.
sock
.
recv
(
1
<<
16
).
split
(
b
'
\
0
'
,
1
)
int
(
prefix
,
2
)
except
ValueError
:
pass
else
:
# let recv return to str
prefix
=
prefix
.
decode
()
msg
=
msg
.
decode
()
if
msg
and
ord
(
msg
[
0
])
==
code
:
return
prefix
,
msg
[
1
:]
return
None
,
None
...
...
@@ -253,7 +257,8 @@ class RegistryServer(object):
# (IOW, do the contrary of newPrefix)
self
.
timeout
=
not_after
and
not_after
+
GRACE_PERIOD
def
handle_request
(
self
,
request
,
method
,
kw
):
def
handle_request
(
self
,
request
:
BaseHTTPRequestHandler
,
method
:
str
,
kw
:
dict
[
str
:
str
]):
m
=
getattr
(
self
,
method
)
if
hasattr
(
m
,
'_private'
):
authorized_origin
=
self
.
config
.
authorized_origin
...
...
@@ -267,7 +272,7 @@ class RegistryServer(object):
with
self
.
lock
:
session
=
self
.
sessions
[
key
]
for
key
,
protocol
in
session
:
if
h
==
hmac
.
HMAC
(
key
,
request
.
path
,
hashlib
.
sha1
).
digest
():
if
h
==
hmac
.
HMAC
(
key
,
request
.
path
.
encode
()
,
hashlib
.
sha1
).
digest
():
break
else
:
raise
Exception
(
"Wrong HMAC"
)
...
...
@@ -284,6 +289,9 @@ class RegistryServer(object):
request
.
headers
.
get
(
"user-agent"
))
try
:
result
=
m
(
**
kw
)
# request.wfile.write need bytes
if
isinstance
(
result
,
str
):
result
=
result
.
encode
()
except
HTTPError
as
e
:
return
request
.
send_error
(
*
e
.
args
)
except
:
...
...
re6st/tests/test_unit/test_registry.py
View file @
179ff86e
...
...
@@ -93,11 +93,11 @@ class TestRegistryServer(unittest.TestCase):
back_sock
=
self
.
server
.
sock
sock
=
self
.
server
.
sock
=
Mock
()
sock
.
recv
.
side_effect
=
[
"0001001001001a_msg"
,
"0001001001002
\
000
1dqdq"
,
"0001001001001
\
000
a_msg"
,
"0001001001001
\
000
\
4
a_msg"
,
"0000000000000
\
0
"
# ERROR, IndexError: msg is null
b
"0001001001001a_msg"
,
b
"0001001001002
\
000
1dqdq"
,
b
"0001001001001
\
000
a_msg"
,
b
"0001001001001
\
000
\
4
a_msg"
,
b
"0000000000000
\
0
"
# ERROR, IndexError: msg is null
]
res1
=
self
.
server
.
recv
(
4
)
...
...
@@ -158,9 +158,9 @@ class TestRegistryServer(unittest.TestCase):
key
=
b"this_is_a_key"
self
.
server
.
sessions
[
prefix
]
=
[(
key
,
protocol
)]
request
=
Mock
()
request
.
path
=
b
"/func?a=1&b=2&cn=0000000011111111"
request
.
path
=
"/func?a=1&b=2&cn=0000000011111111"
request
.
headers
=
{
registry
.
HMAC_HEADER
:
base64
.
b64encode
(
hmac
.
HMAC
(
key
,
request
.
path
,
hashlib
.
sha1
).
digest
())}
hmac
.
HMAC
(
key
,
request
.
path
.
encode
()
,
hashlib
.
sha1
).
digest
())}
self
.
server
.
handle_request
(
request
,
method
,
params
)
...
...
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