/* * Copyright(c) 2013 Tim Ruehsen * * This file is part of libmget. * * Libmget is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Libmget is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libmget. If not, see . * * * Testing Mget * * Changelog * 08.07.2013 Tim Ruehsen created * */ #if HAVE_CONFIG_H # include #endif #include // exit() #include "libtest.h" int main(void) { mget_test_url_t urls[]={ { .name = "/urls.txt", .code = "200 Dontcare", .body = "https://localhost:{{sslport}}/page1.html\nhttps://localhost:{{sslport}}/page2.html\n", .headers = { "Content-Type: text/plain", } }, { .name = "/page1.html", .code = "200 Dontcare", .body = "hello1", .headers = { "Content-Type: text/html", } }, { .name = "/page2.html", .code = "200 Dontcare", .body = "hello2", .headers = { "Content-Type: text/html", } } }; // functions won't come back if an error occurs mget_test_start_server( MGET_TEST_RESPONSE_URLS, &urls, countof(urls), 0); // test-i-https with loading CA Certificate mget_test( // MGET_TEST_KEEP_TMPFILES, 1, MGET_TEST_OPTIONS, "--ca-certificate=../" SRCDIR "/certs/x509-ca-cert.pem --no-ocsp -i urls.txt", MGET_TEST_REQUEST_URL, NULL, MGET_TEST_EXPECTED_ERROR_CODE, 0, MGET_TEST_EXISTING_FILES, &(mget_test_file_t []) { { "urls.txt", urls[0].body }, { NULL } }, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { urls[1].name + 1, urls[1].body }, { urls[2].name + 1, urls[2].body }, { NULL } }, 0); // test-i-https with loading CA Certificate and CRL mget_test( // MGET_TEST_KEEP_TMPFILES, 1, MGET_TEST_OPTIONS, "-d --ca-certificate=../" SRCDIR "/certs/x509-ca-cert.pem --crl-file=../" SRCDIR "/certs/x509-server-crl.pem --no-ocsp -i urls.txt", MGET_TEST_REQUEST_URL, NULL, MGET_TEST_EXPECTED_ERROR_CODE, 5, MGET_TEST_EXISTING_FILES, &(mget_test_file_t []) { { "urls.txt", urls[0].body }, { NULL } }, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { NULL } }, 0); // test-i-https ignoring unknown certificate mget_test( // MGET_TEST_KEEP_TMPFILES, 1, MGET_TEST_OPTIONS, "--no-check-certificate -i urls.txt", MGET_TEST_REQUEST_URL, NULL, MGET_TEST_EXPECTED_ERROR_CODE, 0, MGET_TEST_EXISTING_FILES, &(mget_test_file_t []) { { "urls.txt", urls[0].body }, { NULL } }, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { urls[1].name + 1, urls[1].body }, { urls[2].name + 1, urls[2].body }, { NULL } }, 0); // test-i-https ignoring unknown certificate (with CRL) mget_test( // MGET_TEST_KEEP_TMPFILES, 1, MGET_TEST_OPTIONS, "--no-check-certificate --crl-file=../" SRCDIR "/certs/x509-server-crl.pem -i urls.txt", MGET_TEST_REQUEST_URL, NULL, MGET_TEST_EXPECTED_ERROR_CODE, 0, MGET_TEST_EXISTING_FILES, &(mget_test_file_t []) { { "urls.txt", urls[0].body }, { NULL } }, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { urls[1].name + 1, urls[1].body }, { urls[2].name + 1, urls[2].body }, { NULL } }, 0); // test-i-https failing due to unknown certificate mget_test( // MGET_TEST_KEEP_TMPFILES, 1, MGET_TEST_OPTIONS, "--tries=1 -i urls.txt", MGET_TEST_REQUEST_URL, NULL, MGET_TEST_EXPECTED_ERROR_CODE, 5, MGET_TEST_EXISTING_FILES, &(mget_test_file_t []) { { "urls.txt", urls[0].body }, { NULL } }, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { NULL } }, 0); /* // test-i-http (expands to -i https://localhost:{{sslport}}/urls.txt) mget_test( MGET_TEST_OPTIONS, "-i", MGET_TEST_REQUEST_URL, "urls.txt", MGET_TEST_EXPECTED_ERROR_CODE, 0, MGET_TEST_EXPECTED_FILES, &(mget_test_file_t []) { { urls[0].name + 1, urls[0].body }, { urls[1].name + 1, urls[1].body }, { urls[2].name + 1, urls[2].body }, { NULL } }, 0); */ exit(0); }