1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_security_tools.inc,v $
13 '* last change: $Author: jsk $ $Date: 2008-06-20 07:58:56 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 '* owner : joerg.skottke@sun.com
36 '* short description : Tools to ease testing of security related funtionality
38 '\******************************************************************************
40 function hSetPasswordRecommendation( bEnable as boolean ) as boolean
42 '///<h3>Toggle Tools/Options/OOo/Security: Password recommendation</h3>
45 '///+<li>Mode (boolean)</li>
47 '///+<li>TRUE: Switch password recommendation on</li>
48 '///+<li>FALSE: Switch password recommendation off</li>
54 '///+<li>Prior state (boolean)</li>
56 '///+<li>TRUE: Password recommendation was on</li>
57 '///+<li>FALSE: Password recommendation was off</li>
61 '///<u>Description</u>:
64 const CFN = "hSetPasswordRecommendation::"
66 '///+<li>Open Tools/Options</li>
70 if ( OptionenDlg.exists( 2 ) ) then
72 '///+<li>Go to the security page</li>
73 hToolsOptions( "STAROFFICE" , "SECURITY" )
75 '///+<li>Click on the "Options..." button</li>
79 kontext "TabSecurityOptionsAndWarnings"
80 if ( TabSecurityOptionsAndWarnings.exists( 1 ) ) then
82 '///+<li>Retrieve the current setting for passwor recommendation</li>
83 if ( RecommendPasswordProtectionOnSaving.isChecked() ) then
84 hSetPasswordRecommendation() = true
86 hSetPasswordRecommendation() = false
89 '///+<li>Set the requested state</li>
91 printlog( CFN & "Enabled password recommendation" )
92 RecommendPasswordProtectionOnSaving.check()
94 printlog( CFN & "Disabled password recommendation" )
95 RecommendPasswordProtectionOnSaving.uncheck()
98 TabSecurityOptionsAndWarnings.ok()
100 warnlog( "Failed to open security options page" )
103 '///+<li>Close Tools/Options</li>
104 Kontext "ToolsOptionsDlg"
108 warnlog( "Failed to open Tools/Options" )
114 '******************************************************************************
116 function hOpenDigitalSignaturesDialog() as boolean
118 '///<h3>Open the Digital Signatures Dialog via File-Menu</h3>
121 '///+<li>Nothing</li>
126 '///+<li>Errorcondition (boolean)</li>
128 '///+<li>TRUE: The Digital Signatures Dialog is open</li>
129 '///+<li>FALSE: The Digital Signatures Dialog is not open</li>
133 '///<u>Description</u>:
137 const CFN = "hOpenDigitalSignaturesDialog::"
139 '///+<li>Open the file-menu</li>
141 call hMenuSelectNr( 1 )
143 '///+<li>Select "Digital signatures..."</li>
145 if ( ucase( gApplication ) = "MATH" ) then
146 call hMenuSelectNr( 14 )
148 call hMenuSelectNr( 15 )
151 warnlog( CFN & "Failed to execute menuitem <Digital Signature...>" )
154 ' At this stage either the digital signatures dialog or the messagebox
155 ' <The document needs to be saved> is open. In the latter case the function
156 ' returns false. The possibility that neither of both dialogs are open
157 ' must be handled in the parent function. This means there is no warning
160 '///+<li>Verify that the Digital Signatures dialog is open</li>
161 kontext "DigitalSignature"
162 if ( DigitalSignature.exists() ) then
163 printlog( CFN & "Digital signatures is open" )
170 hOpenDigitalSignaturesDialog() = brc
174 '*******************************************************************************
176 function hAllowMacroExecution() as boolean
178 '///<h3>Allow macro execution on Macro Security Warning dialog</h3>
181 '///+<li>Nothing</li>
186 '///+<li>Errorcondition (boolean)</li>
188 '///+<li>TRUE: Macro dialog is open, successfully clicked "Run"</li>
189 '///+<li>FALSE: Dialog was not opened</li>
193 '///<u>Description</u>:
196 const CFN = "hAllowMacroExecution::"
198 '///+<li>Verify that the Macro security Warning is displayed</li>
199 kontext "SecurityWarning"
200 if ( SecurityWarning.exists( 5 ) ) then
202 '///+<li>Click "Run" to allow macro execution</li>
204 hAllowMacroExecution() = true
205 printlog( CFN & "Allowed macro execution" )
207 hAllowMacroExecution() = false
208 printlog( CFN & "Macro dialog not displayed" )
214 '*******************************************************************************
216 function hDenyMacroExecution() as boolean
218 '///<h3>Deny macro execution on Macro Security Warning dialog</h3>
221 '///+<li>Nothing</li>
226 '///+<li>Errorcondition (boolean)</li>
228 '///+<li>TRUE: Macro dialog is open, successfully clicked "Deny"</li>
229 '///+<li>FALSE: Dialog was not opened</li>
233 '///<u>Description</u>:
236 const CFN = "hDenyMacroExecution::"
238 '///+<li>Verify that the Macro security Warning is displayed</li>
239 kontext "SecurityWarning"
240 if ( SecurityWarning.exists() ) then
242 '///+<li>Click "Cancel" to deny execution</li>
243 SecurityWarning.cancel()
244 hDenyMacroExecution() = true
245 printlog( CFN & "Denied macro execution" )
247 hDenyMacroExecution() = false
248 printlog( CFN & "Macro dialog not displayed" )
254 '*******************************************************************************
256 function hSwitchMacroSecurityTab( cTab as string )
258 '///<h3>Switch between Security Level and Trusted Paths</h3>
261 '///+<li>The Tabpage to be activated (string). Valid options are:</li>
263 '///+<li>"SecurityLevel"</li>
264 '///+<li>"TrustedPaths"</li>
270 '///+<li>Nothing</li>
273 '///<u>Description</u>:
278 '///+<li>Switch to the given Tabpage</li>
279 select case ( lcase( cTab ) )
280 case "securitylevel" : active.setPage TabSecurityLevel
281 case "trustedpaths" : active.setPage TabTrustedSources
288 '*******************************************************************************
290 function hAddTrustedPath( cPath as string ) as boolean
292 '///<h3>Add a directory to the list of trusted paths</h3>
295 '///+<li>Fully qualified path to the directory (string)</li>
300 '///+<li>Errorcondition (boolean)</li>
302 '///+<li>TRUE = Path was successfully added</li>
303 '///+<li>FALSE = Failed to add the path</li>
307 const CFN = "hAddTrustedPath::"
309 dim iPathCount as integer
312 '///<u>Description</u>:
315 '///+<li>Open Tools/Options</li>
318 '///+<li>Switch to the Security page</li>
319 hToolsOptions( "StarOffice" , "Security" )
321 '///+<li>Click Macro Security</li>
322 MacroSecurity.click()
324 '///+<li>Switch to the Trusted Paths tab</li>
325 hSwitchMacroSecurityTab( "trustedpaths" )
326 kontext "TabTrustedSources"
328 '///+<li>Get the number of currently listed items from the list</li>
329 iPathCount = LocationsListBox.getItemCount()
331 '///+<li>Click the "Add" button</li>
334 '///+<li>Enter a path to some files containing macros</li>
336 DateiName.setText( cPath )
338 '///+<li>Click "Select"</li>
341 '///+<li>Verify that the item has been added to the list</li>
342 kontext "TabTrustedSources"
343 if ( LocationsListBox.getItemCount() <> ( iPathCount + 1 ) ) then
344 warnlog( CFN & "Incorrect number of items in locations listbox" )
347 printlog( CFN & "Added: " & cPath )
351 '///+<li>Close the dialog</li>
352 TabTrustedSources.ok()
354 '///+<li>Close Tools/Options</li>
355 Kontext "OptionenDlg"
358 hAddTrustedPath() = brc
364 '*******************************************************************************
366 function hRemoveTrustedPath( cPath as string ) as boolean
368 '///<h3>Remove a directory from the list of trusted paths</h3>
371 '///+<li>Fully qualified path to the directory (string)</li>
376 '///+<li>Errorcondition (boolean)</li>
378 '///+<li>TRUE = Path was successfully added</li>
379 '///+<li>FALSE = Failed to add the path</li>
383 const CFN = "hRemoveTrustedPath()"
385 dim iPathCount as integer
386 dim iCurrentPathItem as integer
391 '///<u>Description</u>:
394 '///+<li>Open Tools/Options</li>
397 '///+<li>Switch to the Security page</li>
398 hToolsOptions( "StarOffice" , "Security" )
400 '///+<li>Click Macro Security</li>
401 MacroSecurity.click()
403 '///+<li>Switch to the Trusted Paths tab</li>
404 hSwitchMacroSecurityTab( "trustedpaths" )
405 kontext "TabTrustedSources"
407 '///+<li>Get the number of currently listed items from the list</li>
408 iPathCount = LocationsListBox.getItemCount()
410 '///+<li>Find the entry in the list</li>
411 for iCurrentPathItem = 1 to iPathCount
413 '///+<li>If it is there, delete it</li>
414 LocationsListBox.select( iCurrentPathItem )
415 if ( LocationsListBox.getSelText() = cPath ) then
416 LocationsRemove.click()
417 printlog( CFN & "Removed item at pos. " & iCurrentPathItem )
422 next iCurrentPathItem
424 '///+<li>Close the dialog</li>
425 TabTrustedSources.ok()
427 '///+<li>Close Tools/Options</li>
428 Kontext "OptionenDlg"
432 printlog( CFN & "The trusted path was not found in the list" )
435 hRemoveTrustedPath() = brc
442 '*******************************************************************************
444 function hSecurityEnterPasswordOnSave( cPassword as string ) as boolean
447 '///<h3>Enter password when saving a document</h3>
448 '///<i>This function enters a password into the password dialog if the "
449 '///+ Save with password" checkbox is checked. It will automatically
450 '///+ generate a faulty password to be entered on first try (to see whether
451 '///+ the "Invalid password confirmation" dialog pops up, on second
452 '///+ attempt the password is confirmed correctly and thus the document should
453 '///+ save ok. The office should return to the document, the File Save dialog
454 '///+ should close after save.</i><br><br>
456 '///<u>Parameter(s):</u><br>
459 '///+<li>Password to use (String)</li>
461 '///+<li>Password should contain strange characters and glyphs if possible</li>
467 '///<u>Returns:</u><br>
469 '///+<li>Errorcondition (Boolean)</li>
471 '///+<li>TRUE if all went well</li>
472 '///+<li>FALSE on any error</li>
476 const CFN = "hSecurityEnterPasswordOnSave::"
477 printlog( CFN & "Enter" )
478 dim brc as boolean 'a multi purpose boolean returnvalue
481 '///<u>Description:</u>
483 '///+<li>Verify that the password dialog is present</li>
484 kontext "PasswordFileSave"
485 if ( PasswordFileSave.exists( 2 ) ) then
487 printlog( CFN & "Password dialog is displayed" )
489 '///+<li>Enter the password</li>
490 Password.setText( cPassword )
492 '///+<li>Confirm with incorrect password (e.g. append a number at random)</li>
493 PasswordConfirm.setText( cPassword & "1" )
495 '///+<li>Click on OK</li>
496 PasswordFileSave.ok()
498 '///+<li>There should be a warning about a faulty password confirmation</li>
500 if ( Active.exists( 1 ) ) then
501 printlog( CFN & "Message: " & Active.getText() )
503 '///+<li>Close messagebox with OK</li>
506 qaerrorlog( CFN & "Warning about faulty password confirmation is missing" )
510 '///+<li>We should now be back on the password dialog</li>
511 kontext "PasswordFileSave"
512 if ( PasswordFileSave.exists( 2 ) ) then
514 printlog( CFN & "Password dialog is displayed" )
516 '///+<li>Enter the password</li>
517 Password.setText( cPassword )
519 '///+<li>Confirm with correct password</li>
520 PasswordConfirm.setText( cPassword )
522 '///+<li>Click on OK</li>
523 PasswordFileSave.ok()
527 qaerrorlog( CFN & "The password dialog is missing after confirmation error" )
534 qaerrorlog( CFN & "The password dialog did not open" )
539 '///+<li>Verify that the "File Save" dialog is closed after saving</li>
540 kontext "SpeichernDlg"
541 if ( SpeichernDlg.exists() ) then
542 qaerrorlog( CFN & "File Save dialog is open, cancelling." )
543 SpeichernDlg.cancel()
548 printlog( CFN & "Exit with result: " & brc )
549 hSecurityEnterPasswordOnSave() = brc
554 '*******************************************************************************
556 function hSecurityEnterPasswordOnLoad( cPassword as string, bValid as boolean ) as boolean
558 use "global\tools\includes\optional\t_stringtools.inc"
560 '///<h3>Enter a password while loading a document</h3>
561 '///<i>Enters a valid or invalid password while loading a passworded file</i><br><br>
563 '///<u>Parameter(s):</u><br>
566 '///+<li>Password (String)</li>
568 '///+<li>The password should contain special characters and glyphs</li>
571 '///+<li>Password validity (Boolean)</li>
573 '///+<li>TRUE: The password is correct, the document should load</li>
574 '///+<li>FALSE: The password is incorrect, the document should not load</li>
580 '///<u>Returns:</u><br>
582 '///+<li>Errorcondition (Boolean)</li>
584 '///+<li>TRUE if the password protection worked as expected</li>
585 '///+<li>FALSE on any error</li>
589 const CFN = "hSecurityEnterPasswordOnLoad::"
590 printlog( CFN & "Enter with option (Password): " & cPassword )
591 printlog( CFN & "Enter with option (Validity): " & bValid )
592 dim brc as boolean 'a multi purpose boolean returnvalue
596 '///<u>Description:</u>
598 '///+<li>Verify that the password dialog exists</li>
599 kontext "PasswordFileOpen"
600 if ( PasswordFileOpen.exists( 3 ) ) then
602 '///+<li>Enter password, click OK</li>
603 PasswortName.setText( cPassword )
604 PasswordFileOpen.ok()
606 '///+<li>If the password was incorrect:</li>
608 if ( not bValid ) then
610 '///+<li>Look for a warning message</li>
612 if ( Active.exists( 1 ) ) then
614 cMsg = Active.getText()
615 cMsg = hRemoveLineBreaks( cMsg )
617 warnlog( CFN & "Message: " & cMsg )
619 printlog( CFN & "Message: " & cMsg )
622 '///+<li>Close the messagebox</li>
625 '///+<li>Close the Password dialog with "Cancel"</li>
626 kontext "PasswordFileOpen"
627 if ( PasswordFileopen.exists( 2 ) ) then
629 PasswordFileOpen.cancel()
633 qaerrorlog( CFN & "Password dialog is not present" )
639 qaerrorlog( CFN & "Warning about incorrect password is missing" )
647 if ( Active.exists( 1 ) ) then
649 cMsg = Active.getText()
650 cMsg = hRemoveLIneBreaks( cMsg )
651 qaerrorlog( CFN & "Unexpected messagebox: " & cMsg )
661 qaerrorlog( CFN & "Password dialog is missing" )
667 printlog( CFN & "Exit with result:" & brc )
668 hSecurityEnterPasswordOnLoad() = brc