upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-08-15 15:17:39 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-08-15 15:53:59 +0100
commit28a37393ee62e3b53dad69d58810f72151bd58c2 (patch)
tree834224a4b2c3965878a03fd7ffc5fcccc223918e /test_utils/src
parentb7f48324a02093d0214b6788e8d7005569a08145 (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/src')
-rw-r--r--test_utils/src/lib.rs20
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};
12use futures::{executor::block_on, future::join_all}; 12use futures::{executor::block_on, future::join_all};
13use git::GitTestRepo; 13use git::GitTestRepo;
14use git2::{Signature, Time}; 14use git2::{Signature, Time};
15use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; 15use nostr::{self, Kind, Tag, event::EventId, nips::nip65::RelayMetadata};
16use nostr_database::NostrDatabase; 16use nostr_database::NostrDatabase;
17use nostr_lmdb::NostrLMDB; 17use nostr_lmdb::NostrLMDB;
18use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json}; 18use 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
1200pub 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
1200pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; 1218pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t";
1201pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; 1219pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f";
1202pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; 1220pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c";