From: Michael Tremer Date: Tue, 21 Sep 2021 13:45:26 +0000 (+0000) Subject: downloader: Add tests that check digests X-Git-Tag: 0.9.28~954 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b4c1b65108e4d3d01b8086bea441adb0edf6d93;p=pakfire.git downloader: Add tests that check digests Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/downloader.c b/tests/libpakfire/downloader.c index 9d2730c04..ee58df0f5 100644 --- a/tests/libpakfire/downloader.c +++ b/tests/libpakfire/downloader.c @@ -119,6 +119,16 @@ FAIL: #ifdef ENABLE_ONLINE_TESTS +static const unsigned char expected_digest[] = { + 0xb7, 0x9b, 0xd6, 0xd2, 0x6a, 0x24, 0xe8, 0xeb, 0x46, 0x09, 0x26, 0x55, 0x70, 0x95, + 0x2f, 0xf5, 0xd2, 0xfc, 0xd0, 0x8e, 0x14, 0x0d, 0x68, 0x36, 0x87, 0x70, 0xa8, 0x86, + 0x46, 0xa9, 0x4e, 0xa7 +}; + +static const unsigned char incorrect_digest[] = { + 0x01, 0x02, 0x03, 0x04, +}; + static int test_retrieve_online(const struct test* t) { struct pakfire_downloader* d = NULL; int r = EXIT_FAILURE; @@ -143,6 +153,54 @@ FAIL: return r; } +static int test_retrieve_online_with_digest(const struct test* t) { + struct pakfire_downloader* d = NULL; + int r = EXIT_FAILURE; + + // Create downloader + ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire)); + + // Retrieve a file + ASSERT_SUCCESS( + pakfire_downloader_retrieve(d, NULL, NULL, NULL, + "https://mirror1.ipfire.org/releases/pakfire/pakfire-0.9.27.tar.gz", + DOWNLOAD_PATH, PAKFIRE_DIGEST_SHA256, expected_digest, sizeof(expected_digest), 0) + ); + + // Everything passed + r = EXIT_SUCCESS; + +FAIL: + if (d) + pakfire_downloader_unref(d); + + return r; +} + +static int test_retrieve_online_with_incorrect_digest(const struct test* t) { + struct pakfire_downloader* d = NULL; + int r = EXIT_FAILURE; + + // Create downloader + ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire)); + + // Retrieve a file + ASSERT_FAILURE( + pakfire_downloader_retrieve(d, NULL, NULL, NULL, + "https://mirror1.ipfire.org/releases/pakfire/pakfire-0.9.27.tar.gz", + DOWNLOAD_PATH, PAKFIRE_DIGEST_SHA256, incorrect_digest, sizeof(incorrect_digest), 0) + ); + + // Everything passed + r = EXIT_SUCCESS; + +FAIL: + if (d) + pakfire_downloader_unref(d); + + return r; +} + #endif /* ENABLE_ONLINE_TESTS */ int main(int argc, char** argv) { @@ -152,6 +210,8 @@ int main(int argc, char** argv) { #ifdef ENABLE_ONLINE_TESTS testsuite_add_test(test_retrieve_online); + testsuite_add_test(test_retrieve_online_with_digest); + testsuite_add_test(test_retrieve_online_with_incorrect_digest); #endif /* ENABLE_ONLINE_TESTS */ return testsuite_run();