'encoding UTF-8 Do not remove or change this line!
'**************************************************************
'
' Licensed to the Apache Software Foundation (ASF) under one
' or more contributor license agreements. See the NOTICE file
' distributed with this work for additional information
' regarding copyright ownership. The ASF licenses this file
' to you under the Apache License, Version 2.0 (the
' "License"); you may not use this file except in compliance
' with the License. You may obtain a copy of the License at
'
' http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing,
' software distributed under the License is distributed on an
' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
' KIND, either express or implied. See the License for the
' specific language governing permissions and limitations
' under the License.
'
'**************************************************************
'*
'* short description : Tools to ease testing of security related funtionality
'*
'\******************************************************************************
function hSetPasswordRecommendation( bEnable as boolean ) as boolean
'///
Toggle Tools/Options/OOo/Security: Password recommendation
'///Input:
'///
'///+- Mode (boolean)
'///
'///+- TRUE: Switch password recommendation on
'///+- FALSE: Switch password recommendation off
'///
'///
'///Returns:
'///
'///+- Prior state (boolean)
'///
'///+- TRUE: Password recommendation was on
'///+- FALSE: Password recommendation was off
'///
'///
'///Description:
'///
const CFN = "hSetPasswordRecommendation::"
'///+- Open Tools/Options
ToolsOptions
kontext "OptionenDlg"
if ( OptionenDlg.exists( 2 ) ) then
'///+- Go to the security page
hToolsOptions( "STAROFFICE" , "SECURITY" )
'///+- Click on the "Options..." button
kontext "TabSecurity"
if ( hClickButton( Options ) ) then
kontext "TabSecurityOptionsAndWarnings"
if ( TabSecurityOptionsAndWarnings.exists( 1 ) ) then
'///+- Retrieve the current setting for passwor recommendation
if ( RecommendPasswordProtectionOnSaving.isChecked() ) then
hSetPasswordRecommendation() = true
else
hSetPasswordRecommendation() = false
endif
'///+- Set the requested state
if ( bEnable ) then
printlog( CFN & "Enabled password recommendation" )
RecommendPasswordProtectionOnSaving.check()
else
printlog( CFN & "Disabled password recommendation" )
RecommendPasswordProtectionOnSaving.uncheck()
endif
hCloseDialog( TabSecurityOptionsAndWarnings, "ok" )
else
warnlog( "Failed to open security options page" )
hSetPasswordRecommendation() = false
endif
else
warnlog( CFN & "Unable to click options button" )
hSetPasswordRecommendation() = false
endif
'///+- Close Tools/Options
Kontext "ToolsOptionsDlg"
hCloseDialog( ToolsOptionsDlg, "ok" )
else
warnlog( "Failed to open Tools/Options" )
endif
'///
end function
'******************************************************************************
function hOpenDigitalSignaturesDialog() as boolean
'///Open the Digital Signatures Dialog via File-Menu
'///Input:
'///
'///+- Nothing
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE: The Digital Signatures Dialog is open
'///+- FALSE: The Digital Signatures Dialog is not open
'///
'///
'///Description:
'///
const CFN = "hOpenDigitalSignaturesDialog::"
const FILE_MENU_POSITION = 1
const SIGNATURES_MENU_POSITION_OTHER = 15
const SIGNATURES_MENU_POSITION_MATH = 14
hOpenDigitalSignaturesDialog() = false
'///+- Open the file-menu
call hUseMenu()
call hMenuSelectNr( FILE_MENU_POSITION )
'///+- Select "Digital signatures..."
try
if ( gApplication = "MATH" ) then
call hMenuSelectNr( SIGNATURES_MENU_POSITION_MATH )
else
call hMenuSelectNr( SIGNATURES_MENU_POSITION_OTHER )
endif
catch
warnlog( CFN & "Failed to execute menuitem " )
endcatch
' At this stage either the digital signatures dialog or the messagebox
' is open. In the latter case the function
' returns false. The possibility that neither of both dialogs are open
' must be handled in the parent function. This means there is no warning
' here either
'///+- Verify that the Digital Signatures dialog is open
kontext "DigitalSignature"
if ( DigitalSignature.exists() ) then
printlog( CFN & "Digital signatures is open" )
hOpenDigitalSignaturesDialog() = true
endif
'///
end function
'*******************************************************************************
function hAllowMacroExecution() as boolean
'///Allow macro execution on Macro Security Warning dialog
'///Input:
'///
'///+- Nothing
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE: Macro dialog is open, successfully clicked "Run"
'///+- FALSE: Dialog was not opened
'///
'///
'///Description:
'///
const CFN = "hAllowMacroExecution::"
const MAX_WAIT_FOR_SECURITY_DIALOG = 5
'///+- Verify that the Macro security Warning is displayed
kontext "SecurityWarning"
if ( SecurityWarning.exists( MAX_WAIT_FOR_SECURITY_DIALOG ) ) then
'///+- Click "Run" to allow macro execution
printlog( CFN & "Allowing macro execution" )
hAllowMacroExecution() = hCloseDialog( SecurityWarning, "ok" )
else
printlog( CFN & "Macro dialog not displayed" )
hAllowMacroExecution() = false
endif
'///
end function
'*******************************************************************************
function hDenyMacroExecution() as boolean
'///Deny macro execution on Macro Security Warning dialog
'///Input:
'///
'///+- Nothing
'///
'///Returns:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE: Macro dialog is open, successfully clicked "Deny"
'///+- FALSE: Dialog was not opened
'///
'///
'///Description:
'///
const CFN = "hDenyMacroExecution::"
'///+- Verify that the Macro security Warning is displayed
kontext "SecurityWarning"
if ( SecurityWarning.exists() ) then
'///+- Click "Cancel" to deny execution
printlog( CFN & "Denied macro execution" )
hDenyMacroExecution() = hCloseDialog( SecurityWarning, "cancel" )
else
printlog( CFN & "Macro dialog not displayed" )
hDenyMacroExecution() = false
endif
'///
end function
'*******************************************************************************
function hSwitchMacroSecurityTab( cTab as string )
'///Switch between Security Level and Trusted Paths
'///Input:
'///
'///+- The Tabpage to be activated (string). Valid options are:
'///
'///+- "SecurityLevel"
'///+- "TrustedPaths"
'///
'///
'///Returns:
'///
'///+- Nothing
'///
'///Description:
'///
kontext
'///+- Switch to the given Tabpage
select case ( lcase( cTab ) )
case "securitylevel" : active.setPage TabSecurityLevel
case "trustedpaths" : active.setPage TabTrustedSources
end select
'///
end function
'*******************************************************************************
function hAddTrustedPath( cPath as string ) as boolean
'///Add a directory to the list of trusted paths
'///Input:
'///
'///+- Fully qualified path to the directory (string)
'///
'///Return:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = Path was successfully added
'///+- FALSE = Failed to add the path
'///
'///
const CFN = "hAddTrustedPath::"
dim iPathCount as integer
'///Description:
'///
'///+- Open Tools/Options
ToolsOptions
'///+- Switch to the Security page
hToolsOptions( "StarOffice" , "Security" )
'///+- Click Macro Security
hClickButton( MacroSecurity )
'///+- Switch to the Trusted Paths tab
hSwitchMacroSecurityTab( "trustedpaths" )
kontext "TabTrustedSources"
'///+- Get the number of currently listed items from the list
iPathCount = LocationsListBox.getItemCount()
'///+- Click the "Add" button
hClickButton( LocationsAdd )
'///+- Enter a path to some files containing macros
kontext "OeffnenDlg"
DateiName.setText( cPath )
'///+- Click "Select"
hClickButton( Oeffnen )
'///+- Verify that the item has been added to the list
kontext "TabTrustedSources"
if ( LocationsListBox.getItemCount() <> ( iPathCount + 1 ) ) then
warnlog( CFN & "Incorrect number of items in locations listbox" )
hAddTrustedPath() = false
else
printlog( "Added: " & cPath )
hAddTrustedPath() = true
endif
'///+- Close the dialog
hCloseDialog( TabTrustedSources, "ok" )
'///+- Close Tools/Options
Kontext "OptionenDlg"
hCloseDialog( OptionenDlg, "ok" )
'///
end function
'*******************************************************************************
function hRemoveTrustedPath( cPath as string ) as boolean
'///Remove a directory from the list of trusted paths
'///Input:
'///
'///+- Fully qualified path to the directory (string)
'///
'///Return:
'///
'///+- Errorcondition (boolean)
'///
'///+- TRUE = Path was successfully added
'///+- FALSE = Failed to add the path
'///
'///
const CFN = "hRemoveTrustedPath()"
dim iPathCount as integer
dim iCurrentPathItem as integer
hRemoveTrustedPath() = false
'///Description:
'///
'///+- Open Tools/Options
ToolsOptions
'///+- Switch to the Security page
hToolsOptions( "StarOffice" , "Security" )
'///+- Click Macro Security
hClickButton( MacroSecurity )
'///+- Switch to the Trusted Paths tab
hSwitchMacroSecurityTab( "trustedpaths" )
kontext "TabTrustedSources"
if ( TabTrustedSources.exists() ) then
'///+- Get the number of currently listed items from the list
iPathCount = LocationsListBox.getItemCount()
'///+- Find the entry in the list
for iCurrentPathItem = 1 to iPathCount
'///+- If it is there, delete it
LocationsListBox.select( iCurrentPathItem )
if ( LocationsListBox.getSelText() = cPath ) then
LocationsRemove.click()
printlog( CFN & "Removed item at pos. " & iCurrentPathItem )
hRemoveTrustedPath() = true
exit for
endif
next iCurrentPathItem
'///+- Close the dialog
hCloseDialog( TabTrustedSources, "ok" )
else
warnlog( CFN & "Trusted Sources Tab did not open" )
hRemoveTrustedPath() = false
endif
'///+- Close Tools/Options
Kontext "OptionenDlg"
hCloseDialog( OptionenDlg, "ok" )
'///
end function
'*******************************************************************************
function hSecurityEnterPasswordOnSave( cPassword as string ) as boolean
'///Enter password when saving a document
'///This function enters a password into the password dialog if the "
'///+ Save with password" checkbox is checked. It will automatically
'///+ generate a faulty password to be entered on first try (to see whether
'///+ the "Invalid password confirmation" dialog pops up, on second
'///+ attempt the password is confirmed correctly and thus the document should
'///+ save ok. The office should return to the document, the File Save dialog
'///+ should close after save.
'///Parameter(s):
'///
'///+- Password to use (String)
'///
'///+- Password should contain strange characters and glyphs if possible
'///
'///
'///Returns:
'///
'///+- Errorcondition (Boolean)
'///
'///+- TRUE if all went well
'///+- FALSE on any error
'///
'///
const CFN = "hSecurityEnterPasswordOnSave::"
if ( GVERBOSE ) then printlog( CFN & "Enter" )
'///Description:
'///
'///+- Verify that the password dialog is present
kontext "PasswordFileSave"
if ( PasswordFileSave.exists( 2 ) ) then
printlog( CFN & "Password dialog is displayed" )
'///+- Enter the password
Password.setText( cPassword )
'///+- Confirm with incorrect password (e.g. append a number at random)
PasswordConfirm.setText( cPassword & "1" )
'///+- Click on OK
hCloseDialog( PasswordFileSave, "ok" )
'///+- There should be a warning about a faulty password confirmation
kontext "Active"
if ( Active.exists( 1 ) ) then
printlog( CFN & "Message: " & Active.getText() )
'///+- Close messagebox with OK
Active.OK()
Active.notExists( 2 )
else
qaerrorlog( CFN & "Warning about faulty password confirmation is missing" )
hSecurityEnterPasswordOnSave() = false
endif
'///+- We should now be back on the password dialog
kontext "PasswordFileSave"
if ( PasswordFileSave.exists() ) then
printlog( CFN & "Password dialog is displayed" )
'///+- Enter the password
Password.setText( cPassword )
'///+- Confirm with correct password
PasswordConfirm.setText( cPassword )
'///+- Click on OK
hCloseDialog( PasswordFileSave, "ok" )
hSecurityEnterPasswordOnSave() = true
else
qaerrorlog( CFN & "The password dialog is missing after confirmation error" )
hSecurityEnterPasswordOnSave() = false
endif
else
qaerrorlog( CFN & "The password dialog did not open" )
hSecurityEnterPasswordOnSave() = false
endif
'///+- Verify that the "File Save" dialog is closed after saving
kontext "SpeichernDlg"
if ( SpeichernDlg.exists() ) then
qaerrorlog( CFN & "File Save dialog is open, cancelling." )
SpeichernDlg.cancel()
hSecurityEnterPasswordOnSave() = false
endif
'///
if ( GVERBOSE ) then printlog( CFN & "Exit" )
end function
'*******************************************************************************
function hSecurityEnterPasswordOnLoad( cPassword as string, bValid as boolean ) as boolean
'///Enter a password while loading a document
'///Enters a valid or invalid password while loading a passworded file
'///Parameter(s):
'///
'///+- Password (String)
'///
'///+- The password should contain special characters and glyphs
'///
'///+- Password validity (Boolean)
'///
'///+- TRUE: The password is correct, the document should load
'///+- FALSE: The password is incorrect, the document should not load
'///
'///
'///Returns:
'///
'///+- Errorcondition (Boolean)
'///
'///+- TRUE if the password protection worked as expected
'///+- FALSE on any error
'///
'///
const CFN = "hSecurityEnterPasswordOnLoad::"
if ( GVERBOSE ) then
printlog( CFN & "Enter with option (Password): " & cPassword )
printlog( CFN & "Enter with option (Validity): " & bValid )
endif
hSecurityEnterPasswordOnLoad() = true
'///Description:
'///
'///+- Verify that the password dialog exists
kontext "PasswordFileOpen"
if ( PasswordFileOpen.exists( 3 ) ) then
'///+- Enter password, click OK
PasswortName.setText( cPassword )
hCloseDialog( PasswordFileOpen, "ok" )
'///+- If the password was incorrect:
'///
if ( not bValid ) then
'///+- Look for a warning message
kontext "Active"
if ( Active.exists( 1 ) ) then
printlog( CFN & "Message: " & Active.getText() )
'///+- Close the messagebox
hCloseDialog( Active, "ok" )
'///+- Close the Password dialog with "Cancel"
kontext "PasswordFileOpen"
if ( PasswordFileopen.exists( 2 ) ) then
hCloseDialog( PasswordFileOpen, "cancel" )
else
qaerrorlog( CFN & "Password dialog is not present" )
hSecurityEnterPasswordOnLoad() = false
endif
else
qaerrorlog( CFN & "Warning about incorrect password is missing" )
hSecurityEnterPasswordOnLoad() = false
endif
else
kontext "Active"
if ( Active.exists( 1 ) ) then
warnlog( CFN & "Unexpected messagebox: " & Active.getText() )
hSecurityEnterPasswordOnLoad() = false
endif
endif
'///
else
warnlog( CFN & "Password dialog is missing" )
hSecurityEnterPasswordOnLoad() = false
endif
'///
end function
'*******************************************************************************
function hSelectXMLSecTab( cTab as string ) as boolean
const CFN = "hSelectXMLSecTab::"
hSelectXMLSecTab() = false
kontext
select case ( ucase( cTab ) )
case "GENERAL" : active.setpage TabXMLSecGeneral
if ( TabXMLSecGeneral.exists() and TabXMLSecGeneral.isVisible() ) then
printlog( CFN & "Switched to General page" )
hSelectXMLSecTab() = true
exit function
endif
case "DETAILS" : active.setpage TabXMLSecDetails
if ( TabXMLSecDetails.exists() and TabXMLSecDetails.isVisible() ) then
printlog( CFN & "Switched to Details page" )
hSelectXMLSecTab() = true
exit function
endif
case "PATH" : active.setpage TabXMLSecCertPath
if ( TabXMLSecCertPath.exists() and TabXMLSecCertPath.isVisible() ) then
printlog( CFN & "Switched to Certification Path page" )
hSelectXMLSecTab() = true
exit function
endif
end select
warnlog( CFN & "Failed to switch XML Security Tabpage" )
end function