File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
main/java/org/dependencytrack/persistence/jdbi
test/java/org/dependencytrack/persistence/jdbi Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 20
20
21
21
import org .jdbi .v3 .core .config .JdbiConfig ;
22
22
23
- import java .util .Collections ;
24
23
import java .util .Optional ;
25
24
import java .util .Set ;
26
25
29
28
*/
30
29
public class ApiRequestConfig implements JdbiConfig <ApiRequestConfig > {
31
30
32
- private Set <OrderingColumn > orderingAllowedColumns = Collections . emptySet () ;
31
+ private Set <OrderingColumn > orderingAllowedColumns ;
33
32
private String orderingAlwaysBy = "" ;
34
33
private String projectIdColumn = "\" PROJECT\" .\" ID\" " ;
35
34
@@ -39,7 +38,9 @@ public ApiRequestConfig() {
39
38
}
40
39
41
40
private ApiRequestConfig (final ApiRequestConfig that ) {
42
- this .orderingAllowedColumns = Set .copyOf (that .orderingAllowedColumns );
41
+ this .orderingAllowedColumns = that .orderingAllowedColumns != null
42
+ ? Set .copyOf (that .orderingAllowedColumns )
43
+ : that .orderingAllowedColumns ;
43
44
this .orderingAlwaysBy = that .orderingAlwaysBy ;
44
45
this .projectIdColumn = that .projectIdColumn ;
45
46
}
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ private void defineOrdering(final StatementContext ctx) {
101
101
}
102
102
103
103
final var config = ctx .getConfig (ApiRequestConfig .class );
104
+ if (config .orderingAllowedColumns () == null ) {
105
+ return ;
106
+ }
104
107
if (config .orderingAllowedColumns ().isEmpty ()) {
105
108
throw new IllegalArgumentException ("Ordering is not allowed" );
106
109
}
Original file line number Diff line number Diff line change 35
35
import org .junit .Test ;
36
36
37
37
import java .sql .PreparedStatement ;
38
+ import java .util .Collections ;
38
39
import java .util .List ;
39
40
import java .util .Set ;
40
41
import java .util .function .Consumer ;
@@ -135,8 +136,33 @@ public void testWithAlpineRequestOrderingWithoutAllowedColumns() {
135
136
/* orderDirection */ OrderDirection .DESCENDING
136
137
);
137
138
139
+ useJdbiHandle (request , handle -> handle
140
+ .addCustomizer (inspectStatement (ctx -> {
141
+ assertThat (ctx .getRenderedSql ()).isEqualToIgnoringWhitespace ("""
142
+ SELECT 1 AS "valueA", 2 AS "valueB" FROM "PROJECT" WHERE TRUE
143
+ """ );
144
+
145
+ assertThat (ctx .getBinding ()).hasToString ("{}" );
146
+ }))
147
+ .createQuery (TEST_QUERY_TEMPLATE )
148
+ .mapTo (Integer .class )
149
+ .findOne ());
150
+ }
151
+
152
+ @ Test
153
+ public void testWithAlpineRequestOrderingEmptyAllowedColumns () {
154
+ final var request = new AlpineRequest (
155
+ /* principal */ null ,
156
+ /* pagination */ null ,
157
+ /* filter */ null ,
158
+ /* orderBy */ "value" ,
159
+ /* orderDirection */ OrderDirection .DESCENDING
160
+ );
161
+
138
162
assertThatExceptionOfType (IllegalArgumentException .class )
139
163
.isThrownBy (() -> useJdbiHandle (request , handle -> handle
164
+ .configure (ApiRequestConfig .class , config ->
165
+ config .setOrderingAllowedColumns (Collections .emptySet ()))
140
166
.createQuery (TEST_QUERY_TEMPLATE )
141
167
.mapTo (Integer .class )
142
168
.findOne ()))
You can’t perform that action at this time.
0 commit comments