@@ -61,32 +61,19 @@ public void setValues() {
61
61
config .addAllowedOriginPattern ("http://*.example.com" );
62
62
config .addAllowedHeader ("*" );
63
63
config .addAllowedMethod ("*" );
64
- config .addExposedHeader ("header1" );
65
- config .addExposedHeader ("header2" );
64
+ config .addExposedHeader ("*" );
66
65
config .setAllowCredentials (true );
67
66
config .setMaxAge (123L );
68
67
69
68
assertThat (config .getAllowedOrigins ()).containsExactly ("*" );
70
69
assertThat (config .getAllowedOriginPatterns ()).containsExactly ("http://*.example.com" );
71
70
assertThat (config .getAllowedHeaders ()).containsExactly ("*" );
72
71
assertThat (config .getAllowedMethods ()).containsExactly ("*" );
73
- assertThat (config .getExposedHeaders ()).containsExactly ("header1" , "header2 " );
72
+ assertThat (config .getExposedHeaders ()).containsExactly ("* " );
74
73
assertThat (config .getAllowCredentials ()).isTrue ();
75
74
assertThat (config .getMaxAge ()).isEqualTo (new Long (123 ));
76
75
}
77
76
78
- @ Test
79
- public void asteriskWildCardOnAddExposedHeader () {
80
- assertThatIllegalArgumentException ()
81
- .isThrownBy (() -> new CorsConfiguration ().addExposedHeader ("*" ));
82
- }
83
-
84
- @ Test
85
- public void asteriskWildCardOnSetExposedHeaders () {
86
- assertThatIllegalArgumentException ()
87
- .isThrownBy (() -> new CorsConfiguration ().setExposedHeaders (Collections .singletonList ("*" )));
88
- }
89
-
90
77
@ Test
91
78
public void combineWithNull () {
92
79
CorsConfiguration config = new CorsConfiguration ();
@@ -133,26 +120,30 @@ public void combineWithDefaultPermitValues() {
133
120
assertThat (combinedConfig .getAllowedOrigins ()).containsExactly ("https://domain.com" );
134
121
assertThat (combinedConfig .getAllowedHeaders ()).containsExactly ("header1" );
135
122
assertThat (combinedConfig .getAllowedMethods ()).containsExactly (HttpMethod .PUT .name ());
123
+ assertThat (combinedConfig .getExposedHeaders ()).isEmpty ();
136
124
137
125
combinedConfig = other .combine (config );
138
126
assertThat (combinedConfig ).isNotNull ();
139
127
assertThat (combinedConfig .getAllowedOrigins ()).containsExactly ("https://domain.com" );
140
128
assertThat (combinedConfig .getAllowedHeaders ()).containsExactly ("header1" );
141
129
assertThat (combinedConfig .getAllowedMethods ()).containsExactly (HttpMethod .PUT .name ());
130
+ assertThat (combinedConfig .getExposedHeaders ()).isEmpty ();
142
131
143
132
combinedConfig = config .combine (new CorsConfiguration ());
144
133
assertThat (config .getAllowedOrigins ()).containsExactly ("*" );
145
134
assertThat (config .getAllowedHeaders ()).containsExactly ("*" );
146
135
assertThat (combinedConfig ).isNotNull ();
147
136
assertThat (combinedConfig .getAllowedMethods ())
148
137
.containsExactly (HttpMethod .GET .name (), HttpMethod .HEAD .name (), HttpMethod .POST .name ());
138
+ assertThat (combinedConfig .getExposedHeaders ()).isEmpty ();
149
139
150
140
combinedConfig = new CorsConfiguration ().combine (config );
151
141
assertThat (config .getAllowedOrigins ()).containsExactly ("*" );
152
142
assertThat (config .getAllowedHeaders ()).containsExactly ("*" );
153
143
assertThat (combinedConfig ).isNotNull ();
154
144
assertThat (combinedConfig .getAllowedMethods ())
155
145
.containsExactly (HttpMethod .GET .name (), HttpMethod .HEAD .name (), HttpMethod .POST .name ());
146
+ assertThat (combinedConfig .getExposedHeaders ()).isEmpty ();
156
147
}
157
148
158
149
@ Test
@@ -196,6 +187,7 @@ public void combineWithAsteriskWildCard() {
196
187
CorsConfiguration config = new CorsConfiguration ();
197
188
config .addAllowedOrigin ("*" );
198
189
config .addAllowedHeader ("*" );
190
+ config .addExposedHeader ("*" );
199
191
config .addAllowedMethod ("*" );
200
192
config .addAllowedOriginPattern ("*" );
201
193
@@ -204,21 +196,26 @@ public void combineWithAsteriskWildCard() {
204
196
other .addAllowedOriginPattern ("http://*.company.com" );
205
197
other .addAllowedHeader ("header1" );
206
198
other .addExposedHeader ("header2" );
199
+ other .addAllowedHeader ("anotherHeader1" );
200
+ other .addExposedHeader ("anotherHeader2" );
207
201
other .addAllowedMethod (HttpMethod .PUT .name ());
208
202
209
203
CorsConfiguration combinedConfig = config .combine (other );
210
204
assertThat (combinedConfig ).isNotNull ();
211
205
assertThat (combinedConfig .getAllowedOrigins ()).containsExactly ("*" );
212
206
assertThat (combinedConfig .getAllowedOriginPatterns ()).containsExactly ("*" );
213
207
assertThat (combinedConfig .getAllowedHeaders ()).containsExactly ("*" );
208
+ assertThat (combinedConfig .getExposedHeaders ()).containsExactly ("*" );
214
209
assertThat (combinedConfig .getAllowedMethods ()).containsExactly ("*" );
215
210
216
211
combinedConfig = other .combine (config );
217
212
assertThat (combinedConfig ).isNotNull ();
218
213
assertThat (combinedConfig .getAllowedOrigins ()).containsExactly ("*" );
219
214
assertThat (combinedConfig .getAllowedOriginPatterns ()).containsExactly ("*" );
220
215
assertThat (combinedConfig .getAllowedHeaders ()).containsExactly ("*" );
216
+ assertThat (combinedConfig .getExposedHeaders ()).containsExactly ("*" );
221
217
assertThat (combinedConfig .getAllowedMethods ()).containsExactly ("*" );
218
+ assertThat (combinedConfig .getAllowedHeaders ()).containsExactly ("*" );
222
219
}
223
220
224
221
@ Test // SPR-14792
0 commit comments