|
| 1 | +// The first "test" is of course whether the header compiles standalone |
| 2 | +#include "nmos/admin_ui.h" |
| 3 | + |
| 4 | +#include "bst/filesystem.h" |
| 5 | +#include "bst/test/test.h" |
| 6 | +#include "cpprest/basic_utils.h" // for utility::us2s, utility::s2us |
| 7 | +#include "nmos/log_gate.h" |
| 8 | + |
| 9 | +namespace |
| 10 | +{ |
| 11 | + utility::string_t get_location(web::http::experimental::listener::api_router& router, const utility::string_t& request_uri) |
| 12 | + { |
| 13 | + web::http::http_request req(web::http::methods::GET); |
| 14 | + req.set_request_uri(web::uri(request_uri)); |
| 15 | + web::http::http_response res; |
| 16 | + router(req, res, U(""), {}).wait(); |
| 17 | + BST_REQUIRE_EQUAL(web::http::status_codes::TemporaryRedirect, res.status_code()); |
| 18 | + return res.headers()[web::http::header_names::location]; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +//////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | +BST_TEST_CASE(testAdminUiRedirectKeepsQuery) |
| 24 | +{ |
| 25 | + using utility::us2s; |
| 26 | + |
| 27 | + std::ostream null_ostream(nullptr); |
| 28 | + nmos::experimental::log_model log_model; |
| 29 | + nmos::experimental::log_gate gate(null_ostream, null_ostream, log_model); |
| 30 | + |
| 31 | + const auto filesystem_root = bst::filesystem::temp_directory_path() / "nmos-cpp-admin-ui-test"; |
| 32 | + bst::filesystem::create_directory(filesystem_root); |
| 33 | + bst::filesystem::create_directory(filesystem_root / "sdpoker"); |
| 34 | + |
| 35 | + auto admin_ui = nmos::experimental::make_admin_ui(utility::s2us(filesystem_root.string()), gate); |
| 36 | + |
| 37 | + BST_CHECK_STRING_EQUAL("/admin/", us2s(get_location(admin_ui, U("http://host:123/admin")))); |
| 38 | + BST_CHECK_STRING_EQUAL("/admin/?foo=bar", us2s(get_location(admin_ui, U("http://host:123/admin?foo=bar")))); |
| 39 | + BST_CHECK_STRING_EQUAL("/admin/sdpoker/", us2s(get_location(admin_ui, U("http://host:123/admin/sdpoker")))); |
| 40 | + BST_CHECK_STRING_EQUAL("/admin/sdpoker/?url=http%3A%2F%2Fnode%2Fsdp", us2s(get_location(admin_ui, U("http://host:123/admin/sdpoker?url=http%3A%2F%2Fnode%2Fsdp")))); |
| 41 | + |
| 42 | + bst::filesystem::remove_all(filesystem_root); |
| 43 | +} |
0 commit comments