summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-06-22 16:15:38 +0200
committerTomaž Vajngerl <quikee@gmail.com>2018-06-22 23:42:24 +0200
commit057c33b6609fe49efb6fa757db5f336acddb2a3d (patch)
treed700a101f7bcc53bc16cd4e41feb6fe5dc26c7a3 /oox
parent32f556667cb09587bd636239da9d463d8c15679a (diff)
oox: encryption/decryption test for Standard2007Engine
Change-Id: I8de25182c40004edffad4452179f191a75f130d9 Reviewed-on: https://gerrit.libreoffice.org/56300 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/CppunitTest_oox_crypto.mk74
-rw-r--r--oox/Module_oox.mk1
-rw-r--r--oox/qa/unit/CryptoTest.cxx106
3 files changed, 181 insertions, 0 deletions
diff --git a/oox/CppunitTest_oox_crypto.mk b/oox/CppunitTest_oox_crypto.mk
new file mode 100644
index 000000000000..64fd4df490b5
--- /dev/null
+++ b/oox/CppunitTest_oox_crypto.mk
@@ -0,0 +1,74 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_crypto))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_crypto,\
+ oox/qa/unit/CryptoTest \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,oox_crypto))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_crypto,\
+ basegfx \
+ comphelper \
+ cppu \
+ cppuhelper \
+ editeng \
+ drawinglayer \
+ msfilter \
+ sal \
+ oox \
+ sax \
+ sfx \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ sot \
+ tl \
+ unotest \
+ utl \
+ vcl \
+ xo \
+ xmlscript \
+))
+
+$(eval $(call gb_CppunitTest_use_api,oox_crypto,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,oox_crypto))
+$(eval $(call gb_CppunitTest_use_vcl,oox_crypto))
+$(eval $(call gb_CppunitTest_use_configuration,oox_crypto))
+
+$(eval $(call gb_CppunitTest_use_components,oox_crypto,\
+ comphelper/util/comphelp \
+ configmgr/source/configmgr \
+ filter/source/config/cache/filterconfig1 \
+ filter/source/storagefilterdetect/storagefd \
+ i18npool/util/i18npool \
+ package/source/xstor/xstor \
+ package/util/package2 \
+ sfx2/util/sfx \
+ sot/util/sot \
+ svl/source/fsstor/fsstorage \
+ svtools/util/svt \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
+ unotools/util/utl \
+ uui/util/uui \
+ vcl/vcl.common \
+))
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index 4d7a79e3d60c..db79a0f8e093 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_tokenmap \
CppunitTest_oox_vba_compression \
CppunitTest_oox_vba_encryption \
+ CppunitTest_oox_crypto \
))
# vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/CryptoTest.cxx b/oox/qa/unit/CryptoTest.cxx
new file mode 100644
index 000000000000..efe3e0cb5d6e
--- /dev/null
+++ b/oox/qa/unit/CryptoTest.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cppunit/plugin/TestPlugIn.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestFixture.h>
+
+#include <algorithm>
+#include <tools/stream.hxx>
+#include <unotools/streamwrap.hxx>
+
+#include <oox/crypto/Standard2007Engine.hxx>
+#include <oox/helper/binaryinputstream.hxx>
+#include <oox/helper/binaryoutputstream.hxx>
+
+using namespace css;
+
+class CryptoTest : public CppUnit::TestFixture
+{
+public:
+ void testStandard2007();
+
+ CPPUNIT_TEST_SUITE(CryptoTest);
+ CPPUNIT_TEST(testStandard2007);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void CryptoTest::testStandard2007()
+{
+ oox::core::Standard2007Engine aEngine;
+ {
+ SvMemoryStream aEncryptionInfo;
+ oox::BinaryXOutputStream aBinaryEncryptionInfoOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aEncryptionInfo), false);
+
+ aEngine.writeEncryptionInfo("Password", aBinaryEncryptionInfoOutputStream);
+ aBinaryEncryptionInfoOutputStream.close();
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(224), aEncryptionInfo.GetSize());
+ }
+
+ SvMemoryStream aUnencryptedInput;
+ SvMemoryStream aEncryptedStream;
+
+ OString aTestString = OUStringToOString("1234567890ABCDEFG", RTL_TEXTENCODING_UTF8);
+
+ aUnencryptedInput.WriteOString(aTestString);
+ aUnencryptedInput.Seek(STREAM_SEEK_TO_BEGIN);
+
+ {
+ oox::BinaryXInputStream aBinaryInputStream(
+ new utl::OSeekableInputStreamWrapper(aUnencryptedInput), true);
+ oox::BinaryXOutputStream aBinaryOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aEncryptedStream), true);
+
+ aEncryptedStream.WriteUInt32(aUnencryptedInput.GetSize());
+ aEncryptedStream.WriteUInt32(0U);
+
+ aEngine.encrypt(aBinaryInputStream, aBinaryOutputStream);
+ aBinaryOutputStream.close();
+ aBinaryInputStream.close();
+
+ const sal_uInt8* pData = static_cast<const sal_uInt8*>(aEncryptedStream.GetData());
+ sal_uInt64 nSize = aEncryptedStream.GetSize();
+
+ std::vector<sal_uInt8> aData(nSize);
+ std::copy(pData, pData + nSize, aData.data());
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(40), nSize);
+ }
+
+ aEncryptedStream.Seek(STREAM_SEEK_TO_BEGIN);
+ SvMemoryStream aUnencryptedOutput;
+
+ {
+ oox::BinaryXInputStream aBinaryInputStream(
+ new utl::OSeekableInputStreamWrapper(aEncryptedStream), true);
+ oox::BinaryXOutputStream aBinaryOutputStream(
+ new utl::OSeekableOutputStreamWrapper(aUnencryptedOutput), true);
+
+ aEngine.decrypt(aBinaryInputStream, aBinaryOutputStream);
+ aBinaryOutputStream.close();
+ aBinaryInputStream.close();
+
+ const sal_Char* pData = static_cast<const sal_Char*>(aUnencryptedOutput.GetData());
+ sal_uInt64 nSize = aUnencryptedOutput.GetSize();
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(32), nSize);
+
+ OString aString(pData);
+
+ CPPUNIT_ASSERT_EQUAL(aTestString, aString);
+ }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(CryptoTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */