@@ -18,8 +18,12 @@ fn run_helper(input: &str, env_vars: &[(&str, &str)]) -> std::process::Output {
1818 cmd. stdin ( Stdio :: piped ( ) )
1919 . stdout ( Stdio :: piped ( ) )
2020 . stderr ( Stdio :: piped ( ) )
21+ . current_dir ( std:: env:: temp_dir ( ) )
2122 . env_remove ( "NOSTR_PRIVATE_KEY" )
22- // Prevent git config on the test machine from supplying a keyfile.
23+ . env_remove ( "BUZZ_AUTH_TAG" )
24+ . env_remove ( "GIT_CONFIG_COUNT" )
25+ // Prevent git config on the test machine from supplying credentials.
26+ . env ( "GIT_CONFIG_GLOBAL" , "/dev/null" )
2327 . env ( "GIT_CONFIG_NOSYSTEM" , "1" )
2428 . env ( "HOME" , std:: env:: temp_dir ( ) ) ;
2529 for ( k, v) in env_vars {
@@ -116,6 +120,69 @@ fn happy_path() {
116120 assert ! ( event[ "tags" ] . is_array( ) , "event missing 'tags'" ) ;
117121}
118122
123+ /// A Buzz-managed agent must carry its NIP-OA owner attestation inside the
124+ /// signed NIP-98 event so the relay can admit it through the owner's membership.
125+ #[ test]
126+ fn includes_nip_oa_auth_tag_in_signed_event ( ) {
127+ let agent_keys = Keys :: generate ( ) ;
128+ let owner_keys = Keys :: generate ( ) ;
129+ let nsec = agent_keys. secret_key ( ) . to_bech32 ( ) . unwrap ( ) ;
130+ let auth_tag = serde_json:: to_string ( & [
131+ "auth" ,
132+ owner_keys. public_key ( ) . to_hex ( ) . as_str ( ) ,
133+ "" ,
134+ & "00" . repeat ( 64 ) ,
135+ ] )
136+ . expect ( "serialize auth tag" ) ;
137+
138+ let out = run_helper (
139+ & valid_input ( ) ,
140+ & [ ( "NOSTR_PRIVATE_KEY" , & nsec) , ( "BUZZ_AUTH_TAG" , & auth_tag) ] ,
141+ ) ;
142+ assert ! (
143+ out. status. success( ) ,
144+ "helper failed: {}" ,
145+ String :: from_utf8_lossy( & out. stderr)
146+ ) ;
147+
148+ let stdout = String :: from_utf8_lossy ( & out. stdout ) ;
149+ let credential = stdout
150+ . lines ( )
151+ . find_map ( |line| line. strip_prefix ( "credential=" ) )
152+ . expect ( "credential output" ) ;
153+ let event_json = base64:: engine:: general_purpose:: STANDARD
154+ . decode ( credential)
155+ . expect ( "base64 credential" ) ;
156+ let event: nostr:: Event = serde_json:: from_slice ( & event_json) . expect ( "NIP-98 event" ) ;
157+
158+ assert ! (
159+ event. verify( ) . is_ok( ) ,
160+ "auth tag must be covered by the event signature"
161+ ) ;
162+ assert ! ( event. tags. iter( ) . any( |tag| tag. as_slice( )
163+ == [
164+ "auth" ,
165+ owner_keys. public_key( ) . to_hex( ) . as_str( ) ,
166+ "" ,
167+ serde_json:: from_str:: <Vec <String >>( & auth_tag) . unwrap( ) [ 3 ] . as_str( ) ,
168+ ] ) ) ;
169+ }
170+
171+ /// A configured but malformed owner attestation must fail closed rather than
172+ /// silently authenticating the agent without delegation.
173+ #[ test]
174+ fn malformed_nip_oa_auth_tag_fails_closed ( ) {
175+ let nsec = fresh_nsec ( ) ;
176+ let out = run_helper (
177+ & valid_input ( ) ,
178+ & [ ( "NOSTR_PRIVATE_KEY" , & nsec) , ( "BUZZ_AUTH_TAG" , "not-json" ) ] ,
179+ ) ;
180+
181+ assert_eq ! ( out. status. code( ) , Some ( 1 ) ) ;
182+ assert ! ( String :: from_utf8_lossy( & out. stderr) . contains( "invalid NIP-OA auth tag" ) ) ;
183+ assert ! ( !String :: from_utf8_lossy( & out. stdout) . contains( "credential=" ) ) ;
184+ }
185+
119186/// Old git (no `capability[]=authtype` in input) → empty line on stdout, exit 0.
120187#[ test]
121188fn old_git_no_authtype_capability ( ) {
@@ -264,7 +331,10 @@ fn bad_keyfile_permissions() {
264331
265332 let out = run_helper (
266333 & valid_input ( ) ,
267- & [ ( "HOME" , git_config_dir. to_str ( ) . unwrap ( ) ) ] ,
334+ & [
335+ ( "HOME" , git_config_dir. to_str ( ) . unwrap ( ) ) ,
336+ ( "GIT_CONFIG_GLOBAL" , git_config_file. to_str ( ) . unwrap ( ) ) ,
337+ ] ,
268338 ) ;
269339
270340 // Clean up regardless of outcome.
0 commit comments