Skip to content

Commit a4b745f

Browse files
authored
trustpub: Change PUT /api/v1/trusted_publishing/github_configs endpoint to POST (#11390)
`PUT` should be used for updates, not for resource creation. The conventional HTTP method for resource creation in REST APIs is `POST`.
1 parent 22b19b5 commit a4b745f

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/controllers/trustpub/github_configs/create/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod tests;
2323

2424
/// Create a new Trusted Publishing configuration for GitHub Actions.
2525
#[utoipa::path(
26-
put,
26+
post,
2727
path = "/api/v1/trusted_publishing/github_configs",
2828
security(("cookie" = [])),
2929
request_body = inline(json::CreateRequest),

src/controllers/trustpub/github_configs/create/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn run_test(payload: impl Into<Bytes>) -> (TestApp, Response<()>) {
4141
.await
4242
.unwrap();
4343

44-
(app, cookie_client.put::<()>(URL, payload).await)
44+
(app, cookie_client.post::<()>(URL, payload).await)
4545
}
4646

4747
inner(payload.into()).await
@@ -213,7 +213,7 @@ async fn test_unauthenticated() -> anyhow::Result<()> {
213213
}
214214
}))?;
215215

216-
let response = client.put::<()>(URL, body).await;
216+
let response = client.post::<()>(URL, body).await;
217217
assert_snapshot!(response.status(), @"403 Forbidden");
218218
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"this action requires authentication"}]}"#);
219219

@@ -243,7 +243,7 @@ async fn test_token_auth() -> anyhow::Result<()> {
243243
}
244244
}))?;
245245

246-
let response = token_client.put::<()>(URL, body).await;
246+
let response = token_client.post::<()>(URL, body).await;
247247
assert_snapshot!(response.status(), @"403 Forbidden");
248248
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"this action can only be performed on the crates.io website"}]}"#);
249249

@@ -267,7 +267,7 @@ async fn test_missing_crate() -> anyhow::Result<()> {
267267
}
268268
}))?;
269269

270-
let response = cookie_client.put::<()>(URL, body).await;
270+
let response = cookie_client.post::<()>(URL, body).await;
271271
assert_snapshot!(response.status(), @"404 Not Found");
272272
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"crate `foo` does not exist"}]}"#);
273273

@@ -299,7 +299,7 @@ async fn test_non_owner() -> anyhow::Result<()> {
299299
}
300300
}))?;
301301

302-
let response = other_client.put::<()>(URL, body).await;
302+
let response = other_client.post::<()>(URL, body).await;
303303
assert_snapshot!(response.status(), @"400 Bad Request");
304304
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"You are not an owner of this crate"}]}"#);
305305

@@ -331,7 +331,7 @@ async fn test_unknown_github_user() -> anyhow::Result<()> {
331331
}
332332
}))?;
333333

334-
let response = cookie_client.put::<()>(URL, body).await;
334+
let response = cookie_client.post::<()>(URL, body).await;
335335
assert_snapshot!(response.status(), @"400 Bad Request");
336336
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"Unknown GitHub user or organization"}]}"#);
337337

@@ -363,7 +363,7 @@ async fn test_github_error() -> anyhow::Result<()> {
363363
}
364364
}))?;
365365

366-
let response = cookie_client.put::<()>(URL, body).await;
366+
let response = cookie_client.post::<()>(URL, body).await;
367367
assert_snapshot!(response.status(), @"500 Internal Server Error");
368368
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"Internal Server Error"}]}"#);
369369

@@ -398,7 +398,7 @@ async fn test_unverified_email() -> anyhow::Result<()> {
398398
}
399399
}))?;
400400

401-
let response = cookie_client.put::<()>(URL, body).await;
401+
let response = cookie_client.post::<()>(URL, body).await;
402402
assert_snapshot!(response.status(), @"403 Forbidden");
403403
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"You must verify your email address to create a Trusted Publishing config"}]}"#);
404404

src/snapshots/crates_io__openapi__tests__openapi_snapshot-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4227,7 +4227,7 @@ expression: response.json()
42274227
"trusted_publishing"
42284228
]
42294229
},
4230-
"put": {
4230+
"post": {
42314231
"operationId": "create_trustpub_github_config",
42324232
"requestBody": {
42334233
"content": {

src/tests/krate/publish/trustpub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async fn test_full_flow() -> anyhow::Result<()> {
7777
}))?;
7878

7979
let url = "/api/v1/trusted_publishing/github_configs";
80-
let response = cookie_client.put::<()>(url, body).await;
80+
let response = cookie_client.post::<()>(url, body).await;
8181

8282
assert_json_snapshot!(response.json(), { ".github_config.created_at" => "[datetime]" }, @r#"
8383
{

0 commit comments

Comments
 (0)