Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
0dd6ddb8
Unverified
Commit
0dd6ddb8
authored
Feb 23, 2021
by
acud
Committed by
GitHub
Feb 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api: dont accept two soc's with the same address (#1256)
parent
62c576e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
soc.go
pkg/api/soc.go
+14
-0
soc_test.go
pkg/api/soc_test.go
+26
-0
No files found.
pkg/api/soc.go
View file @
0dd6ddb8
...
...
@@ -103,8 +103,22 @@ func (s *server) socUploadHandler(w http.ResponseWriter, r *http.Request) {
return
}
ctx
:=
r
.
Context
()
has
,
err
:=
s
.
storer
.
Has
(
ctx
,
chunk
.
Address
())
if
err
!=
nil
{
s
.
logger
.
Debugf
(
"soc upload: store has: %v"
,
err
)
s
.
logger
.
Error
(
"soc upload: store has"
)
jsonhttp
.
InternalServerError
(
w
,
"storage error"
)
return
}
if
has
{
s
.
logger
.
Error
(
"soc upload: chunk already exists"
)
jsonhttp
.
Conflict
(
w
,
"chunk already exists"
)
return
}
_
,
err
=
s
.
storer
.
Put
(
ctx
,
requestModePut
(
r
),
chunk
)
if
err
!=
nil
{
s
.
logger
.
Debugf
(
"soc upload: chunk write error: %v"
,
err
)
...
...
pkg/api/soc_test.go
View file @
0dd6ddb8
...
...
@@ -124,6 +124,32 @@ func TestSoc(t *testing.T) {
t
.
Fatal
(
"data retrieved doesnt match uploaded content"
)
}
})
t
.
Run
(
"already exists"
,
func
(
t
*
testing
.
T
)
{
s
,
owner
,
payload
:=
mockSoc
(
t
)
id
:=
make
([]
byte
,
soc
.
IdSize
)
sig
:=
s
.
Signature
()
addr
,
err
:=
s
.
Address
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
jsonhttptest
.
Request
(
t
,
client
,
http
.
MethodPost
,
socResource
(
hex
.
EncodeToString
(
owner
),
hex
.
EncodeToString
(
id
),
hex
.
EncodeToString
(
sig
)),
http
.
StatusCreated
,
jsonhttptest
.
WithRequestBody
(
bytes
.
NewReader
(
payload
)),
jsonhttptest
.
WithExpectedJSONResponse
(
api
.
SocPostResponse
{
Reference
:
addr
,
}),
)
jsonhttptest
.
Request
(
t
,
client
,
http
.
MethodPost
,
socResource
(
hex
.
EncodeToString
(
owner
),
hex
.
EncodeToString
(
id
),
hex
.
EncodeToString
(
sig
)),
http
.
StatusConflict
,
jsonhttptest
.
WithRequestBody
(
bytes
.
NewReader
(
payload
)),
jsonhttptest
.
WithExpectedJSONResponse
(
jsonhttp
.
StatusResponse
{
Message
:
"chunk already exists"
,
Code
:
http
.
StatusConflict
,
}),
)
})
}
// returns a valid, mocked SOC
...
...
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