diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.bp | 7 | ||||
-rw-r--r-- | tests/component/install_test.cpp | 4 | ||||
-rw-r--r-- | tests/component/verifier_test.cpp | 15 | ||||
-rw-r--r-- | tests/testdata/otasigned_4096bits.zip | bin | 0 -> 4055 bytes | |||
-rw-r--r-- | tests/testdata/testkey_4096bits.x509.pem | 35 | ||||
-rw-r--r-- | tests/unit/asn1_decoder_test.cpp | 2 | ||||
-rw-r--r-- | tests/unit/package_test.cpp | 2 | ||||
-rw-r--r-- | tests/unit/sysutil_test.cpp | 61 |
8 files changed, 116 insertions, 10 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index ef5919eb5..09ef716d6 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -76,9 +76,9 @@ libapplypatch_static_libs = [ librecovery_static_libs = [ "librecovery", "librecovery_fastboot", + "libinstall", + "librecovery_ui", "libminui", - "libpackage", - "libverifier", "libotautil", "libhealthhalutils", @@ -116,10 +116,9 @@ cc_test { ], static_libs: libapplypatch_static_libs + [ + "libinstall", "librecovery_ui", "libminui", - "libpackage", - "libverifier", "libotautil", "libupdater", "libgtest_prod", diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp index 969805b42..385132939 100644 --- a/tests/component/install_test.cpp +++ b/tests/component/install_test.cpp @@ -32,9 +32,9 @@ #include <ziparchive/zip_archive.h> #include <ziparchive/zip_writer.h> -#include "install.h" +#include "install/install.h" #include "otautil/paths.h" -#include "private/install.h" +#include "private/setup_commands.h" static void BuildZipArchive(const std::map<std::string, std::string>& file_map, int fd, int compression_type) { diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp index c904cd038..ded23c52f 100644 --- a/tests/component/verifier_test.cpp +++ b/tests/component/verifier_test.cpp @@ -35,9 +35,9 @@ #include <ziparchive/zip_writer.h> #include "common/test_constants.h" +#include "install/package.h" +#include "install/verifier.h" #include "otautil/sysutil.h" -#include "package.h" -#include "verifier.h" using namespace std::string_literals; @@ -158,6 +158,17 @@ TEST(VerifierTest, LoadCertificateFromBuffer_sha256_ec256bits) { VerifyPackageWithSingleCertificate("otasigned_v5.zip", std::move(cert)); } +TEST(VerifierTest, LoadCertificateFromBuffer_sha256_rsa4096_bits) { + Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); + LoadKeyFromFile(from_testdata_base("testkey_4096bits.x509.pem"), &cert); + + ASSERT_EQ(SHA256_DIGEST_LENGTH, cert.hash_len); + ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type); + ASSERT_EQ(nullptr, cert.ec); + + VerifyPackageWithSingleCertificate("otasigned_4096bits.zip", std::move(cert)); +} + TEST(VerifierTest, LoadCertificateFromBuffer_check_rsa_keys) { std::unique_ptr<RSA, RSADeleter> rsa(RSA_new()); std::unique_ptr<BIGNUM, decltype(&BN_free)> exponent(BN_new(), BN_free); diff --git a/tests/testdata/otasigned_4096bits.zip b/tests/testdata/otasigned_4096bits.zip Binary files differnew file mode 100644 index 000000000..5016dfc9a --- /dev/null +++ b/tests/testdata/otasigned_4096bits.zip diff --git a/tests/testdata/testkey_4096bits.x509.pem b/tests/testdata/testkey_4096bits.x509.pem new file mode 100644 index 000000000..cba30d61b --- /dev/null +++ b/tests/testdata/testkey_4096bits.x509.pem @@ -0,0 +1,35 @@ +-----BEGIN CERTIFICATE----- +MIIGADCCA+igAwIBAgIJAJiRMVvanGUaMA0GCSqGSIb3DQEBCwUAMIGUMQswCQYD +VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g +VmlldzEQMA4GA1UECgwHQW5kcm9pZDEQMA4GA1UECwwHQW5kcm9pZDEQMA4GA1UE +AwwHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAe +Fw0xODEwMzAxMjEzNTFaFw00NjAzMTcxMjEzNTFaMIGUMQswCQYDVQQGEwJVUzET +MBEGA1UECAwKQ2FsaWZv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Wap9zDKmuR0qMUZ6wlualnag0hUG1jZHQP +t63KO6LmNNMSuXRX60Zcq6WWzgLOyoT4HqHZZ47Jamfb4XQQcnWMMW0tJ3pDtTkz +dZILBInHJO8QPYI8Du6XWsDLSvMajq6ueBtO3NdcgsNL7eiHf3WoOtajLZxFM94Z +MESkUQOIsqHolYeTMHLTsuGkX1CK2Zw3Xn18bUSTYwZCHa6mYH00ItUBfetGCnWh +Y7bth/R15Cc+hocSB7ZsOa/R5kDyDdFDIKrnV5nH5Yd7CryrYC6Ac5UarYrxSJTq +eKPwqUlJB/tJW/lvdLt8YaURbFGzf/ZqU12zZRafYjmMjcQvfpzMoDSnbvHTA9IR +ZGO7dwhwykoSaL4/8LWde49xQUq6F2pQBRmEr+7mTzml1MaM5cWEk5emkCMXgLog +k+c56CAk1EdM1teWik7wR0TIqkkYyYJHTSg61GkXUIXrZJ6iYx2ejDg1+QTPm9rU +Yr7nP52gVkQuUAX1+xB6wKLSDizQJw8SNiUGXl5+2vwV6+0BI3/CXlQ8I/nRPBC1 +oqOIkRSbE+IF7DP9QvYuNG/3bZZQ8LUVeHxqI5Mq8K2VIJZd95AIwPNMH34SaDGz +9xjG28Fq4ZkuDP0pCsHM9d2XEwK5PEVS18WW5fJ/QcJKMno4IPTB70ZBBjVzv6Y+ +MYjOrw== +-----END CERTIFICATE----- diff --git a/tests/unit/asn1_decoder_test.cpp b/tests/unit/asn1_decoder_test.cpp index b334a655b..d94dd4353 100644 --- a/tests/unit/asn1_decoder_test.cpp +++ b/tests/unit/asn1_decoder_test.cpp @@ -20,7 +20,7 @@ #include <gtest/gtest.h> -#include "asn1_decoder.h" +#include "private/asn1_decoder.h" TEST(Asn1DecoderTest, Empty_Failure) { uint8_t empty[] = {}; diff --git a/tests/unit/package_test.cpp b/tests/unit/package_test.cpp index fa492d38b..a735a699e 100644 --- a/tests/unit/package_test.cpp +++ b/tests/unit/package_test.cpp @@ -26,7 +26,7 @@ #include <ziparchive/zip_writer.h> #include "common/test_constants.h" -#include "package.h" +#include "install/package.h" class PackageTest : public ::testing::Test { protected: diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp index 77625dbe9..3466e8eec 100644 --- a/tests/unit/sysutil_test.cpp +++ b/tests/unit/sysutil_test.cpp @@ -17,8 +17,10 @@ #include <string> #include <android-base/file.h> +#include <android-base/strings.h> #include <gtest/gtest.h> +#include "otautil/rangeset.h" #include "otautil/sysutil.h" TEST(SysUtilTest, InvalidArgs) { @@ -28,6 +30,65 @@ TEST(SysUtilTest, InvalidArgs) { ASSERT_FALSE(mapping.MapFile("")); } +TEST(SysUtilTest, ParseBlockMapFile_smoke) { + std::vector<std::string> content = { + "/dev/abc", "49652 4096", "3", "1000 1008", "2100 2102", "30 33", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_EQ("/dev/abc", block_map_data.path()); + ASSERT_EQ(49652, block_map_data.file_size()); + ASSERT_EQ(4096, block_map_data.block_size()); + ASSERT_EQ(RangeSet(std::vector<Range>{ + { 1000, 1008 }, + { 2100, 2102 }, + { 30, 33 }, + }), + block_map_data.block_ranges()); +} + +TEST(SysUtilTest, ParseBlockMapFile_invalid_line_count) { + std::vector<std::string> content = { + "/dev/abc", "49652 4096", "2", "1000 1008", "2100 2102", "30 33", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data1 = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(block_map_data1); +} + +TEST(SysUtilTest, ParseBlockMapFile_invalid_size) { + std::vector<std::string> content = { + "/dev/abc", + "42949672950 4294967295", + "1", + "0 9", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_EQ("/dev/abc", block_map_data.path()); + ASSERT_EQ(42949672950, block_map_data.file_size()); + ASSERT_EQ(4294967295, block_map_data.block_size()); + + content[1] = "42949672950 4294967296"; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + auto large_block_size = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(large_block_size); + + content[1] = "4294967296 1"; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + auto too_many_blocks = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(too_many_blocks); +} + TEST(SysUtilTest, MapFileRegularFile) { TemporaryFile temp_file1; std::string content = "abc"; |