5
5
6
6
package com .liferay .dynamic .data .mapping .web .internal .portlet .action ;
7
7
8
+ import com .liferay .dynamic .data .mapping .io .DDMFormDeserializer ;
9
+ import com .liferay .dynamic .data .mapping .io .DDMFormDeserializerDeserializeResponse ;
10
+ import com .liferay .dynamic .data .mapping .model .DDMForm ;
11
+ import com .liferay .dynamic .data .mapping .model .DDMFormField ;
8
12
import com .liferay .dynamic .data .mapping .render .DDMFormFieldRenderingContext ;
9
13
import com .liferay .portal .kernel .test .ReflectionTestUtil ;
10
14
import com .liferay .portal .kernel .theme .ThemeDisplay ;
17
21
import jakarta .servlet .http .HttpServletRequest ;
18
22
import jakarta .servlet .http .HttpServletResponse ;
19
23
24
+ import java .util .Collections ;
25
+
20
26
import org .junit .Assert ;
21
27
import org .junit .ClassRule ;
22
28
import org .junit .Test ;
@@ -86,6 +92,94 @@ public void testCreateDDMFormFieldRenderingContext() {
86
92
ddmFormFieldRenderingContext .getPortletNamespace ());
87
93
}
88
94
95
+ @ Test
96
+ public void testGetDDMFormField () {
97
+ HttpServletRequest httpServletRequest = Mockito .mock (
98
+ HttpServletRequest .class );
99
+
100
+ ThemeDisplay themeDisplay = Mockito .mock (ThemeDisplay .class );
101
+
102
+ Mockito .when (
103
+ themeDisplay .getLocale ()
104
+ ).thenReturn (
105
+ LocaleUtil .US
106
+ );
107
+
108
+ Mockito .when (
109
+ httpServletRequest .getAttribute (WebKeys .THEME_DISPLAY )
110
+ ).thenReturn (
111
+ themeDisplay
112
+ );
113
+
114
+ String script = "'\" ></option><img onerror=alert(123) src=x>" ;
115
+
116
+ Mockito .when (
117
+ httpServletRequest .getParameter ("definition" )
118
+ ).thenReturn (
119
+ script
120
+ );
121
+
122
+ Mockito .when (
123
+ httpServletRequest .getParameter ("fieldName" )
124
+ ).thenReturn (
125
+ HtmlUtil .escapeAttribute (script )
126
+ );
127
+
128
+ DDMFormField ddmFormFieldMock = Mockito .mock (DDMFormField .class );
129
+
130
+ Mockito .when (
131
+ ddmFormFieldMock .getName ()
132
+ ).thenReturn (
133
+ HtmlUtil .escapeAttribute (script )
134
+ );
135
+
136
+ DDMForm ddmForm = Mockito .mock (DDMForm .class );
137
+
138
+ Mockito .when (
139
+ ddmForm .getDDMFormFieldsMap (true )
140
+ ).thenReturn (
141
+ Collections .singletonMap (
142
+ HtmlUtil .escapeAttribute (script ), ddmFormFieldMock )
143
+ );
144
+
145
+ DDMFormDeserializerDeserializeResponse
146
+ ddmFormDeserializerDeserializeResponseMock = Mockito .mock (
147
+ DDMFormDeserializerDeserializeResponse .class );
148
+
149
+ Mockito .when (
150
+ ddmFormDeserializerDeserializeResponseMock .getDDMForm ()
151
+ ).thenReturn (
152
+ ddmForm
153
+ );
154
+
155
+ DDMFormDeserializer jsonDDMFormDeserializerMock = Mockito .mock (
156
+ DDMFormDeserializer .class );
157
+
158
+ Mockito .when (
159
+ jsonDDMFormDeserializerMock .deserialize (Mockito .any ())
160
+ ).thenReturn (
161
+ ddmFormDeserializerDeserializeResponseMock
162
+ );
163
+
164
+ RenderStructureFieldMVCResourceCommand
165
+ renderStructureFieldMVCResourceCommand =
166
+ new RenderStructureFieldMVCResourceCommand ();
167
+
168
+ ReflectionTestUtil .setFieldValue (
169
+ renderStructureFieldMVCResourceCommand , "_portal" , _portal );
170
+
171
+ ReflectionTestUtil .setFieldValue (
172
+ renderStructureFieldMVCResourceCommand , "_jsonDDMFormDeserializer" ,
173
+ jsonDDMFormDeserializerMock );
174
+
175
+ DDMFormField ddmFormField = ReflectionTestUtil .invoke (
176
+ renderStructureFieldMVCResourceCommand , "_getDDMFormField" ,
177
+ new Class <?>[] {HttpServletRequest .class }, httpServletRequest );
178
+
179
+ Assert .assertEquals (
180
+ HtmlUtil .escapeAttribute (script ), ddmFormField .getName ());
181
+ }
182
+
89
183
private final Portal _portal = Mockito .mock (Portal .class );
90
184
91
185
}
0 commit comments