mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 18:56:25 +00:00
Reject rhizome import before sending manifest & payload
This commit is contained in:
parent
8cdd849c3e
commit
87d171cdf7
@ -1165,7 +1165,7 @@ malformed:
|
||||
* Then we need to send a 100 continue response header before parsing the request body
|
||||
*/
|
||||
static int http_request_start_continue(struct http_request *r){
|
||||
const char *msg = "HTTP/1.0 100 Continue\r\n\r\n";
|
||||
const char *msg = "HTTP/1.1 100 Continue\r\n\r\n";
|
||||
static size_t msg_len = 0;
|
||||
if (msg_len == 0)
|
||||
msg_len = strlen(msg);
|
||||
|
@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "str.h"
|
||||
#include "base64.h"
|
||||
#include "strbuf_helpers.h"
|
||||
#include "numeric_str.h"
|
||||
|
||||
DEFINE_FEATURE(http_rest_rhizome);
|
||||
|
||||
@ -449,8 +450,33 @@ static int restful_rhizome_insert(httpd_request *r, const char *remainder)
|
||||
|
||||
static int restful_rhizome_import(httpd_request *r, const char *remainder)
|
||||
{
|
||||
int ret;
|
||||
r->u.insert.importing = 1;
|
||||
return restful_rhizome_insert(r, remainder);
|
||||
if ((ret = restful_rhizome_insert(r, remainder))!=1)
|
||||
return ret;
|
||||
|
||||
const char *s_id = http_request_get_query_param(&r->http, "id");
|
||||
const char *s_version = http_request_get_query_param(&r->http, "version");
|
||||
|
||||
// if we can reject the request now, the client won't have to send us the full manifest and payload
|
||||
if (s_id && s_version){
|
||||
rhizome_bid_t bid;
|
||||
uint64_t version;
|
||||
if (str_to_rhizome_bid_t(&bid, s_id) != -1
|
||||
&& str_to_uint64(s_version, 10, &version, NULL) == 1){
|
||||
|
||||
r->bundle_result.status = rhizome_is_interesting(&bid, version);
|
||||
switch (r->bundle_result.status){
|
||||
case RHIZOME_BUNDLE_STATUS_NEW:
|
||||
case RHIZOME_BUNDLE_STATUS_BUSY:
|
||||
break;
|
||||
default:
|
||||
return http_request_rhizome_response(r, 0, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int restful_rhizome_append(httpd_request *r, const char *remainder)
|
||||
|
@ -1252,9 +1252,10 @@ test_RhizomeImport() {
|
||||
--basic --user harry:potter \
|
||||
--form "manifest=@file1.manifest;type=rhizome/manifest;format=\"text+binarysig\"" \
|
||||
--form "payload=@file1" \
|
||||
"http://$addr_localhost:$PORTA/restful/rhizome/import"
|
||||
"http://$addr_localhost:$PORTA/restful/rhizome/import?id=${BID[1]}&version=${VERSION[1]}"
|
||||
tfw_cat http.header http.body
|
||||
assertStdoutIs 201
|
||||
assertGrep http.header '100 Continue'
|
||||
assertJq http.body 'contains({"http_status_code": 201})'
|
||||
assertJq http.body 'contains({"http_status_message": "Created"})'
|
||||
execute curl \
|
||||
@ -1264,9 +1265,10 @@ test_RhizomeImport() {
|
||||
--basic --user harry:potter \
|
||||
--form "manifest=@file1.manifest;type=rhizome/manifest;format=\"text+binarysig\"" \
|
||||
--form "payload=@file1" \
|
||||
"http://$addr_localhost:$PORTA/restful/rhizome/import"
|
||||
"http://$addr_localhost:$PORTA/restful/rhizome/import?id=${BID[1]}&version=${VERSION[1]}"
|
||||
tfw_cat http.header http.body
|
||||
assertStdoutIs 200
|
||||
assertGrep --matches=0 http.header '100 Continue'
|
||||
assertJq http.body 'contains({"http_status_code": 200})'
|
||||
assertJq http.body 'contains({"http_status_message": "Bundle already in store"})'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user