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: security_macrosecurity.inc,v $
13 '* last change: $Author: rt $ $Date: 2008-08-28 11:40:28 $
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 : Macros with all security-levels
38 '\******************************************************************************
40 sub tMacroSecurityLevelsControlModule
42 dim iApplication as integer
44 for iApplication = 1 to 6
47 printlog( hNumericDocType( iApplication ) )
48 call tMacroSecurityLevels( "current" )
49 call tMacroSecurityLevels( "645" )
55 '*******************************************************************************
57 testcase tMacroSecurityLevels( cFileFormat )
59 '///<H1>Macro execution in all security levels</H1>
62 dim cWorkFile as string
63 cWorkFile = gTesttoolPath & "framework\optional\input\BasicDocs\"
64 cWorkFile = cWorkFile & "basic" & hGetSuffix( cFileFormat )
65 cWorkFile = convertpath( cWorkFile )
66 cWorkFile = convertToURL( cWorkFile )
68 dim iSecLevel as integer
71 ' We have quite a bunch of possible combinations here. Some trigger a security warning
72 ' others do not. Depending on the security level we either get no warning at all, the
73 ' "classic" Security Warning or a message that the macros will not be executed (Blocked)
75 ' |---------------------------------------------------------|
76 ' | Trusted | Security Level / Warning displayed |
77 ' | Path | Low | Medium | High | Very High |
78 ' |---------------------------------------------------------|
79 ' | Yes*) | No | No | No | No |
80 ' |---------------------------------------------------------|
81 ' | No | No | Yes | Blocked | Blocked |
82 ' |---------------------------------------------------------|
83 ' *) Covered by test "f_sec_trusted_path.bas"
85 '///+<li>Cycle through all four security levels and load a document with macro</li>
87 for iSecLevel = 0 to 3
89 '///+<li>Set the macro security level</li>
91 hSetMacroSecurityAPI( iSecLevel )
92 FileOpen( "URL", cWorkFile, "FrameName", "_default" )
93 '///+<li>Load a file from ..\framework\optional\input\BasicDocs\</li>
96 '///+<li>For security level &eq; 0: Macro should be executed</li>
97 case 0 : brc = hIdentifyExecutedMacro()
99 if ( gApplication = "MATH" ) then
100 qaerrorlog( "#i68291# Math document forgets eventbinding" )
102 qaerrorlog( "#i53711# Macro was not found/executed" )
106 '///+<li>For security level &eq; 1: Macro should be executed after security warning</li>
107 case 1 : brc = hAllowMacroExecution()
109 warnlog( "Macro execution warning missing, chek the file/security settings" )
111 brc = hIdentifyExecutedMacro()
113 if ( gApplication = "MATH" ) then
114 qaerrorlog( "#i68291# Math document forgets eventbinding" )
116 qaerrorlog( "#i53711# Macro was not found/executed" )
117 'warnlog( "#i65885# - CWS Warnings01/Macro not executed on load" )
121 '///+<li>For security level &eq; 2: Macro should *not* be executed (it is not in trusted path)</li>
122 case 2 : brc = hHandleActivesOnLoad( 1 , 1 )
124 qaerrorlog( "#i53710# unexpected second messagebox" )
126 brc = hIdentifyExecutedMacro()
128 warnlog( "Macro was executed" )
131 '///+<li>For security level &eq; 3: Macro should *never* be executed</li>
132 case 3 : brc = hHandleActivesOnLoad( 1 , 0 )
133 brc = hIdentifyExecutedMacro()
135 warnlog( "Macro was executed" )
140 brc = hDestroyDocument()
145 '///+<li>Reset macro security level to default (High)</li>
146 hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_DEFAULT )
151 '*******************************************************************************
153 function hIdentifyExecutedMacro() as boolean
155 '///<h3>Function to identify the macro just being executed</h3>
156 '///This is a tiny helper function that compares the string from the message-
157 '///+box with a reference - TTMacro3 - and returns TRUE if the macro is the
158 '///+ correct one. FALSE in any other case.
160 dim cMessage as string
161 const CFN = "hIdentifyExecutedMacro::"
166 if ( active.exists( 3 ) ) then
168 cMessage = active.getText()
170 if ( cMessage = "TTMacro3" ) then
171 printlog( CFN & "The Macro has been executed" )
172 hIdentifyExecutedMacro() = true
175 warnlog( CFN & "The WRONG macro/dialog is open" )
176 hIdentifyExecutedMacro() = false
177 hHandleActivesOnLoad( 0 , 2 )
182 printlog( CFN & "No macro/dialog is open" )
183 hIdentifyExecutedMacro() = false