diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-06-06 22:10:40 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-06-09 22:33:49 +0100 |
| commit | e6f2a4b0085b35be378f2cdd687146857d61df80 (patch) | |
| tree | 98bf0fe5057db49e1e58afc7769305264073b271 /test/ecinema_kdm_test.cc | |
| parent | 951d70db4f81b5ddd4093f11853637c8ecbe63c5 (diff) | |
swaroop: support validity periods in ecinema KDMs.
Diffstat (limited to 'test/ecinema_kdm_test.cc')
| -rw-r--r-- | test/ecinema_kdm_test.cc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/test/ecinema_kdm_test.cc b/test/ecinema_kdm_test.cc new file mode 100644 index 000000000..e44a626ba --- /dev/null +++ b/test/ecinema_kdm_test.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "lib/decrypted_ecinema_kdm.h" +#include "lib/encrypted_ecinema_kdm.h" +#include "lib/config.h" +#include <boost/test/unit_test.hpp> +extern "C" { +#include <libavutil/aes_ctr.h> +} +#include <fstream> + +using std::string; +using boost::optional; + +#ifdef DCPOMATIC_VARIANT_SWAROOP + +BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test1) +{ + dcp::Key key (AES_CTR_KEY_SIZE); + DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>()); + EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf()); + DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key()); + BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0"); + BOOST_CHECK_EQUAL (dec2.name(), "Hello world"); + BOOST_CHECK (dec2.key() == key); + BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before())); + BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after())); +} + +BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test2) +{ + dcp::Key key (AES_CTR_KEY_SIZE); + DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00")); + EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf()); + DecryptedECinemaKDM dec2 (enc, *Config::instance()->decryption_chain()->key()); + BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0"); + BOOST_CHECK_EQUAL (dec2.name(), "Hello world"); + BOOST_CHECK (dec2.key() == key); + BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before())); + BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00"); + BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after())); + BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00"); +} + +BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test3) +{ + dcp::Key key (AES_CTR_KEY_SIZE); + DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, optional<dcp::LocalTime>(), optional<dcp::LocalTime>()); + EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf()); + string const enc_xml = enc.as_xml (); + EncryptedECinemaKDM enc2 (enc_xml); + DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key()); + BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0"); + BOOST_CHECK_EQUAL (dec2.name(), "Hello world"); + BOOST_CHECK (dec2.key() == key); + BOOST_CHECK (!static_cast<bool>(dec2.not_valid_before())); + BOOST_CHECK (!static_cast<bool>(dec2.not_valid_after())); +} + +BOOST_AUTO_TEST_CASE (ecinema_kdm_roundtrip_test4) +{ + dcp::Key key (AES_CTR_KEY_SIZE); + DecryptedECinemaKDM dec ("123-456-789-0", "Hello world", key, dcp::LocalTime("2019-06-01T15:05:23+01:00"), dcp::LocalTime("2019-07-02T19:10:12+02:00")); + EncryptedECinemaKDM enc = dec.encrypt (Config::instance()->decryption_chain()->leaf()); + string const enc_xml = enc.as_xml(); + EncryptedECinemaKDM enc2 (dcp::file_to_string("build/test/shit_the_bed.xml")); + DecryptedECinemaKDM dec2 (enc2, *Config::instance()->decryption_chain()->key()); + BOOST_CHECK_EQUAL (dec2.id(), "123-456-789-0"); + BOOST_CHECK_EQUAL (dec2.name(), "Hello world"); + BOOST_CHECK (dec2.key() == key); + BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_before())); + BOOST_CHECK_EQUAL (dec2.not_valid_before()->as_string(), "2019-06-01T15:05:23+01:00"); + BOOST_REQUIRE (static_cast<bool>(dec2.not_valid_after())); + BOOST_CHECK_EQUAL (dec2.not_valid_after()->as_string(), "2019-07-02T19:10:12+02:00"); +} + +#endif |
