mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 10:46:23 +00:00
Change HTTP Authorization realm to "Serval RESTful API"
Was "Serval Rhizome", which is not accurate
This commit is contained in:
parent
11e9d38299
commit
067340bbba
8
httpd.c
8
httpd.c
@ -328,7 +328,7 @@ static int is_from_loopback(const struct http_request *r)
|
|||||||
/* Return 1 if the given authorization credentials are acceptable.
|
/* Return 1 if the given authorization credentials are acceptable.
|
||||||
* Return 0 if not.
|
* Return 0 if not.
|
||||||
*/
|
*/
|
||||||
static int is_authorized(const struct http_client_authorization *auth)
|
static int is_authorized_restful(const struct http_client_authorization *auth)
|
||||||
{
|
{
|
||||||
if (auth->scheme != BASIC)
|
if (auth->scheme != BASIC)
|
||||||
return 0;
|
return 0;
|
||||||
@ -342,13 +342,13 @@ static int is_authorized(const struct http_client_authorization *auth)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int authorize(struct http_request *r)
|
int authorize_restful(struct http_request *r)
|
||||||
{
|
{
|
||||||
if (!is_from_loopback(r))
|
if (!is_from_loopback(r))
|
||||||
return 403;
|
return 403;
|
||||||
if (!is_authorized(&r->request_header.authorization)) {
|
if (!is_authorized_restful(&r->request_header.authorization)) {
|
||||||
r->response.header.www_authenticate.scheme = BASIC;
|
r->response.header.www_authenticate.scheme = BASIC;
|
||||||
r->response.header.www_authenticate.realm = "Serval Rhizome";
|
r->response.header.www_authenticate.realm = "Serval RESTful API";
|
||||||
return 401;
|
return 401;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
2
httpd.h
2
httpd.h
@ -191,7 +191,7 @@ int httpd_server_start(uint16_t port_low, uint16_t port_high);
|
|||||||
typedef int HTTP_HANDLER(httpd_request *r, const char *remainder);
|
typedef int HTTP_HANDLER(httpd_request *r, const char *remainder);
|
||||||
|
|
||||||
int is_http_header_complete(const char *buf, size_t len, size_t read_since_last_call);
|
int is_http_header_complete(const char *buf, size_t len, size_t read_since_last_call);
|
||||||
int authorize(struct http_request *r);
|
int authorize_restful(struct http_request *r);
|
||||||
int http_response_content_type(httpd_request *r, const char *what, const struct mime_content_type *ct);
|
int http_response_content_type(httpd_request *r, const char *what, const struct mime_content_type *ct);
|
||||||
int http_response_content_disposition(httpd_request *r, const char *what, const char *type);
|
int http_response_content_disposition(httpd_request *r, const char *what, const char *type);
|
||||||
int http_response_form_part(httpd_request *r, const char *what, const char *partname, const char *text, size_t textlen);
|
int http_response_form_part(httpd_request *r, const char *what, const char *partname, const char *text, size_t textlen);
|
||||||
|
@ -185,7 +185,7 @@ int restful_meshms_(httpd_request *r, const char *remainder)
|
|||||||
http_request_simple_response(&r->http, 400, "Bad content length");
|
http_request_simple_response(&r->http, 400, "Bad content length");
|
||||||
return 400;
|
return 400;
|
||||||
}
|
}
|
||||||
int ret = authorize(&r->http);
|
int ret = authorize_restful(&r->http);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
ret = handler(r, remainder);
|
ret = handler(r, remainder);
|
||||||
|
@ -74,7 +74,7 @@ int restful_rhizome_bundlelist_json(httpd_request *r, const char *remainder)
|
|||||||
return 404;
|
return 404;
|
||||||
if (r->http.verb != HTTP_VERB_GET)
|
if (r->http.verb != HTTP_VERB_GET)
|
||||||
return 405;
|
return 405;
|
||||||
int ret = authorize(&r->http);
|
int ret = authorize_restful(&r->http);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
r->u.rhlist.phase = LIST_HEADER;
|
r->u.rhlist.phase = LIST_HEADER;
|
||||||
@ -108,7 +108,7 @@ int restful_rhizome_newsince(httpd_request *r, const char *remainder)
|
|||||||
return 404;
|
return 404;
|
||||||
if (r->http.verb != HTTP_VERB_GET)
|
if (r->http.verb != HTTP_VERB_GET)
|
||||||
return 405;
|
return 405;
|
||||||
int ret = authorize(&r->http);
|
int ret = authorize_restful(&r->http);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
r->u.rhlist.phase = LIST_HEADER;
|
r->u.rhlist.phase = LIST_HEADER;
|
||||||
@ -248,7 +248,7 @@ int restful_rhizome_insert(httpd_request *r, const char *remainder)
|
|||||||
return 403;
|
return 403;
|
||||||
if (r->http.verb != HTTP_VERB_POST)
|
if (r->http.verb != HTTP_VERB_POST)
|
||||||
return 405;
|
return 405;
|
||||||
int ret = authorize(&r->http);
|
int ret = authorize_restful(&r->http);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
// Parse the request body as multipart/form-data.
|
// Parse the request body as multipart/form-data.
|
||||||
@ -589,7 +589,7 @@ int restful_rhizome_(httpd_request *r, const char *remainder)
|
|||||||
return 404;
|
return 404;
|
||||||
if (r->http.verb != HTTP_VERB_GET)
|
if (r->http.verb != HTTP_VERB_GET)
|
||||||
return 405;
|
return 405;
|
||||||
int ret = authorize(&r->http);
|
int ret = authorize_restful(&r->http);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
if ((r->manifest = rhizome_new_manifest()) == NULL)
|
if ((r->manifest = rhizome_new_manifest()) == NULL)
|
||||||
|
@ -81,7 +81,7 @@ test_AuthBasicMissing() {
|
|||||||
--dump-header http.headers \
|
--dump-header http.headers \
|
||||||
"http://$addr_localhost:$PORTA/restful/meshms/$SIDA/conversationlist.json"
|
"http://$addr_localhost:$PORTA/restful/meshms/$SIDA/conversationlist.json"
|
||||||
assertStdoutIs '401'
|
assertStdoutIs '401'
|
||||||
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval Rhizome\"$CR\$"
|
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
||||||
assertJq http.output 'contains({"http_status_code": 401})'
|
assertJq http.output 'contains({"http_status_code": 401})'
|
||||||
assertJq http.output 'contains({"http_status_message": ""})'
|
assertJq http.output 'contains({"http_status_message": ""})'
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ test_AuthBasicWrong() {
|
|||||||
--basic --user fred:nurks \
|
--basic --user fred:nurks \
|
||||||
"http://$addr_localhost:$PORTA/restful/meshms/$SIDA/conversationlist.json"
|
"http://$addr_localhost:$PORTA/restful/meshms/$SIDA/conversationlist.json"
|
||||||
assertStdoutIs '401'
|
assertStdoutIs '401'
|
||||||
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval Rhizome\"$CR\$"
|
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
||||||
assertJq http.output 'contains({"http_status_code": 401})'
|
assertJq http.output 'contains({"http_status_code": 401})'
|
||||||
assertJq http.output 'contains({"http_status_message": ""})'
|
assertJq http.output 'contains({"http_status_message": ""})'
|
||||||
executeOk curl \
|
executeOk curl \
|
||||||
|
@ -81,7 +81,7 @@ test_AuthBasicMissing() {
|
|||||||
--dump-header http.headers \
|
--dump-header http.headers \
|
||||||
"http://$addr_localhost:$PORTA/restful/rhizome/bundlelist.json"
|
"http://$addr_localhost:$PORTA/restful/rhizome/bundlelist.json"
|
||||||
assertStdoutIs '401'
|
assertStdoutIs '401'
|
||||||
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval Rhizome\"$CR\$"
|
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
||||||
assertJq http.output 'contains({"http_status_code": 401})'
|
assertJq http.output 'contains({"http_status_code": 401})'
|
||||||
assertJq http.output 'contains({"http_status_message": ""})'
|
assertJq http.output 'contains({"http_status_message": ""})'
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ test_AuthBasicWrong() {
|
|||||||
--basic --user fred:nurks \
|
--basic --user fred:nurks \
|
||||||
"http://$addr_localhost:$PORTA/restful/rhizome/bundlelist.json"
|
"http://$addr_localhost:$PORTA/restful/rhizome/bundlelist.json"
|
||||||
assertStdoutIs '401'
|
assertStdoutIs '401'
|
||||||
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval Rhizome\"$CR\$"
|
assertGrep http.headers "^WWW-Authenticate: Basic realm=\"Serval RESTful API\"$CR\$"
|
||||||
assertJq http.output 'contains({"http_status_code": 401})'
|
assertJq http.output 'contains({"http_status_code": 401})'
|
||||||
assertJq http.output 'contains({"http_status_message": ""})'
|
assertJq http.output 'contains({"http_status_message": ""})'
|
||||||
executeOk curl \
|
executeOk curl \
|
||||||
|
Loading…
Reference in New Issue
Block a user