Преглед изворни кода

[Test] Add unit tests

tags/3.8.2
Vsevolod Stakhov пре 3 месеци
родитељ
комит
f8210a5ba9
No account linked to committer's email address
3 измењених фајлова са 43 додато и 4 уклоњено
  1. 10
    0
      src/libserver/http/http_message.c
  2. 5
    3
      src/libserver/http/http_message.h
  3. 28
    1
      test/rspamd_cxx_unit_utils.hxx

+ 10
- 0
src/libserver/http/http_message.c Прегледај датотеку

} }


return msg->port == 80; return msg->port == 80;
}

const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len)
{
if (msg->url) {
*len = msg->url->len;
return msg->url->str;
}

return NULL;
} }

+ 5
- 3
src/libserver/http/http_message.h Прегледај датотеку

/*-
* Copyright 2019 Vsevolod Stakhov
/*
* Copyright 2024 Vsevolod Stakhov
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
*/ */
bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg); bool rspamd_http_message_is_standard_port(struct rspamd_http_message *msg);


const gchar *rspamd_http_message_get_url(struct rspamd_http_message *msg, gsize *len);

#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

+ 28
- 1
test/rspamd_cxx_unit_utils.hxx Прегледај датотеку

/* /*
* Copyright 2023 Vsevolod Stakhov
* Copyright 2024 Vsevolod Stakhov
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
#include "libmime/mime_headers.h" #include "libmime/mime_headers.h"
#include "contrib/libottery/ottery.h" #include "contrib/libottery/ottery.h"
#include "libcryptobox/cryptobox.h" #include "libcryptobox/cryptobox.h"
#include "libserver/http/http_message.h"


#include <vector> #include <vector>
#include <utility> #include <utility>
} }
} }
} }

TEST_CASE("rspamd_http_message_from_url")
{
std::vector<std::pair<std::string, std::string>> cases{
{"http://example.com", "/"},
{"http://example.com/", "/"},
{"http://example.com/lol", "/lol"},
{"http://example.com/lol#keke", "/lol"},
{"http://example.com/lol?omg=huh&oh", "/lol?omg=huh&oh"},
{"http://example.com/lol?omg=huh&oh#", "/lol?omg=huh&oh"},
{"http://example.com/lol?omg=huh&oh#keke", "/lol?omg=huh&oh"},
{"http://example.com/lol?", "/lol"},
{"http://example.com/lol?#", "/lol"},
};

for (const auto &c: cases) {
SUBCASE(("rspamd_http_message_from_url: " + c.first).c_str())
{
auto *msg = rspamd_http_message_from_url(c.first.c_str());
std::size_t nlen;
auto *path = rspamd_http_message_get_url(msg, &nlen);
CHECK(std::string{path, nlen} == c.second);
rspamd_http_message_unref(msg);
}
}
}
} }


#endif #endif

Loading…
Откажи
Сачувај