diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-15 15:17:39 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-15 15:53:59 +0100 |
| commit | 28a37393ee62e3b53dad69d58810f72151bd58c2 (patch) | |
| tree | 834224a4b2c3965878a03fd7ffc5fcccc223918e /test_utils | |
| parent | b7f48324a02093d0214b6788e8d7005569a08145 (diff) | |
feat(remote): list proposals as `refs/pr-by-id/*`
This branch name cannot be attacked by brute forcing a
shorthand event id like refs/pr/<branch-name(<shorthand-event-id)
can.
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/lib.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 3e348a4..8d81efe 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -12,7 +12,7 @@ use dialoguer::theme::{ColorfulTheme, Theme}; | |||
| 12 | use futures::{executor::block_on, future::join_all}; | 12 | use futures::{executor::block_on, future::join_all}; |
| 13 | use git::GitTestRepo; | 13 | use git::GitTestRepo; |
| 14 | use git2::{Signature, Time}; | 14 | use git2::{Signature, Time}; |
| 15 | use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; | 15 | use nostr::{self, Kind, Tag, event::EventId, nips::nip65::RelayMetadata}; |
| 16 | use nostr_database::NostrDatabase; | 16 | use nostr_database::NostrDatabase; |
| 17 | use nostr_lmdb::NostrLMDB; | 17 | use nostr_lmdb::NostrLMDB; |
| 18 | use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json}; | 18 | use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json}; |
| @@ -1197,6 +1197,24 @@ pub fn get_proposal_branch_name_from_events( | |||
| 1197 | bail!("failed to find proposal root with branch-name tag matching title") | 1197 | bail!("failed to find proposal root with branch-name tag matching title") |
| 1198 | } | 1198 | } |
| 1199 | 1199 | ||
| 1200 | pub fn get_proposal_id_from_branch_name( | ||
| 1201 | events: &[nostr::Event], | ||
| 1202 | branch_name_in_event: &str, | ||
| 1203 | ) -> Result<EventId> { | ||
| 1204 | let mut events = events.to_owned(); | ||
| 1205 | events.reverse(); | ||
| 1206 | for event in events { | ||
| 1207 | if event | ||
| 1208 | .tags | ||
| 1209 | .iter() | ||
| 1210 | .any(|t| t.as_slice()[0].eq("branch-name") && t.as_slice()[1].eq(branch_name_in_event)) | ||
| 1211 | { | ||
| 1212 | return Ok(event.id); | ||
| 1213 | } | ||
| 1214 | } | ||
| 1215 | bail!("failed to find proposal root with branch-name tag matching title") | ||
| 1216 | } | ||
| 1217 | |||
| 1200 | pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; | 1218 | pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; |
| 1201 | pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; | 1219 | pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; |
| 1202 | pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; | 1220 | pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; |