@@ -106,24 +106,24 @@ pub struct User {
106106/// Accept the UI's existing roles array or an object with a caller-supplied password.
107107#[ derive( Deserialize ) ]
108108#[ serde( untagged) ]
109- pub enum CreateUserRequest {
109+ pub enum CreateUserOptions {
110110 Roles ( HashSet < String > ) ,
111- Options ( CreateUserOptions ) ,
111+ Details ( CreateUserDetails ) ,
112112}
113113
114114#[ derive( Deserialize ) ]
115115#[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
116- pub struct CreateUserOptions {
116+ pub struct CreateUserDetails {
117117 #[ serde( default ) ]
118118 roles : HashSet < String > ,
119- provided_password : Option < String > ,
119+ password : Option < String > ,
120120}
121121
122- impl CreateUserRequest {
122+ impl CreateUserOptions {
123123 pub fn split_request ( self ) -> ( HashSet < String > , Option < String > ) {
124124 match self {
125125 Self :: Roles ( roles) => ( roles, None ) ,
126- Self :: Options ( options ) => ( options . roles , options . provided_password ) ,
126+ Self :: Details ( details ) => ( details . roles , details . password ) ,
127127 }
128128 }
129129}
@@ -134,7 +134,7 @@ impl User {
134134 Self :: new_basic_with_passcode ( username, tenant, protected, Basic :: gen_new_password ( ) )
135135 }
136136
137- pub fn new_basic_with_provided_password (
137+ pub fn new_basic_with_password (
138138 username : String ,
139139 tenant : Option < String > ,
140140 protected : bool ,
@@ -144,7 +144,7 @@ impl User {
144144 || password. trim ( ) != password
145145 || password. chars ( ) . any ( char:: is_control)
146146 {
147- return Err ( RBACError :: InvalidProvidedPassword ) ;
147+ return Err ( RBACError :: InvalidPassword ) ;
148148 }
149149
150150 let hash = gen_hash ( & password) ;
@@ -761,34 +761,32 @@ impl UserGroup {
761761}
762762
763763#[ cfg( test) ]
764- mod provided_password_tests {
764+ mod password_request_tests {
765765 use super :: * ;
766766
767767 #[ test]
768768 fn accepts_legacy_roles_array_and_new_password_object ( ) {
769- let legacy: CreateUserRequest = serde_json:: from_str ( r#"["reader"]"# ) . unwrap ( ) ;
769+ let legacy: CreateUserOptions = serde_json:: from_str ( r#"["reader"]"# ) . unwrap ( ) ;
770770 let ( roles, password) = legacy. split_request ( ) ;
771771 assert ! ( roles. contains( "reader" ) ) ;
772772 assert ! ( password. is_none( ) ) ;
773773
774- let modern: CreateUserRequest = serde_json:: from_str (
775- r#"{"roles":["reader"],"providedPassword":"a_valid_password_123"}"# ,
776- )
777- . unwrap ( ) ;
774+ let modern: CreateUserOptions =
775+ serde_json:: from_str ( r#"{"roles":["reader"],"password":"a_valid_password_123"}"# )
776+ . unwrap ( ) ;
778777 let ( roles, password) = modern. split_request ( ) ;
779778 assert ! ( roles. contains( "reader" ) ) ;
780779 assert_eq ! ( password. as_deref( ) , Some ( "a_valid_password_123" ) ) ;
781780
782781 assert ! (
783- serde_json:: from_str:: <CreateUserRequest >( r#"{"providedPasswrod ":"typo "}"# ) . is_err( )
782+ serde_json:: from_str:: <CreateUserOptions >( r#"{"providedPassword ":"old "}"# ) . is_err( )
784783 ) ;
785784 }
786785
787786 #[ test]
788787 fn supplied_password_is_hashed_and_invalid_values_are_rejected ( ) {
789788 let ( user, returned) =
790- User :: new_basic_with_provided_password ( "alice" . into ( ) , None , false , "Pa$$w0rd" . into ( ) )
791- . unwrap ( ) ;
789+ User :: new_basic_with_password ( "alice" . into ( ) , None , false , "Pa$$w0rd" . into ( ) ) . unwrap ( ) ;
792790 assert_eq ! ( returned, "Pa$$w0rd" ) ;
793791 let UserType :: Native ( basic) = & user. ty else {
794792 panic ! ( "expected native user" )
@@ -797,8 +795,8 @@ mod provided_password_tests {
797795 assert ! ( !serde_json:: to_string( & user) . unwrap( ) . contains( & returned) ) ;
798796
799797 assert ! ( matches!(
800- User :: new_basic_with_provided_password ( "bob" . into( ) , None , false , "short" . into( ) ) ,
801- Err ( RBACError :: InvalidProvidedPassword )
798+ User :: new_basic_with_password ( "bob" . into( ) , None , false , "short" . into( ) ) ,
799+ Err ( RBACError :: InvalidPassword )
802800 ) ) ;
803801 }
804802}
0 commit comments