Skip to content

Commit 0ac51f7

Browse files
committed
Add support for testing extensions
Allows extensions to provide functionality that lets administrators verify whether a given configuration is likely to work. The primary use case here being a "test" button in the UI. Having an easy way to test configuration provides much better UX, as the lack of feedback without it can cause a lot of frustration. Especially when the to-be-configured functionality only runs on schedule and can't be triggered manually at all. Signed-off-by: nscuro <nscuro@protonmail.com>
1 parent 6e5a07a commit 0ac51f7

21 files changed

Lines changed: 910 additions & 50 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
type: string
18+
enum:
19+
- PASSED
20+
- FAILED
21+
- SKIPPED
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
type: object
18+
properties:
19+
name:
20+
type: string
21+
example: "connection"
22+
status:
23+
$ref: "./extension-test-check-status.yaml"
24+
message:
25+
type: string
26+
example: "Connection failed"
27+
detail:
28+
type: string
29+
required:
30+
- name
31+
- status
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
type: object
18+
properties:
19+
config:
20+
type: object
21+
additionalProperties: true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
type: object
18+
properties:
19+
checks:
20+
type: array
21+
items:
22+
$ref: "./extension-test-check.yaml"
23+
required:
24+
- checks

api/src/main/openapi/openapi.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ paths:
130130
$ref: "./paths/extension-points__name__extensions__name__config.yaml"
131131
/extension-points/{extensionPointName}/extensions/{extensionName}/config-schema:
132132
$ref: "./paths/extension-points__name__extensions__name__config-schema.yaml"
133+
/extension-points/{extensionPointName}/extensions/{extensionName}/test:
134+
$ref: "./paths/extension-points__name__extensions__name__test.yaml"
133135
/metrics/portfolio/current:
134136
$ref: "./paths/metrics_portfolio_current.yaml"
135137
/metrics/vulnerabilities:

api/src/main/openapi/paths/components.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ post:
3434
content:
3535
application/problem+json:
3636
schema:
37-
oneOf:
37+
anyOf:
3838
- $ref: "../components/schemas/invalid-request-problem-details.yaml"
3939
- $ref: "../components/schemas/problem-details.yaml"
4040
"401":

api/src/main/openapi/paths/extension-points__name__extensions__name__config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ put:
5858
description: |-
5959
Updates the configuration of an extension.
6060
61+
**Do not use clear text credentials in the supplied config**.
62+
Fields annotated with `x-secret-ref` in the config schema expect
63+
a name of a managed secret, which is resolved internally by the API.
64+
6165
Requires the `SYSTEM_CONFIGURATION` or `SYSTEM_CONFIGURATION_READ` permission.
6266
tags:
6367
- Extensions
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
post:
18+
operationId: testExtension
19+
summary: Test extension
20+
description: |-
21+
Tests an extension.
22+
23+
If the extension is configurable (i.e. `/config-schema` returns status `200`),
24+
a valid configuration **must** be provided in the test request.
25+
The configuration is validated against the applicable JSON schema.
26+
27+
**Do not use clear text credentials in the supplied config**.
28+
Fields annotated with `x-secret-ref` in the config schema expect
29+
a name of a managed secret, which is resolved internally by the API.
30+
31+
Test results contain one or more checks, each of which can have a status of
32+
`PASSED`, `FAILED`, or `SKIPPED`. If *at least one* check is `FAILED`,
33+
the entire test should be considered `FAILED`.
34+
35+
Requires the `SYSTEM_CONFIGURATION` or `SYSTEM_CONFIGURATION_UPDATE` permission.
36+
tags:
37+
- Extensions
38+
parameters:
39+
- name: extensionPointName
40+
description: Name of the extension point
41+
in: path
42+
required: true
43+
schema:
44+
type: string
45+
- name: extensionName
46+
description: Name of the extension
47+
in: path
48+
required: true
49+
schema:
50+
type: string
51+
requestBody:
52+
required: true
53+
content:
54+
application/json:
55+
schema:
56+
$ref: "../components/schemas/extensions/test-extension-request.yaml"
57+
responses:
58+
"200":
59+
description: Test result
60+
content:
61+
application/json:
62+
schema:
63+
$ref: "../components/schemas/extensions/test-extension-response.yaml"
64+
"400":
65+
description: Bad Request
66+
content:
67+
application/problem+json:
68+
schema:
69+
anyOf:
70+
- $ref: "../components/schemas/json-schema-validation-problem-details.yaml"
71+
- $ref: "../components/schemas/problem-details.yaml"
72+
"401":
73+
$ref: "../components/responses/generic-unauthorized-error.yaml"
74+
"403":
75+
$ref: "../components/responses/generic-forbidden-error.yaml"
76+
"404":
77+
$ref: "../components/responses/generic-not-found-error.yaml"
78+
default:
79+
$ref: "../components/responses/generic-error.yaml"

api/src/main/openapi/paths/secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ post:
7373
content:
7474
application/problem+json:
7575
schema:
76-
oneOf:
76+
anyOf:
7777
- $ref: "../components/schemas/invalid-request-problem-details.yaml"
7878
- $ref: "../components/schemas/problem-details.yaml"
7979
"401":

api/src/main/openapi/paths/secrets__name_.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ patch:
8181
content:
8282
application/problem+json:
8383
schema:
84-
oneOf:
84+
anyOf:
8585
- $ref: "../components/schemas/invalid-request-problem-details.yaml"
8686
- $ref: "../components/schemas/problem-details.yaml"
8787
"401":
@@ -120,7 +120,7 @@ delete:
120120
content:
121121
application/problem+json:
122122
schema:
123-
oneOf:
123+
anyOf:
124124
- $ref: "../components/schemas/invalid-request-problem-details.yaml"
125125
- $ref: "../components/schemas/problem-details.yaml"
126126
"401":

0 commit comments

Comments
 (0)