Browse Source

[http] fix query detection, addresshelper processing, update tests

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1881/head
R4SAS 2 years ago
parent
commit
77142e59ee
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 2
      libi2pd/HTTP.h
  2. 28
      libi2pd_client/HTTPProxy.cpp
  3. 34
      tests/Makefile
  4. 9
      tests/test-http-url.cpp

2
libi2pd/HTTP.h

@ -37,7 +37,7 @@ namespace http @@ -37,7 +37,7 @@ namespace http
std::string query;
std::string frag;
URL(): schema(""), user(""), pass(""), host(""), port(0), path(""), query(""), frag("") {};
URL(): schema(""), user(""), pass(""), host(""), port(0), path(""), hasquery(false), query(""), frag("") {};
/**
* @brief Tries to parse url from string

28
libi2pd_client/HTTPProxy.cpp

@ -238,9 +238,33 @@ namespace proxy { @@ -238,9 +238,33 @@ namespace proxy {
std::string value = params["i2paddresshelper"];
len += value.length();
b64 = i2p::http::UrlDecode(value);
// if we need update exists, request formed with update param
if (params["update"] == "true") { len += std::strlen("&update=true"); confirm = true; }
if (pos != 0 && url.query[pos-1] == '&') { pos--; len++; } // if helper is not only one query option
if (params["update"] == "true")
{
len += std::strlen("&update=true");
confirm = true;
}
// if helper is not only one query option and it placed after user's query
if (pos != 0 && url.query[pos-1] == '&')
{
pos--;
len++;
}
// if helper is not only one query option and it placed before user's query
else if (pos == 0 && url.query.length () > len && url.query[len] == '&')
{
// we don't touch the '?' but remove the trailing '&'
len++;
}
else
{
// there is no more query options, resetting hasquery flag
url.hasquery = false;
}
// reset hasquery flag and remove addresshelper from URL
url.query.replace(pos, len, "");
return true;
}

34
tests/Makefile

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
SYS := $(shell $(CXX) -dumpmachine)
CXXFLAGS += -Wall -Wno-unused-parameter -Wextra -pedantic -O0 -g -std=c++11 -D_GLIBCXX_USE_NANOSLEEP=1 -DOPENSSL_SUPPRESS_DEPRECATED -pthread -Wl,--unresolved-symbols=ignore-in-object-files
INCFLAGS += -I../libi2pd
@ -7,41 +9,51 @@ TESTS = \ @@ -7,41 +9,51 @@ TESTS = \
test-http-merge_chunked test-http-req test-http-res test-http-url test-http-url_decode \
test-gost test-gost-sig test-base-64 test-x25519 test-aeadchacha20poly1305 test-blinding test-elligator
ifneq (, $(findstring mingw, $(SYS))$(findstring windows-gnu, $(SYS))$(findstring cygwin, $(SYS)))
CXXFLAGS += -DWIN32_LEAN_AND_MEAN
LDFLAGS += -mwindows -static
BOOST_SUFFIX = -mt
NEEDED_LDLIBS = -lwsock32 -lws2_32 -lgdi32 -liphlpapi -lole32
endif
LDLIBS = \
-lcrypto \
-lboost_filesystem$(BOOST_SUFFIX) \
-lboost_program_options$(BOOST_SUFFIX) \
-lssl \
-lboost_filesystem \
-lboost_program_options \
-lcrypto \
-lz \
$(NEEDED_LDLIBS) \
-lpthread
all: $(TESTS) run
$(LIBI2PD):
@echo "Building libi2pd.a ..." && cd .. && $(MAKE) libi2pd.a
test-http-%: test-http-%.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-base-%: test-base-%.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-gost: test-gost.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-gost-sig: test-gost-sig.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-x25519: test-x25519.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-aeadchacha20poly1305: test-aeadchacha20poly1305.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-blinding: test-blinding.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test-elligator: test-elligator.cpp $(LIBI2PD)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LDLIBS)
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
run: $(TESTS)
@for TEST in $(TESTS); do echo Running $$TEST; ./$$TEST ; done

9
tests/test-http-url.cpp

@ -15,6 +15,7 @@ int main() { @@ -15,6 +15,7 @@ int main() {
assert(url->host == "127.0.0.1");
assert(url->port == 7070);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "12345");
assert(url->to_string() == "https://127.0.0.1:7070/asdasd?12345");
delete url;
@ -27,6 +28,7 @@ int main() { @@ -27,6 +28,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 8080);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "123456");
delete url;
@ -38,6 +40,7 @@ int main() { @@ -38,6 +40,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 0);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "name=value");
delete url;
@ -49,6 +52,7 @@ int main() { @@ -49,6 +52,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 0);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "name=value1&name=value2");
delete url;
@ -60,6 +64,7 @@ int main() { @@ -60,6 +64,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 0);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "name1=value1&name2&name3=value2");
assert(url->parse_query(params));
assert(params.size() == 3);
@ -79,6 +84,7 @@ int main() { @@ -79,6 +84,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 800);
assert(url->path == "/asdasd");
assert(url->hasquery == true);
assert(url->query == "");
delete url;
@ -90,6 +96,7 @@ int main() { @@ -90,6 +96,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 17);
assert(url->path == "");
assert(url->hasquery == false);
assert(url->query == "");
delete url;
@ -101,6 +108,7 @@ int main() { @@ -101,6 +108,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 0);
assert(url->path == "");
assert(url->hasquery == false);
assert(url->query == "");
delete url;
@ -112,6 +120,7 @@ int main() { @@ -112,6 +120,7 @@ int main() {
assert(url->host == "site.com");
assert(url->port == 84);
assert(url->path == "/asdasd/@17");
assert(url->hasquery == false);
assert(url->query == "");
assert(url->frag == "frag");
delete url;

Loading…
Cancel
Save