[Libreoffice-commits] core.git: 2 commits - basic/source sw/qa

Michael Stahl mstahl at redhat.com
Mon Mar 7 11:07:34 UTC 2016


 basic/source/uno/namecont.cxx   |   17 ++++++++++++--
 basic/source/uno/scriptcont.cxx |   10 ++++++++
 sw/qa/core/macros-test.cxx      |   47 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 2 deletions(-)

New commits:
commit 6a351c5cf91d0f667168d834ba2eb5c04121c7d5
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Mar 5 00:42:05 2016 +0100

    basic: tdf#87530 if a new password is set, must set mbLoadedSource flag
    
    ... so that the library is stored (and encrypted), and not copied
    unencrypted from source storage.
    
    Change-Id: I9546087ec6f07007aa1ec377d2e959f2bae99a38

diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index e315d3e..09388fc 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -94,6 +94,11 @@ void SfxScriptLibraryContainer::setLibraryPassword( const OUString& rLibraryName
             pImplLib->mbDoc50Password = true;
             pImplLib->mbPasswordProtected = true;
             pImplLib->maPassword = rPassword;
+            SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
+            if (pSL && pSL->mbLoaded)
+            {
+                pSL->mbLoadedSource = true; // must store source code now!
+            }
         }
     }
     catch(const NoSuchElementException& ) {}
@@ -486,6 +491,11 @@ void SAL_CALL SfxScriptLibraryContainer::changeLibraryPassword( const OUString&
         pImplLib->mbPasswordProtected = true;
         pImplLib->mbPasswordVerified = true;
         pImplLib->maPassword = NewPassword;
+        SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
+        if (pSL && pSL->mbLoaded)
+        {
+            pSL->mbLoadedSource = true; // must store source code now!
+        }
 
         maModifiable.setModified( true );
         pImplLib->implSetModified( true );
commit aeb43916366b293935314efe9454c66b4877b9d1
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 4 23:01:18 2016 +0100

    basic: tdf#87530 don't copy storage that doesn't exist
    
    If the Basic library is newly created it may not have been stored to the
    document storage yet.
    
    (regression from 5246fa262450f686674850c53df666422f441c86)
    
    Change-Id: I9c2fc1d7446795b9c1c2224671118b2a671dcad8

diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index b83344a..9608fa1 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1946,8 +1946,21 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
 // fdo#68983: If there's a password and the password is not known, only
 // copying the storage works!
             // Can we simply copy the storage?
-            if (!mbOldInfoFormat && !pImplLib->isLoadedStorable() &&
-                !mbOasis2OOoFormat && xSourceLibrariesStor.is())
+            bool isCopyStorage = !mbOldInfoFormat && !mbOasis2OOoFormat
+                    && !pImplLib->isLoadedStorable()
+                    && xSourceLibrariesStor.is() /* null for user profile */;
+            if (isCopyStorage)
+            {
+                try
+                {
+                    xSourceLibrariesStor->isStorageElement(rLib.aName);
+                }
+                catch (container::NoSuchElementException const&)
+                {
+                    isCopyStorage = false;
+                }
+            }
+            if (isCopyStorage)
             {
                 try
                 {
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index 687ac86..ab9203e 100644
--- a/sw/qa/core/macros-test.cxx
+++ b/sw/qa/core/macros-test.cxx
@@ -86,6 +86,7 @@ public:
 #endif
     void testFdo55289();
     void testFdo68983();
+    void testFdo87530();
     void testFindReplace();
     CPPUNIT_TEST_SUITE(SwMacrosTest);
 #if !defined(MACOSX) && !defined(_WIN32)
@@ -101,6 +102,7 @@ public:
 #endif
     CPPUNIT_TEST(testFdo55289);
     CPPUNIT_TEST(testFdo68983);
+    CPPUNIT_TEST(testFdo87530);
     CPPUNIT_TEST(testFindReplace);
 
     CPPUNIT_TEST_SUITE_END();
@@ -431,6 +433,51 @@ void SwMacrosTest::testFdo68983()
     xDocCloseable->close(false);
 }
 
+void SwMacrosTest::testFdo87530()
+{
+    Reference<css::lang::XComponent> xComponent =
+        loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+
+    {
+        Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
+        Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
+        Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
+        Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
+        xBasLib->createLibrary("Library1");
+        xBasLibPwd->changeLibraryPassword("Library1", "", "foo");
+    }
+
+    Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xDocStorable.is());
+
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+    Sequence<beans::PropertyValue> desc(1);
+    desc[0].Name = "FilterName";
+    desc[0].Value <<= OUString("writer8");
+    xDocStorable->storeAsURL(aTempFile.GetURL(), desc);
+
+    Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false);
+
+    // re-load
+    xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+
+    // check that password-protected library survived store and re-load
+    Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
+    Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
+    Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
+    Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("Library1"));
+    CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("Library1", "foo"));
+    xBasLib->loadLibrary("Library1");
+    CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("Library1"));
+
+    // close
+    Reference<util::XCloseable> xDocCloseable(xComponent, UNO_QUERY_THROW);
+    xDocCloseable->close(false);
+}
+
+
 void SwMacrosTest::testFindReplace()
 {
     // we need a full document with view and layout etc. because ::GetNode()


More information about the Libreoffice-commits mailing list