summaryrefslogtreecommitdiff
path: root/testautomation/framework/optional/includes/security_macrosecurity.inc
blob: 2b6a05d9fccaa58373754916d2c7f4e693eebf26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'/************************************************************************
'*
'*  owner : joerg.skottke@oracle.com
'*
'*  short description : Macros with all security-levels
'*
'\******************************************************************************

sub tMacroSecurityLevelsControlModule

    dim iApplication as integer

    for iApplication = 1 to 6

        printlog( "" )
        printlog( hNumericDocType( iApplication ) )
        call tMacroSecurityLevels( "current" )
        call tMacroSecurityLevels( "645" )

    next iApplication

end sub

'*******************************************************************************

testcase tMacroSecurityLevels( cFileFormat )

    printlog( "Check macro execution behavior for all macro security levels" )
    warnlog( "#i110184# - Documentbound macros not executed when loaded via API" )
    goto endsub

    dim cWorkFile as string
        cWorkFile = gTesttoolPath & "framework\optional\input\BasicDocs\"
        cWorkFile = cWorkFile & "basic" & hGetSuffix( cFileFormat )
        cWorkFile = convertpath( cWorkFile )
        cWorkFile = convertToURL( cWorkFile )

    dim iSecLevel as integer

    const EXPECTED_MESSAGECOUNT = 1
    const ALLOW_ONE_EXTRA_MESSAGEBOX = 1
    const ALLOW_NO_EXTRA_MESSAGEBOXES = 0
    
    ' We have quite a bunch of possible combinations here. Some trigger a security warning
    ' others do not. Depending on the security level we either get no warning at all, the
    ' "classic" Security Warning or a message that the macros will not be executed (Blocked)
        
    '         |---------------------------------------------------------|
    '         | Trusted |     Security Level / Warning displayed        |
    '         |  Path   |   Low     |  Medium   |   High    | Very High |
    '         |---------------------------------------------------------|
    '         |  Yes*)  |     No    |    No     |     No    |    No     |
    '         |---------------------------------------------------------|
    '         |   No    |     No    |    Yes    |  Blocked  |  Blocked  |
    '         |---------------------------------------------------------|
    ' *) Covered by test "f_sec_trusted_path.bas"
    
    printlog( "Load a document with macro for each of the four security levels" )
    for iSecLevel = GC_MACRO_SECURITY_LEVEL_LOW to GC_MACRO_SECURITY_LEVEL_VERYHIGH

        printlog( "Set macro security level to " & iSecLevel )
        hSetMacroSecurityAPI( iSecLevel )
        
        printlog( "Load document..." )
        hFileOpen( cWorkFile )
        
        printlog( "Check security level dependent behavior" )
        select case iSecLevel
        case GC_MACRO_SECURITY_LEVEL_LOW :

            if ( not hIdentifyExecutedMacro() ) then
                warnlog( "#i110184# - Macro was not executed" )
            endif

        case GC_MACRO_SECURITY_LEVEL_MEDIUM :

            if ( not hAllowMacroExecution() )   then
                warnlog( "#i110184# - Macro execution warning missing, check the file/security settings" )
            endif

            if ( not hIdentifyExecutedMacro() ) then
                warnlog( "#i110184# - Macro was not executed" )
            endif

        case GC_MACRO_SECURITY_LEVEL_HIGH :

            if ( not hHandleActivesOnLoad( EXPECTED_MESSAGECOUNT , ALLOW_ONE_EXTRA_MESSAGEBOX ) ) then
                warnlog( "#i53710# unexpected second messagebox" )
            endif

            if ( hIdentifyExecutedMacro() ) then
                warnlog( "Macro was executed" )
            endif

        case GC_MACRO_SECURITY_LEVEL_VERYHIGH :

            if ( not hHandleActivesOnLoad( EXPECTED_MESSAGECOUNT , ALLOW_NO_EXTRA_MESSAGEBOXES ) ) then
                warnlog( "#i53710# unexpected second messagebox" )
            endif

            if ( hIdentifyExecutedMacro() ) then
                warnlog( "Macro was executed" )
            endif

        end select

        printlog( "Close document" )
        hDestroyDocument()

    next iSecLevel

    printlog( "Reset security level to default" )
    hSetMacroSecurityAPI( GC_MACRO_SECURITY_LEVEL_DEFAULT )

endcase

'*******************************************************************************

function hIdentifyExecutedMacro() as boolean


    dim cMessage as string
    const CFN = "hIdentifyExecutedMacro::"

    sleep( 1 )

    kontext "active"
    if ( active.exists( 3 ) ) then

        cMessage = active.getText()
        
        if ( cMessage = "TTMacro3" ) then
            printlog( CFN & "The Macro has been executed" )
            hIdentifyExecutedMacro() = true
            active.ok()
        else
            warnlog( CFN & "The WRONG macro/dialog is open" )
            hIdentifyExecutedMacro() = false
            hHandleActivesOnLoad( 0 , 2 )
        endif
        
    else
    
        printlog( CFN & "No macro/dialog is open" )
        hIdentifyExecutedMacro() = false
        
    endif
    
end function