@@ -138,3 +138,68 @@ impl UserRecord {
138138 }
139139 }
140140}
141+
142+ #[ cfg( test) ]
143+ mod tests {
144+ use super :: * ;
145+
146+ #[ test]
147+ fn backward_compat_stored_user_defaults ( ) {
148+ let created_at_epoch: u64 = 1_700_000_000 ;
149+ let mut buf = Vec :: new ( ) ;
150+ rmpv:: encode:: write_value (
151+ & mut buf,
152+ & rmpv:: Value :: Map ( vec ! [
153+ (
154+ rmpv:: Value :: String ( "user_id" . into( ) ) ,
155+ rmpv:: Value :: Integer ( rmpv:: Integer :: from( 42u64 ) ) ,
156+ ) ,
157+ (
158+ rmpv:: Value :: String ( "username" . into( ) ) ,
159+ rmpv:: Value :: String ( "legacy_user" . into( ) ) ,
160+ ) ,
161+ (
162+ rmpv:: Value :: String ( "tenant_id" . into( ) ) ,
163+ rmpv:: Value :: Integer ( rmpv:: Integer :: from( 1u32 ) ) ,
164+ ) ,
165+ (
166+ rmpv:: Value :: String ( "password_hash" . into( ) ) ,
167+ rmpv:: Value :: String ( "$argon2id$fake_hash" . into( ) ) ,
168+ ) ,
169+ (
170+ rmpv:: Value :: String ( "scram_salt" . into( ) ) ,
171+ rmpv:: Value :: Binary ( vec![ 1 , 2 , 3 ] ) ,
172+ ) ,
173+ (
174+ rmpv:: Value :: String ( "scram_salted_password" . into( ) ) ,
175+ rmpv:: Value :: Binary ( vec![ 4 , 5 , 6 ] ) ,
176+ ) ,
177+ (
178+ rmpv:: Value :: String ( "roles" . into( ) ) ,
179+ rmpv:: Value :: Array ( vec![ rmpv:: Value :: String ( "read_write" . into( ) ) ] ) ,
180+ ) ,
181+ (
182+ rmpv:: Value :: String ( "is_superuser" . into( ) ) ,
183+ rmpv:: Value :: Boolean ( false ) ,
184+ ) ,
185+ (
186+ rmpv:: Value :: String ( "is_active" . into( ) ) ,
187+ rmpv:: Value :: Boolean ( true ) ,
188+ ) ,
189+ (
190+ rmpv:: Value :: String ( "created_at" . into( ) ) ,
191+ rmpv:: Value :: Integer ( rmpv:: Integer :: from( created_at_epoch) ) ,
192+ ) ,
193+ ] ) ,
194+ )
195+ . expect ( "encode legacy StoredUser" ) ;
196+
197+ let stored: StoredUser = zerompk:: from_msgpack ( & buf) . expect ( "decode legacy StoredUser" ) ;
198+ assert ! ( !stored. must_change_password) ;
199+ assert_eq ! ( stored. password_changed_at, 0 ) ;
200+
201+ let record = UserRecord :: from_stored ( stored) ;
202+ assert ! ( !record. must_change_password) ;
203+ assert_eq ! ( record. password_changed_at, created_at_epoch) ;
204+ }
205+ }
0 commit comments