Forge-web page tests share their fixtures and merge into tables
Browse files at this commitd052c078f11f3b8eff298753f063439e9da90384Parent: 9d64853- test
- forge-web page tests share their fixtures and merge into tables
4 changed files +93 -160
- crates/forge-web/src/pages/notifications.rs +17 -37
- crates/forge-web/src/pages/repo_mirrors.rs +54 -70
- crates/forge-web/src/pages/repo_settings_live_tests.rs +15 -29
- crates/forge-web/src/pages/repo_webhooks.rs +7 -24
crates/forge-web/src/pages/notifications.rsmodified+17 -37
| @@ -1311,25 +1311,14 @@ mod tests { | |||
| 1311 | assert!(page.body.contains("Mark all as read")); | 1311 | assert!(page.body.contains("Mark all as read")); |
| 1312 | } | 1312 | } |
| 1313 | 1313 | ||
| 1314 | + /// Another user cannot open or mark read a row that is not theirs. The owner's open redirects | ||
| 1315 | + /// to the issue and marks the row read. | ||
| 1314 | #[tokio::test] | 1316 | #[tokio::test] |
| 1315 | - async fn open_marks_read_and_redirects_to_the_issue() { | 1317 | + async fn another_users_notification_is_404_and_the_owner_opens_it() { |
| 1316 | - let site = site().await; | ||
| 1317 | - let w = world(&site, Visibility::Public).await; | ||
| 1318 | - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; | ||
| 1319 | - notify(&site, &w, Reason::Comment).await; | ||
| 1320 | - let id = first_note_id(&site, &w.bob.id).await; | ||
| 1321 | - | ||
| 1322 | - let res = get(&site, &format!("/notifications/{id}/open"), Some(&cookie)).await; | ||
| 1323 | - assert_eq!(res.status, 303); | ||
| 1324 | - assert_eq!(res.location.as_deref(), Some("/tahinli/demo/issues/1")); | ||
| 1325 | - assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); | ||
| 1326 | - } | ||
| 1327 | - | ||
| 1328 | - #[tokio::test] | ||
| 1329 | - async fn another_users_notification_is_404() { | ||
| 1330 | let site = site().await; | 1318 | let site = site().await; |
| 1331 | let w = world(&site, Visibility::Public).await; | 1319 | let w = world(&site, Visibility::Public).await; |
| 1332 | let tahinli_cookie = sign_in(&site.store, &w.tahinli.id, "tahinli-token").await; | 1320 | let tahinli_cookie = sign_in(&site.store, &w.tahinli.id, "tahinli-token").await; |
| 1321 | + let bob_cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; | ||
| 1333 | notify(&site, &w, Reason::Comment).await; | 1322 | notify(&site, &w, Reason::Comment).await; |
| 1334 | let id = first_note_id(&site, &w.bob.id).await; | 1323 | let id = first_note_id(&site, &w.bob.id).await; |
| 1335 | 1324 | ||
| @@ -1351,6 +1340,12 @@ mod tests { | |||
| 1351 | .await; | 1340 | .await; |
| 1352 | assert_eq!(read.status, 303); | 1341 | assert_eq!(read.status, 303); |
| 1353 | assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 1); | 1342 | assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 1); |
| 1343 | + | ||
| 1344 | + // Bob opens his own row: it redirects to the issue and marks the row read. | ||
| 1345 | + let res = get(&site, &format!("/notifications/{id}/open"), Some(&bob_cookie)).await; | ||
| 1346 | + assert_eq!(res.status, 303); | ||
| 1347 | + assert_eq!(res.location.as_deref(), Some("/tahinli/demo/issues/1")); | ||
| 1348 | + assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); | ||
| 1354 | } | 1349 | } |
| 1355 | 1350 | ||
| 1356 | #[tokio::test] | 1351 | #[tokio::test] |
| @@ -1365,13 +1360,6 @@ mod tests { | |||
| 1365 | assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); | 1360 | assert_eq!(site.store.unread_count(&w.bob.id).await.expect("count"), 0); |
| 1366 | } | 1361 | } |
| 1367 | 1362 | ||
| 1368 | - #[tokio::test] | ||
| 1369 | - async fn the_stream_needs_a_session() { | ||
| 1370 | - let site = site().await; | ||
| 1371 | - let res = get(&site, "/notifications/stream", None).await; | ||
| 1372 | - assert_eq!(res.status, 401); | ||
| 1373 | - } | ||
| 1374 | - | ||
| 1375 | #[tokio::test] | 1363 | #[tokio::test] |
| 1376 | async fn the_stream_sends_the_count_then_each_change() { | 1364 | async fn the_stream_sends_the_count_then_each_change() { |
| 1377 | let site = site().await; | 1365 | let site = site().await; |
| @@ -1423,7 +1411,7 @@ mod tests { | |||
| 1423 | } | 1411 | } |
| 1424 | 1412 | ||
| 1425 | #[tokio::test] | 1413 | #[tokio::test] |
| 1426 | - async fn subscription_toggle_on_an_issue() { | 1414 | + async fn subscription_toggles_on_an_issue_and_unknown_pull_is_404() { |
| 1427 | let site = site().await; | 1415 | let site = site().await; |
| 1428 | let w = world(&site, Visibility::Public).await; | 1416 | let w = world(&site, Visibility::Public).await; |
| 1429 | let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; | 1417 | let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; |
| @@ -1461,13 +1449,8 @@ mod tests { | |||
| 1461 | .await | 1449 | .await |
| 1462 | .expect("sub"); | 1450 | .expect("sub"); |
| 1463 | assert_eq!(sub, Some((SubState::Ignored, Reason::Subscribed))); | 1451 | assert_eq!(sub, Some((SubState::Ignored, Reason::Subscribed))); |
| 1464 | - } | ||
| 1465 | 1452 | ||
| 1466 | - #[tokio::test] | 1453 | + // A pull request number that does not exist is a 404 on the pulls subscription. |
| 1467 | - async fn pull_subscription_404_for_unknown_number() { | ||
| 1468 | - let site = site().await; | ||
| 1469 | - let w = world(&site, Visibility::Public).await; | ||
| 1470 | - let cookie = sign_in(&site.store, &w.bob.id, "bob-token").await; | ||
| 1471 | let res = post( | 1454 | let res = post( |
| 1472 | &site, | 1455 | &site, |
| 1473 | "/tahinli/demo/pulls/1/subscription", | 1456 | "/tahinli/demo/pulls/1/subscription", |
| @@ -1515,12 +1498,14 @@ mod tests { | |||
| 1515 | } | 1498 | } |
| 1516 | 1499 | ||
| 1517 | #[tokio::test] | 1500 | #[tokio::test] |
| 1518 | - async fn anonymous_viewer_is_redirected_to_login() { | 1501 | + async fn anonymous_viewers_are_sent_to_login_and_the_stream_needs_a_session() { |
| 1519 | let site = site().await; | 1502 | let site = site().await; |
| 1520 | let _w = world(&site, Visibility::Public).await; | 1503 | let _w = world(&site, Visibility::Public).await; |
| 1521 | let res = get(&site, "/notifications", None).await; | 1504 | let res = get(&site, "/notifications", None).await; |
| 1522 | assert_eq!(res.status, 303); | 1505 | assert_eq!(res.status, 303); |
| 1523 | assert!(res.location.unwrap_or_default().starts_with("/login")); | 1506 | assert!(res.location.unwrap_or_default().starts_with("/login")); |
| 1507 | + let stream = get(&site, "/notifications/stream", None).await; | ||
| 1508 | + assert_eq!(stream.status, 401); | ||
| 1524 | } | 1509 | } |
| 1525 | 1510 | ||
| 1526 | #[tokio::test] | 1511 | #[tokio::test] |
| @@ -1546,7 +1531,7 @@ mod tests { | |||
| 1546 | } | 1531 | } |
| 1547 | 1532 | ||
| 1548 | #[tokio::test] | 1533 | #[tokio::test] |
| 1549 | - async fn discussion_reply_shows_in_inbox_and_open_marks_read() { | 1534 | + async fn discussion_replies_show_in_the_inbox_and_clear_by_open_or_mark_all() { |
| 1550 | let site = site().await; | 1535 | let site = site().await; |
| 1551 | let w = world(&site, Visibility::Public).await; | 1536 | let w = world(&site, Visibility::Public).await; |
| 1552 | // The world's issue takes number 1, so the discussion is #2. | 1537 | // The world's issue takes number 1, so the discussion is #2. |
| @@ -1589,12 +1574,8 @@ mod tests { | |||
| 1589 | site.store.unread_count(&w.tahinli.id).await.expect("count"), | 1574 | site.store.unread_count(&w.tahinli.id).await.expect("count"), |
| 1590 | 0 | 1575 | 0 |
| 1591 | ); | 1576 | ); |
| 1592 | - } | ||
| 1593 | 1577 | ||
| 1594 | - #[tokio::test] | 1578 | + // A second discussion, cleared by mark all read. |
| 1595 | - async fn discussion_rows_are_marked_read_by_mark_all() { | ||
| 1596 | - let site = site().await; | ||
| 1597 | - let w = world(&site, Visibility::Public).await; | ||
| 1598 | let discussion = site | 1579 | let discussion = site |
| 1599 | .store | 1580 | .store |
| 1600 | .create_discussion( | 1581 | .create_discussion( |
| @@ -1610,7 +1591,6 @@ mod tests { | |||
| 1610 | .add_discussion_comment(&discussion.id, &w.bob.id, None, "+1", false) | 1591 | .add_discussion_comment(&discussion.id, &w.bob.id, None, "+1", false) |
| 1611 | .await | 1592 | .await |
| 1612 | .expect("reply"); | 1593 | .expect("reply"); |
| 1613 | - let tahinli = sign_in(&site.store, &w.tahinli.id, "tahinli-token").await; | ||
| 1614 | assert_eq!( | 1594 | assert_eq!( |
| 1615 | site.store.unread_count(&w.tahinli.id).await.expect("count"), | 1595 | site.store.unread_count(&w.tahinli.id).await.expect("count"), |
| 1616 | 1 | 1596 | 1 |
crates/forge-web/src/pages/repo_mirrors.rsmodified+54 -70
| @@ -1149,11 +1149,14 @@ mod tests { | |||
| 1149 | assert_eq!(redacted_url("not a url"), "(unreadable URL)"); | 1149 | assert_eq!(redacted_url("not a url"), "(unreadable URL)"); |
| 1150 | } | 1150 | } |
| 1151 | 1151 | ||
| 1152 | + /// One seeded push mirror with a secret. Non-admins get 404 on every mirror route. The owner's | ||
| 1153 | + /// pages never render the secret or the query string, and the list follows the stored | ||
| 1154 | + /// Turkish language once that preference is set last. | ||
| 1152 | #[tokio::test] | 1155 | #[tokio::test] |
| 1153 | - async fn non_admins_get_not_found() { | 1156 | + async fn mirror_pages_hide_from_non_admins_and_redact_for_the_owner() { |
| 1154 | let dir = tempfile::tempdir().expect("tempdir"); | 1157 | let dir = tempfile::tempdir().expect("tempdir"); |
| 1155 | let (store, app, repo) = fixture(dir.path()).await; | 1158 | let (store, app, repo) = fixture(dir.path()).await; |
| 1156 | - let id = push_mirror(&store, &repo, None).await; | 1159 | + let id = push_mirror(&store, &repo, Some(b"hunter2-secret")).await; |
| 1157 | for token in ["bob-token", "carol-token"] { | 1160 | for token in ["bob-token", "carol-token"] { |
| 1158 | let (status, _, _) = send( | 1161 | let (status, _, _) = send( |
| 1159 | &app, | 1162 | &app, |
| @@ -1192,41 +1195,8 @@ mod tests { | |||
| 1192 | ) | 1195 | ) |
| 1193 | .await; | 1196 | .await; |
| 1194 | assert_eq!(status, 200); | 1197 | assert_eq!(status, 200); |
| 1195 | - } | ||
| 1196 | - | ||
| 1197 | - #[tokio::test] | ||
| 1198 | - async fn list_page_follows_the_stored_turkish_language() { | ||
| 1199 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1200 | - let (store, app, _repo) = fixture(dir.path()).await; | ||
| 1201 | - let tahinli = store | ||
| 1202 | - .user_by_username("tahinli") | ||
| 1203 | - .await | ||
| 1204 | - .expect("lookup") | ||
| 1205 | - .expect("tahinli"); | ||
| 1206 | - store | ||
| 1207 | - .set_ui_prefs(&tahinli.id, "auto", "tr") | ||
| 1208 | - .await | ||
| 1209 | - .expect("set language"); | ||
| 1210 | - let (status, _, body) = send( | ||
| 1211 | - &app, | ||
| 1212 | - "GET", | ||
| 1213 | - "/tahinli/proj/settings/mirrors", | ||
| 1214 | - &cookie_for("tahinli-token"), | ||
| 1215 | - &[], | ||
| 1216 | - ) | ||
| 1217 | - .await; | ||
| 1218 | - assert_eq!(status, 200, "{body}"); | ||
| 1219 | - assert!( | ||
| 1220 | - body.contains("<h2>Yansılar</h2>"), | ||
| 1221 | - "Turkish heading missing" | ||
| 1222 | - ); | ||
| 1223 | - } | ||
| 1224 | 1198 | ||
| 1225 | - #[tokio::test] | 1199 | + // The owner's list and edit pages hide the secret and the query string. |
| 1226 | - async fn secret_is_never_rendered_and_urls_are_redacted() { | ||
| 1227 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1228 | - let (store, app, repo) = fixture(dir.path()).await; | ||
| 1229 | - let id = push_mirror(&store, &repo, Some(b"hunter2-secret")).await; | ||
| 1230 | let cookie = cookie_for("tahinli-token"); | 1200 | let cookie = cookie_for("tahinli-token"); |
| 1231 | for uri in [ | 1201 | for uri in [ |
| 1232 | "/tahinli/proj/settings/mirrors".to_owned(), | 1202 | "/tahinli/proj/settings/mirrors".to_owned(), |
| @@ -1249,30 +1219,50 @@ mod tests { | |||
| 1249 | .expect("mirror") | 1219 | .expect("mirror") |
| 1250 | .has_secret | 1220 | .has_secret |
| 1251 | ); | 1221 | ); |
| 1222 | + | ||
| 1223 | + // Last, so the Turkish preference does not change the English checks above. | ||
| 1224 | + let tahinli = store | ||
| 1225 | + .user_by_username("tahinli") | ||
| 1226 | + .await | ||
| 1227 | + .expect("lookup") | ||
| 1228 | + .expect("tahinli"); | ||
| 1229 | + store | ||
| 1230 | + .set_ui_prefs(&tahinli.id, "auto", "tr") | ||
| 1231 | + .await | ||
| 1232 | + .expect("set language"); | ||
| 1233 | + let (status, _, body) = send( | ||
| 1234 | + &app, | ||
| 1235 | + "GET", | ||
| 1236 | + "/tahinli/proj/settings/mirrors", | ||
| 1237 | + &cookie, | ||
| 1238 | + &[], | ||
| 1239 | + ) | ||
| 1240 | + .await; | ||
| 1241 | + assert_eq!(status, 200, "{body}"); | ||
| 1242 | + assert!(body.contains("<h2>Yansılar</h2>"), "Turkish heading missing"); | ||
| 1252 | } | 1243 | } |
| 1253 | 1244 | ||
| 1245 | + /// The push form refuses a loopback destination and stores nothing, then adds a good mirror | ||
| 1246 | + /// that a sync-now makes due. | ||
| 1254 | #[tokio::test] | 1247 | #[tokio::test] |
| 1255 | - async fn loopback_url_is_rejected_by_the_form() { | 1248 | + async fn push_form_refuses_loopback_then_adds_and_syncs() { |
| 1256 | let dir = tempfile::tempdir().expect("tempdir"); | 1249 | let dir = tempfile::tempdir().expect("tempdir"); |
| 1257 | let (store, app, repo) = fixture(dir.path()).await; | 1250 | let (store, app, repo) = fixture(dir.path()).await; |
| 1251 | + let cookie = cookie_for("tahinli-token"); | ||
| 1252 | + | ||
| 1253 | + // A loopback destination is shown as an error and nothing is stored. | ||
| 1258 | let (status, _, body) = send( | 1254 | let (status, _, body) = send( |
| 1259 | &app, | 1255 | &app, |
| 1260 | "POST", | 1256 | "POST", |
| 1261 | "/tahinli/proj/settings/mirrors", | 1257 | "/tahinli/proj/settings/mirrors", |
| 1262 | - &cookie_for("tahinli-token"), | 1258 | + &cookie, |
| 1263 | &[("url", "https://127.0.0.1/remote.git"), ("interval", "480")], | 1259 | &[("url", "https://127.0.0.1/remote.git"), ("interval", "480")], |
| 1264 | ) | 1260 | ) |
| 1265 | .await; | 1261 | .await; |
| 1266 | - assert_eq!(status, 200); | 1262 | + assert_eq!(status, 200, "loopback form"); |
| 1267 | assert!(body.contains("destination not allowed"), "error not shown"); | 1263 | assert!(body.contains("destination not allowed"), "error not shown"); |
| 1268 | assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); | 1264 | assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); |
| 1269 | - } | ||
| 1270 | 1265 | ||
| 1271 | - #[tokio::test] | ||
| 1272 | - async fn add_push_mirror_then_sync_now_schedules_it() { | ||
| 1273 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1274 | - let (store, app, repo) = fixture(dir.path()).await; | ||
| 1275 | - let cookie = cookie_for("tahinli-token"); | ||
| 1276 | let (status, location, _) = send( | 1266 | let (status, location, _) = send( |
| 1277 | &app, | 1267 | &app, |
| 1278 | "POST", | 1268 | "POST", |
| @@ -1315,8 +1305,10 @@ mod tests { | |||
| 1315 | ); | 1305 | ); |
| 1316 | } | 1306 | } |
| 1317 | 1307 | ||
| 1308 | + /// One seeded mirror with a secret. An edit can clear the password and keep the stored URL. | ||
| 1309 | + /// Then delete needs the confirm box before it removes the mirror. | ||
| 1318 | #[tokio::test] | 1310 | #[tokio::test] |
| 1319 | - async fn edit_clears_the_password_on_request() { | 1311 | + async fn edit_clears_the_password_and_delete_needs_the_confirm_box() { |
| 1320 | let dir = tempfile::tempdir().expect("tempdir"); | 1312 | let dir = tempfile::tempdir().expect("tempdir"); |
| 1321 | let (store, app, repo) = fixture(dir.path()).await; | 1313 | let (store, app, repo) = fixture(dir.path()).await; |
| 1322 | let id = push_mirror(&store, &repo, Some(b"hunter2-secret")).await; | 1314 | let id = push_mirror(&store, &repo, Some(b"hunter2-secret")).await; |
| @@ -1341,13 +1333,7 @@ mod tests { | |||
| 1341 | mirror.url, "https://example.com/remote.git?token=abc123", | 1333 | mirror.url, "https://example.com/remote.git?token=abc123", |
| 1342 | "a blank URL keeps the stored one" | 1334 | "a blank URL keeps the stored one" |
| 1343 | ); | 1335 | ); |
| 1344 | - } | ||
| 1345 | 1336 | ||
| 1346 | - #[tokio::test] | ||
| 1347 | - async fn delete_needs_the_confirm_box() { | ||
| 1348 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1349 | - let (store, app, repo) = fixture(dir.path()).await; | ||
| 1350 | - let id = push_mirror(&store, &repo, None).await; | ||
| 1351 | let cookie = cookie_for("tahinli-token"); | 1337 | let cookie = cookie_for("tahinli-token"); |
| 1352 | let uri = format!("/tahinli/proj/settings/mirrors/{id}/delete"); | 1338 | let uri = format!("/tahinli/proj/settings/mirrors/{id}/delete"); |
| 1353 | let (status, _, _) = send(&app, "POST", &uri, &cookie, &[]).await; | 1339 | let (status, _, _) = send(&app, "POST", &uri, &cookie, &[]).await; |
| @@ -1382,10 +1368,25 @@ mod tests { | |||
| 1382 | run(&["update-ref", "refs/heads/main", &commit]); | 1368 | run(&["update-ref", "refs/heads/main", &commit]); |
| 1383 | } | 1369 | } |
| 1384 | 1370 | ||
| 1371 | + /// On an empty repo a pull mirror can be added, and only the owner may add one: non-admins | ||
| 1372 | + /// get 404 first and store nothing. | ||
| 1385 | #[tokio::test] | 1373 | #[tokio::test] |
| 1386 | - async fn pull_mirror_can_be_added_to_an_empty_repo() { | 1374 | + async fn pull_mirror_can_be_added_to_an_empty_repo_by_the_owner_only() { |
| 1387 | let dir = tempfile::tempdir().expect("tempdir"); | 1375 | let dir = tempfile::tempdir().expect("tempdir"); |
| 1388 | let (store, app, repo) = fixture(dir.path()).await; | 1376 | let (store, app, repo) = fixture(dir.path()).await; |
| 1377 | + for token in ["bob-token", "carol-token"] { | ||
| 1378 | + let (status, _, _) = send( | ||
| 1379 | + &app, | ||
| 1380 | + "POST", | ||
| 1381 | + "/tahinli/proj/settings/mirrors", | ||
| 1382 | + &cookie_for(token), | ||
| 1383 | + &[("direction", "pull"), ("url", REMOTE), ("interval", "60")], | ||
| 1384 | + ) | ||
| 1385 | + .await; | ||
| 1386 | + assert_eq!(status, 404, "pull add as {token}"); | ||
| 1387 | + } | ||
| 1388 | + assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); | ||
| 1389 | + | ||
| 1389 | let cookie = cookie_for("tahinli-token"); | 1390 | let cookie = cookie_for("tahinli-token"); |
| 1390 | let (status, _, body) = | 1391 | let (status, _, body) = |
| 1391 | send(&app, "GET", "/tahinli/proj/settings/mirrors", &cookie, &[]).await; | 1392 | send(&app, "GET", "/tahinli/proj/settings/mirrors", &cookie, &[]).await; |
| @@ -1468,21 +1469,4 @@ mod tests { | |||
| 1468 | assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); | 1469 | assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); |
| 1469 | } | 1470 | } |
| 1470 | 1471 | ||
| 1471 | - #[tokio::test] | ||
| 1472 | - async fn pull_mirror_add_is_404_for_non_admins() { | ||
| 1473 | - let dir = tempfile::tempdir().expect("tempdir"); | ||
| 1474 | - let (store, app, repo) = fixture(dir.path()).await; | ||
| 1475 | - for token in ["bob-token", "carol-token"] { | ||
| 1476 | - let (status, _, _) = send( | ||
| 1477 | - &app, | ||
| 1478 | - "POST", | ||
| 1479 | - "/tahinli/proj/settings/mirrors", | ||
| 1480 | - &cookie_for(token), | ||
| 1481 | - &[("direction", "pull"), ("url", REMOTE), ("interval", "60")], | ||
| 1482 | - ) | ||
| 1483 | - .await; | ||
| 1484 | - assert_eq!(status, 404, "pull add as {token}"); | ||
| 1485 | - } | ||
| 1486 | - assert!(store.list_mirrors(&repo.id).await.expect("list").is_empty()); | ||
| 1487 | - } | ||
| 1488 | } | 1472 | } |
crates/forge-web/src/pages/repo_settings_live_tests.rsmodified+15 -29
| @@ -83,23 +83,31 @@ async fn fixture(site: &Site) -> (String, String) { | |||
| 83 | (owner_cookie, reader_cookie) | 83 | (owner_cookie, reader_cookie) |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | +/// Who may open each live stream. The settings stream is admin-only. The security and transfer | ||
| 87 | +/// streams take the same page check as their pages: a reader gets in, anonymous does not. | ||
| 86 | #[tokio::test] | 88 | #[tokio::test] |
| 87 | -async fn the_settings_stream_is_for_admins_only() { | 89 | +async fn the_streams_check_who_may_open_them() { |
| 88 | let site = site().await; | 90 | let site = site().await; |
| 89 | let (owner_cookie, reader_cookie) = fixture(&site).await; | 91 | let (owner_cookie, reader_cookie) = fixture(&site).await; |
| 90 | 92 | ||
| 91 | let owner = get(&site, "/owner/proj/settings/live", Some(&owner_cookie)).await; | 93 | let owner = get(&site, "/owner/proj/settings/live", Some(&owner_cookie)).await; |
| 92 | - assert_eq!(owner.status().as_u16(), 200); | 94 | + assert_eq!(owner.status().as_u16(), 200, "settings: owner"); |
| 93 | assert_eq!( | 95 | assert_eq!( |
| 94 | owner.headers().get("content-type").unwrap(), | 96 | owner.headers().get("content-type").unwrap(), |
| 95 | - "text/event-stream" | 97 | + "text/event-stream", |
| 98 | + "settings: owner content type" | ||
| 96 | ); | 99 | ); |
| 97 | - | ||
| 98 | let reader = get(&site, "/owner/proj/settings/live", Some(&reader_cookie)).await; | 100 | let reader = get(&site, "/owner/proj/settings/live", Some(&reader_cookie)).await; |
| 99 | - assert_eq!(reader.status().as_u16(), 403); | 101 | + assert_eq!(reader.status().as_u16(), 403, "settings: reader"); |
| 100 | - | ||
| 101 | let anonymous = get(&site, "/owner/proj/settings/live", None).await; | 102 | let anonymous = get(&site, "/owner/proj/settings/live", None).await; |
| 102 | - assert_ne!(anonymous.status().as_u16(), 200); | 103 | + assert_ne!(anonymous.status().as_u16(), 200, "settings: anonymous"); |
| 104 | + | ||
| 105 | + for path in ["/owner/proj/security/live", "/owner/proj/transfer/live"] { | ||
| 106 | + let reader = get(&site, path, Some(&reader_cookie)).await; | ||
| 107 | + assert_eq!(reader.status().as_u16(), 200, "{path}: reader"); | ||
| 108 | + let anonymous = get(&site, path, None).await; | ||
| 109 | + assert_ne!(anonymous.status().as_u16(), 200, "{path}: anonymous"); | ||
| 110 | + } | ||
| 103 | } | 111 | } |
| 104 | 112 | ||
| 105 | #[tokio::test] | 113 | #[tokio::test] |
| @@ -126,28 +134,6 @@ async fn a_settings_write_wakes_the_open_settings_stream() { | |||
| 126 | assert_eq!(&changed[..], b"event: changed\ndata: 1\n\n"); | 134 | assert_eq!(&changed[..], b"event: changed\ndata: 1\n\n"); |
| 127 | } | 135 | } |
| 128 | 136 | ||
| 129 | -#[tokio::test] | ||
| 130 | -async fn the_security_stream_takes_the_security_page_check() { | ||
| 131 | - let site = site().await; | ||
| 132 | - let (_, reader_cookie) = fixture(&site).await; | ||
| 133 | - | ||
| 134 | - let reader = get(&site, "/owner/proj/security/live", Some(&reader_cookie)).await; | ||
| 135 | - assert_eq!(reader.status().as_u16(), 200); | ||
| 136 | - let anonymous = get(&site, "/owner/proj/security/live", None).await; | ||
| 137 | - assert_ne!(anonymous.status().as_u16(), 200); | ||
| 138 | -} | ||
| 139 | - | ||
| 140 | -#[tokio::test] | ||
| 141 | -async fn the_transfer_stream_takes_the_transfer_page_check() { | ||
| 142 | - let site = site().await; | ||
| 143 | - let (_, reader_cookie) = fixture(&site).await; | ||
| 144 | - | ||
| 145 | - let reader = get(&site, "/owner/proj/transfer/live", Some(&reader_cookie)).await; | ||
| 146 | - assert_eq!(reader.status().as_u16(), 200); | ||
| 147 | - let anonymous = get(&site, "/owner/proj/transfer/live", None).await; | ||
| 148 | - assert_ne!(anonymous.status().as_u16(), 200); | ||
| 149 | -} | ||
| 150 | - | ||
| 151 | #[tokio::test] | 137 | #[tokio::test] |
| 152 | async fn a_visibility_change_wakes_the_repo_owner_explore_and_the_repo() { | 138 | async fn a_visibility_change_wakes_the_repo_owner_explore_and_the_repo() { |
| 153 | let site = site().await; | 139 | let site = site().await; |
crates/forge-web/src/pages/repo_webhooks.rsmodified+7 -24
| @@ -1246,7 +1246,7 @@ mod tests { | |||
| 1246 | } | 1246 | } |
| 1247 | 1247 | ||
| 1248 | #[tokio::test] | 1248 | #[tokio::test] |
| 1249 | - async fn invalid_urls_and_empty_event_list_show_errors() { | 1249 | + async fn invalid_hook_forms_show_errors_and_store_nothing() { |
| 1250 | let tmp = tempfile::tempdir().expect("tempdir"); | 1250 | let tmp = tempfile::tempdir().expect("tempdir"); |
| 1251 | let fx = fixture(tmp.path()).await; | 1251 | let fx = fixture(tmp.path()).await; |
| 1252 | let cookie = cookie_for("tahinli-token"); | 1252 | let cookie = cookie_for("tahinli-token"); |
| @@ -1283,13 +1283,8 @@ mod tests { | |||
| 1283 | .expect("hooks") | 1283 | .expect("hooks") |
| 1284 | .is_empty() | 1284 | .is_empty() |
| 1285 | ); | 1285 | ); |
| 1286 | - } | ||
| 1287 | 1286 | ||
| 1288 | - #[tokio::test] | 1287 | + // A secret over 256 characters is refused too, and stores nothing. |
| 1289 | - async fn long_secret_is_refused() { | ||
| 1290 | - let tmp = tempfile::tempdir().expect("tempdir"); | ||
| 1291 | - let fx = fixture(tmp.path()).await; | ||
| 1292 | - let cookie = cookie_for("tahinli-token"); | ||
| 1293 | let long = "x".repeat(257); | 1288 | let long = "x".repeat(257); |
| 1294 | let mut fields = hook_fields(URL, &["ev_push"]); | 1289 | let mut fields = hook_fields(URL, &["ev_push"]); |
| 1295 | fields.push(("secret", long)); | 1290 | fields.push(("secret", long)); |
| @@ -1346,7 +1341,7 @@ mod tests { | |||
| 1346 | } | 1341 | } |
| 1347 | 1342 | ||
| 1348 | #[tokio::test] | 1343 | #[tokio::test] |
| 1349 | - async fn hook_of_another_repo_is_404() { | 1344 | + async fn hook_pages_are_repo_scoped_and_edit_and_delete_keep_their_rules() { |
| 1350 | let tmp = tempfile::tempdir().expect("tempdir"); | 1345 | let tmp = tempfile::tempdir().expect("tempdir"); |
| 1351 | let fx = fixture(tmp.path()).await; | 1346 | let fx = fixture(tmp.path()).await; |
| 1352 | let other = fx | 1347 | let other = fx |
| @@ -1381,12 +1376,8 @@ mod tests { | |||
| 1381 | .await; | 1376 | .await; |
| 1382 | assert_eq!(status, 404); | 1377 | assert_eq!(status, 404); |
| 1383 | assert!(fx.store.webhook(&hook.id).await.expect("lookup").is_some()); | 1378 | assert!(fx.store.webhook(&hook.id).await.expect("lookup").is_some()); |
| 1384 | - } | ||
| 1385 | 1379 | ||
| 1386 | - #[tokio::test] | 1380 | + // An edit with a blank secret keeps the stored one, and a typed one replaces it. |
| 1387 | - async fn edit_with_blank_secret_keeps_the_secret() { | ||
| 1388 | - let tmp = tempfile::tempdir().expect("tempdir"); | ||
| 1389 | - let fx = fixture(tmp.path()).await; | ||
| 1390 | let sealed = secret::seal(&KEY, b"old-secret").expect("seal"); | 1381 | let sealed = secret::seal(&KEY, b"old-secret").expect("seal"); |
| 1391 | let hook = fx | 1382 | let hook = fx |
| 1392 | .store | 1383 | .store |
| @@ -1438,12 +1429,8 @@ mod tests { | |||
| 1438 | .expect("secret"), | 1429 | .expect("secret"), |
| 1439 | "new-secret" | 1430 | "new-secret" |
| 1440 | ); | 1431 | ); |
| 1441 | - } | ||
| 1442 | 1432 | ||
| 1443 | - #[tokio::test] | 1433 | + // Delete needs the confirm box, then removes the hook. |
| 1444 | - async fn delete_needs_confirmation_then_removes_the_hook() { | ||
| 1445 | - let tmp = tempfile::tempdir().expect("tempdir"); | ||
| 1446 | - let fx = fixture(tmp.path()).await; | ||
| 1447 | let sealed = secret::seal(&KEY, b"s").expect("seal"); | 1434 | let sealed = secret::seal(&KEY, b"s").expect("seal"); |
| 1448 | let hook = fx | 1435 | let hook = fx |
| 1449 | .store | 1436 | .store |
| @@ -1473,7 +1460,7 @@ mod tests { | |||
| 1473 | } | 1460 | } |
| 1474 | 1461 | ||
| 1475 | #[tokio::test] | 1462 | #[tokio::test] |
| 1476 | - async fn delivery_body_is_escaped_on_the_hook_page() { | 1463 | + async fn delivery_bodies_are_escaped_and_redeliver_queues_one_more() { |
| 1477 | let tmp = tempfile::tempdir().expect("tempdir"); | 1464 | let tmp = tempfile::tempdir().expect("tempdir"); |
| 1478 | let fx = fixture(tmp.path()).await; | 1465 | let fx = fixture(tmp.path()).await; |
| 1479 | let sealed = secret::seal(&KEY, b"s").expect("seal"); | 1466 | let sealed = secret::seal(&KEY, b"s").expect("seal"); |
| @@ -1506,12 +1493,8 @@ mod tests { | |||
| 1506 | assert!(body.contains("<script>alert(1)"), "{body}"); | 1493 | assert!(body.contains("<script>alert(1)"), "{body}"); |
| 1507 | assert!(!body.contains("<script>alert(1)"), "{body}"); | 1494 | assert!(!body.contains("<script>alert(1)"), "{body}"); |
| 1508 | assert!(body.contains("issues: opened"), "{body}"); | 1495 | assert!(body.contains("issues: opened"), "{body}"); |
| 1509 | - } | ||
| 1510 | 1496 | ||
| 1511 | - #[tokio::test] | 1497 | + // Redelivering a delivery queues a second one for the same hook. |
| 1512 | - async fn redeliver_creates_a_new_delivery() { | ||
| 1513 | - let tmp = tempfile::tempdir().expect("tempdir"); | ||
| 1514 | - let fx = fixture(tmp.path()).await; | ||
| 1515 | let sealed = secret::seal(&KEY, b"s").expect("seal"); | 1498 | let sealed = secret::seal(&KEY, b"s").expect("seal"); |
| 1516 | let hook = fx | 1499 | let hook = fx |
| 1517 | .store | 1500 | .store |