Skip to content

Commit dd084f1

Browse files
authored
Fix DependencyTrack API request method (#30)
DT's sbom upload API supports POST for multipart/form-data and PUT for application/json. This patch changes the used method in the DT API call from POST to PUT, to match the passed headers and data. Also updates DESIGN.md to not mention the request method (it is an implementation detail). Signed-off-by: Lukas Puehringer <lukas.puehringer@eclipse-foundation.org>
1 parent 425a5c2 commit dd084f1

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

docs/DESIGN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ sequenceDiagram
5252
IdP->>PIA: 7. Return JWKs
5353
PIA->>PIA: 8. Authenticate
5454
Note over PIA: - Verify token<br/>- Match claims with projects settings
55-
PIA->>dp: 9. Post SBOM
55+
PIA->>dp: 9. Upload SBOM
5656
dp-->>PIA: Success
5757
PIA-->>Publisher: Success
5858
```
@@ -128,7 +128,7 @@ sequenceDiagram
128128

129129
- see 3.1.1. Token Verification and Authentication Flow
130130

131-
5. **SBOM Publishing**: PIA sends POST request to DependencyTrack:
131+
5. **SBOM Publishing**: PIA sends upload request to DependencyTrack:
132132

133133
- `Content-Type`: `application/json`
134134
- `X-Api-Key`: Use internally stored, DependencyTrack access token
@@ -194,7 +194,7 @@ Content-Type: application/json
194194
- Issuer not allowed
195195
- No matching project found for token claims
196196
- `422 Unprocessable Entity`: Missing Authorization header or invalid JSON
197-
- `502`: DependencyTrack post request failed
197+
- `502`: DependencyTrack upload request failed
198198
- `*`: Relay DependencyTrack status code
199199

200200

pia/dependencytrack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def upload_sbom(
2323
}
2424

2525
try:
26-
response = requests.post(
26+
response = requests.put(
2727
url,
2828
json=payload.to_dict(),
2929
headers=headers,

tests/test_dependencytrack.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ def dt_payload():
2525

2626

2727
class TestUploadSBOM:
28-
@patch("pia.dependencytrack.requests.post")
29-
def test_upload(self, mock_post, dt_payload):
28+
@patch("pia.dependencytrack.requests.put")
29+
def test_upload(self, mock_put, dt_payload):
3030
"""Test request and response."""
31-
mock_post.return_value = "mock_response"
31+
mock_put.return_value = "mock_response"
3232
result = upload_sbom(TEST_URL, TEST_API_KEY, dt_payload)
3333

3434
# Assert result is request response
3535
assert result == "mock_response"
3636

3737
# Assert request was made correctly
38-
mock_post.assert_called_once_with(
38+
mock_put.assert_called_once_with(
3939
"https://dt.example.com/api/v1/bom",
4040
json={
4141
"projectName": "test-product",
@@ -51,10 +51,10 @@ def test_upload(self, mock_post, dt_payload):
5151
},
5252
)
5353

54-
@patch("pia.dependencytrack.requests.post")
55-
def test_upload_request_exception(self, mock_post, dt_payload):
54+
@patch("pia.dependencytrack.requests.put")
55+
def test_upload_request_exception(self, mock_put, dt_payload):
5656
"""Test error handling."""
57-
mock_post.side_effect = requests.RequestException()
57+
mock_put.side_effect = requests.RequestException()
5858

5959
with pytest.raises(
6060
DependencyTrackError, match="Failed to upload SBOM to DependencyTrack"

0 commit comments

Comments
 (0)