1717//! tests use: unset under CI is a FAILURE, unset locally skips only this scenario), one durable
1818//! scenario per door — upsert, point read, a child chain, single-use token redemption, delete.
1919//!
20- //! RED ARMS, in the same test and always run (no database needed): the library asked for as
20+ //! RED ARMS, each its own test and always run (no database needed): the library asked for as
2121//! `kind: secret` is refused before any slot is called, and DIFFERENT bytes (the cdylib with its
2222//! object magic broken) are not the store — so the comparison above cannot pass vacuously.
2323
@@ -137,31 +137,11 @@ fn transcript(
137137 } )
138138}
139139
140- /// The Postgres store behaves as ONE store through either door — and the RED arms show the
141- /// comparison is not vacuous.
140+ /// The Postgres store behaves as ONE store through either door ( the RED arms are their own tests
141+ /// below, so the comparison is not vacuous) .
142142#[ test]
143143fn the_linked_and_the_dropped_in_postgres_store_are_one_store ( ) {
144144 let live = live_url ( ) ;
145- let lib = common:: cdylib ( ) ;
146-
147- // RED ARM 1 — RUN FIRST: DIFFERENT bytes (the object's magic broken) are not the store. It must
148- // run before ANY good image is loaded from a path the loader may have mapped already.
149- let mut foreign = std:: fs:: read ( & lib) . expect ( "read the cdylib" ) ;
150- foreign[ ..4 ] . copy_from_slice ( b"XXXX" ) ;
151- let dir = std:: env:: temp_dir ( ) . join ( format ! ( "store-postgres-conf-{}" , std:: process:: id( ) ) ) ;
152- let _ = std:: fs:: remove_dir_all ( & dir) ;
153- std:: fs:: create_dir_all ( & dir) . unwrap ( ) ;
154- let broken = dir. join ( lib. file_name ( ) . unwrap ( ) ) ;
155- std:: fs:: write ( & broken, & foreign) . unwrap ( ) ;
156- let red = match common:: dropped_at ( & broken, "{}" ) {
157- Ok ( _) => panic ! ( "foreign bytes opened as the store" ) ,
158- Err ( e) => e,
159- } ;
160- assert ! (
161- !red. contains( "requires a \" url\" " ) ,
162- "foreign bytes cannot speak the store's own refusal: {red}"
163- ) ;
164-
165145 let linked = transcript ( "linked" , & common:: linked, live. as_deref ( ) ) ;
166146 let dropped_in = transcript ( "dropped" , & common:: dropped, live. as_deref ( ) ) ;
167147 assert_eq ! ( linked, dropped_in, "the two doors are not one store" ) ;
@@ -197,8 +177,38 @@ fn the_linked_and_the_dropped_in_postgres_store_are_one_store() {
197177 } )
198178 ) ;
199179 }
180+ }
181+
182+ /// RED ARM 1: DIFFERENT bytes (the object's magic broken) are not the store, so the both-ways
183+ /// comparison cannot pass vacuously. The broken image is its own file in its own directory, so it
184+ /// is never a path a good image was mapped from. No database needed.
185+ #[ test]
186+ fn a_cdylib_with_broken_magic_is_not_the_store ( ) {
187+ let lib = common:: cdylib ( ) ;
188+ let mut foreign = std:: fs:: read ( & lib) . expect ( "read the cdylib" ) ;
189+ foreign[ ..4 ] . copy_from_slice ( b"XXXX" ) ;
190+ let dir =
191+ std:: env:: temp_dir ( ) . join ( format ! ( "store-postgres-conf-broken-{}" , std:: process:: id( ) ) ) ;
192+ let _ = std:: fs:: remove_dir_all ( & dir) ;
193+ std:: fs:: create_dir_all ( & dir) . unwrap ( ) ;
194+ let broken = dir. join ( lib. file_name ( ) . unwrap ( ) ) ;
195+ std:: fs:: write ( & broken, & foreign) . unwrap ( ) ;
196+ let red = match common:: dropped_at ( & broken, "{}" ) {
197+ Ok ( _) => panic ! ( "foreign bytes opened as the store" ) ,
198+ Err ( e) => e,
199+ } ;
200+ assert ! (
201+ !red. contains( "requires a \" url\" " ) ,
202+ "foreign bytes cannot speak the store's own refusal: {red}"
203+ ) ;
204+ let _ = std:: fs:: remove_dir_all ( & dir) ;
205+ }
200206
201- // RED ARM 2: the store's library asked for as another kind is refused before any slot runs.
207+ /// RED ARM 2: the store's library asked for as another kind is refused before any slot runs. No
208+ /// database needed.
209+ #[ test]
210+ fn a_store_library_loaded_as_another_kind_is_refused ( ) {
211+ let lib = common:: cdylib ( ) ;
202212 let d = Arc :: new ( Dispatcher :: new ( DispatchConfig :: default ( ) ) ) ;
203213 let bind = Bind {
204214 instance : Arc :: from ( "store-postgres-as-secret" ) ,
@@ -211,5 +221,4 @@ fn the_linked_and_the_dropped_in_postgres_store_are_one_store() {
211221 load_dropped:: <Secret >( & lib, & common:: stated( ) , bind) . is_err( ) ,
212222 "a store library loaded as kind secret"
213223 ) ;
214- let _ = std:: fs:: remove_dir_all ( & dir) ;
215224}
0 commit comments