X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fkdm_cli_test.cc;h=303f2b0d4d470b8d01cc35ef930e7f608f755a8d;hb=0cdb390a035f8bb6d3a17633f791a78cf835143c;hp=2e5e4760c47b506dfec6bdd16916e5dbfec548cc;hpb=a115088ca904a26d100e479a7fde21c9235bf7c9;p=dcpomatic.git diff --git a/test/kdm_cli_test.cc b/test/kdm_cli_test.cc index 2e5e4760c..303f2b0d4 100644 --- a/test/kdm_cli_test.cc +++ b/test/kdm_cli_test.cc @@ -22,6 +22,8 @@ #include "lib/cinema.h" #include "lib/config.h" #include "lib/content_factory.h" +#include "lib/cross.h" +#include "lib/dkdm_wrapper.h" #include "lib/film.h" #include "lib/kdm_cli.h" #include "lib/screen.h" @@ -33,13 +35,14 @@ #include +using std::dynamic_pointer_cast; using std::string; using std::vector; using boost::optional; optional -run(vector const& args, vector& output) +run(vector const& args, vector& output, bool dump_errors = true) { std::vector argv(args.size()); for (auto i = 0U; i < args.size(); ++i) { @@ -47,7 +50,7 @@ run(vector const& args, vector& output) } auto error = kdm_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); }); - if (error) { + if (error && dump_errors) { std::cout << *error << "\n"; } @@ -62,7 +65,7 @@ BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate) "--verbose", "--valid-from", "now", "--valid-duration", "2 weeks", - "--certificate", "test/data/cert.pem", + "--projector-certificate", "test/data/cert.pem", "-S", "my great screen", "-o", "build/test", "test/data/dkdm.xml" @@ -80,6 +83,70 @@ BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate) } +BOOST_AUTO_TEST_CASE(kdm_cli_specify_decryption_key_test) +{ + using boost::filesystem::path; + + ConfigRestorer cr; + + path const dir = "build/test/kdm_cli_specify_decryption_key_test"; + + boost::system::error_code ec; + boost::filesystem::remove_all(dir, ec); + boost::filesystem::create_directories(dir); + + dcp::CertificateChain chain(openssl_path(), 365); + dcp::write_string_to_file(chain.leaf().certificate(true), dir / "cert.pem"); + dcp::write_string_to_file(*chain.key(), dir / "key.pem"); + + vector make_args = { + "kdm_cli", + "--valid-from", "now", + "--valid-duration", "2 weeks", + "--projector-certificate", path(dir / "cert.pem").string(), + "-S", "base", + "-o", dir.string(), + "test/data/dkdm.xml" + }; + + vector output; + auto error = run(make_args, output); + BOOST_CHECK(!error); + + vector bad_args = { + "kdm_cli", + "--valid-from", "now", + "--valid-duration", "2 weeks", + "--projector-certificate", path(dir / "cert.pem").string(), + "-S", "bad", + "-o", dir.string(), + path(dir / "KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV__base.xml").string() + }; + + /* This should fail because we're using the wrong decryption certificate */ + output.clear(); + error = run(bad_args, output, false); + BOOST_REQUIRE(error); + BOOST_CHECK(error->find("oaep decoding error") != string::npos); + + vector good_args = { + "kdm_cli", + "--valid-from", "now", + "--valid-duration", "2 weeks", + "--projector-certificate", path(dir / "cert.pem").string(), + "--decryption-key", path(dir / "key.pem").string(), + "-S", "good", + "-o", dir.string(), + path(dir / "KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV__base.xml").string() + }; + + /* This should succeed */ + output.clear(); + error = run(good_args, output); + BOOST_CHECK(!error); +} + + static void setup_test_config() @@ -184,7 +251,7 @@ BOOST_AUTO_TEST_CASE(kdm_cli_specify_cinemas_file) "kdm_cli", "--cinemas-file", "test/data/cinemas.xml", - "--list-cinemas" + "list-cinemas" }; vector output; @@ -217,6 +284,7 @@ BOOST_AUTO_TEST_CASE(kdm_cli_specify_cert) "--valid-duration", "2 weeks", "-C", "test/data/cert.pem", "-o", "build/test", + "create", "build/test/kdm_cli_specify_cert" }; @@ -265,3 +333,29 @@ BOOST_AUTO_TEST_CASE(kdm_cli_time) BOOST_CHECK(boost::filesystem::exists(kdm_filename)); } + +BOOST_AUTO_TEST_CASE(kdm_cli_add_dkdm) +{ + ConfigRestorer cr; + + setup_test_config(); + + BOOST_CHECK_EQUAL(Config::instance()->dkdms()->children().size(), 0U); + + vector args = { + "kdm_cli", + "add-dkdm", + "test/data/dkdm.xml" + }; + + vector output; + auto error = run(args, output); + BOOST_CHECK(!error); + + auto dkdms = Config::instance()->dkdms()->children(); + BOOST_CHECK_EQUAL(dkdms.size(), 1U); + auto dkdm = dynamic_pointer_cast(dkdms.front()); + BOOST_CHECK(dkdm); + BOOST_CHECK_EQUAL(dkdm->dkdm().as_xml(), dcp::file_to_string("test/data/dkdm.xml")); +} +