rustfs-cli 0.1.32

A Rust S3 CLI client for S3-compatible object storage
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
//! User management commands
//!
//! Commands for managing IAM users: list, add, info, remove, enable, disable.

use std::path::PathBuf;

use clap::Subcommand;
use serde::Serialize;

use super::get_admin_client;
use crate::confirm::{Confirmation, confirm};
use crate::exit_code::ExitCode;
use crate::output::Formatter;
use crate::secret_input::{SecretSource, can_prompt};
use rc_core::admin::{AdminApi, SecretValue, User, UserCredentialApi, UserStatus};

const ADD_USER_AFTER_HELP: &str = "\
Examples:
  rc admin user add local analyst analyst-secret
  rc admin user add local deployer deployer-secret
  rc admin user add production readonly-user long-secret-value";

/// User management subcommands
#[derive(Subcommand, Debug)]
pub enum UserCommands {
    /// List all users
    #[command(name = "ls", alias = "list")]
    List(ListArgs),

    /// Add a new user
    Add(AddArgs),

    /// Get user information
    Info(InfoArgs),

    /// Remove a user
    #[command(name = "rm", alias = "remove")]
    Remove(RemoveArgs),

    /// Enable a user
    Enable(EnableArgs),

    /// Disable a user
    Disable(DisableArgs),

    /// Reset a user's password (S3 secret key)
    #[command(after_help = PASSWD_AFTER_HELP)]
    Passwd(PasswdArgs),

    /// Inspect or clear a user's two-factor authentication
    #[command(subcommand)]
    Mfa(UserMfaCommands),
}

const PASSWD_AFTER_HELP: &str = "\
Examples:
  rc admin user passwd local analyst --password-from-env NEW_PW
  rc admin user passwd local analyst --password-file ./new.txt

Unlike re-creating the user, this changes only the secret key: the account's
status, policies and group memberships are left alone.";

const USER_MFA_AFTER_HELP: &str = "\
Examples:
  rc admin user mfa status local analyst
  rc admin user mfa reset local analyst --yes

`reset` is the break-glass path for a user who lost both their authenticator and
their recovery codes. It removes their second factor, so the account is left
protected by its password alone until they enrol again.";

#[derive(clap::Args, Debug)]
#[command(after_help = PASSWD_AFTER_HELP)]
pub struct PasswdArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user whose password is being reset
    pub access_key: String,

    /// Read the new password from this environment variable
    #[arg(long, value_name = "NAME")]
    pub password_from_env: Option<String>,

    /// Read the new password from the first line of this file
    #[arg(long, value_name = "PATH")]
    pub password_file: Option<PathBuf>,
}

#[derive(Subcommand, Debug)]
#[command(after_help = USER_MFA_AFTER_HELP)]
pub enum UserMfaCommands {
    /// Show whether a user has two-factor authentication enabled
    Status(UserMfaStatusArgs),

    /// Clear a user's second factor (break-glass)
    Reset(UserMfaResetArgs),
}

#[derive(clap::Args, Debug)]
pub struct UserMfaStatusArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user to inspect
    pub access_key: String,
}

#[derive(clap::Args, Debug)]
pub struct UserMfaResetArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user whose second factor is being cleared
    pub access_key: String,

    /// Confirm without an interactive prompt
    #[arg(long)]
    pub yes: bool,
}

#[derive(clap::Args, Debug)]
pub struct ListArgs {
    /// Alias name of the server
    pub alias: String,
}

#[derive(clap::Args, Debug)]
#[command(after_help = ADD_USER_AFTER_HELP)]
pub struct AddArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key (username) for the new user
    pub access_key: String,

    /// Secret key (password) for the new user
    pub secret_key: String,
}

#[derive(clap::Args, Debug)]
pub struct InfoArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user
    pub access_key: String,
}

#[derive(clap::Args, Debug)]
pub struct RemoveArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user to remove
    pub access_key: String,
}

#[derive(clap::Args, Debug)]
pub struct EnableArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user to enable
    pub access_key: String,
}

#[derive(clap::Args, Debug)]
pub struct DisableArgs {
    /// Alias name of the server
    pub alias: String,

    /// Access key of the user to disable
    pub access_key: String,
}

/// JSON output for user list
#[derive(Serialize)]
struct UserListOutput {
    users: Vec<UserInfo>,
}

/// JSON representation of a user
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct UserInfo {
    access_key: String,
    status: String,
    policies: Vec<String>,
    member_of: Vec<String>,
}

impl From<User> for UserInfo {
    fn from(user: User) -> Self {
        let policies = user.policies();
        Self {
            access_key: user.access_key,
            status: user.status.to_string(),
            policies,
            member_of: user.member_of,
        }
    }
}

/// JSON output for user operations
#[derive(Serialize)]
struct UserOperationOutput {
    success: bool,
    access_key: String,
    message: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    secret_key: Option<String>,
}

/// Execute a user subcommand
pub async fn execute(cmd: UserCommands, formatter: &Formatter) -> ExitCode {
    match cmd {
        UserCommands::List(args) => execute_list(args, formatter).await,
        UserCommands::Add(args) => execute_add(args, formatter).await,
        UserCommands::Info(args) => execute_info(args, formatter).await,
        UserCommands::Remove(args) => execute_remove(args, formatter).await,
        UserCommands::Enable(args) => execute_enable(args, formatter).await,
        UserCommands::Disable(args) => execute_disable(args, formatter).await,
        UserCommands::Passwd(args) => execute_passwd(args, formatter).await,
        UserCommands::Mfa(mfa_cmd) => execute_user_mfa(mfa_cmd, formatter).await,
    }
}

/// JSON output for a password reset
#[derive(Serialize)]
struct UserPasswordOutput {
    success: bool,
    access_key: String,
    sessions_revoked: u32,
    message: String,
}

/// JSON output for a user's two-factor state
#[derive(Serialize)]
struct UserMfaStatusOutput {
    access_key: String,
    enabled: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    activated_at: Option<String>,
    recovery_codes_remaining: u32,
}

async fn execute_passwd(args: PasswdArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(client) => client,
        Err(code) => return code,
    };

    if args.access_key.is_empty() {
        return formatter.fail_with_suggestion(
            ExitCode::UsageError,
            "Access key cannot be empty",
            "Provide the access key of the user whose password is being reset.",
        );
    }

    let source = match SecretSource::resolve(
        args.password_from_env,
        args.password_file,
        can_prompt(formatter.is_json()),
        "password",
    ) {
        Ok(source) => source,
        Err(error) => return formatter.fail(ExitCode::UsageError, &error.to_string()),
    };
    let secret = match source.load(&format!("New password for {}: ", args.access_key)) {
        Ok(value) => SecretValue::new(value.to_string()),
        Err(error) => return formatter.fail(ExitCode::UsageError, &error.to_string()),
    };

    match client.set_user_secret_key(&args.access_key, &secret).await {
        Ok(result) => {
            let message = if result.sessions_revoked > 0 {
                format!(
                    "Password reset for '{}'. {} session(s) were signed out.",
                    args.access_key, result.sessions_revoked
                )
            } else {
                format!("Password reset for '{}'.", args.access_key)
            };

            if formatter.is_json() {
                formatter.json(&UserPasswordOutput {
                    success: true,
                    access_key: args.access_key,
                    sessions_revoked: result.sessions_revoked,
                    message,
                });
            } else {
                formatter.println(&message);
            }
            ExitCode::Success
        }
        Err(error) => {
            let code = ExitCode::from_i32(error.exit_code()).unwrap_or(ExitCode::GeneralError);
            formatter.fail(code, &format!("Failed to reset the password: {error}"))
        }
    }
}

async fn execute_user_mfa(cmd: UserMfaCommands, formatter: &Formatter) -> ExitCode {
    match cmd {
        UserMfaCommands::Status(args) => execute_user_mfa_status(args, formatter).await,
        UserMfaCommands::Reset(args) => execute_user_mfa_reset(args, formatter).await,
    }
}

async fn execute_user_mfa_status(args: UserMfaStatusArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(client) => client,
        Err(code) => return code,
    };

    match client.user_mfa_status(&args.access_key).await {
        Ok(status) => {
            if formatter.is_json() {
                formatter.json(&UserMfaStatusOutput {
                    access_key: status.access_key,
                    enabled: status.enabled,
                    activated_at: status.activated_at,
                    recovery_codes_remaining: status.recovery_codes_remaining,
                });
            } else {
                formatter.println(&format!(
                    "{}: two-factor authentication {}",
                    formatter.style_name(&status.access_key),
                    if status.enabled { "on" } else { "off" }
                ));
                if status.enabled {
                    if let Some(activated) = &status.activated_at {
                        formatter.println(&format!(
                            "  Enabled on: {}",
                            formatter.sanitize_text(activated)
                        ));
                    }
                    formatter.println(&format!(
                        "  Recovery:   {} code(s) remaining",
                        status.recovery_codes_remaining
                    ));
                }
            }
            ExitCode::Success
        }
        Err(error) => {
            let code = ExitCode::from_i32(error.exit_code()).unwrap_or(ExitCode::GeneralError);
            formatter.fail(code, &format!("Failed to read two-factor state: {error}"))
        }
    }
}

async fn execute_user_mfa_reset(args: UserMfaResetArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(client) => client,
        Err(code) => return code,
    };

    if let Err(error) = confirm_mfa_reset(&args.access_key, args.yes, formatter) {
        let code = ExitCode::from_i32(error.exit_code()).unwrap_or(ExitCode::GeneralError);
        return formatter.fail(code, &error.to_string());
    }

    match client.user_mfa_reset(&args.access_key).await {
        Ok(()) => {
            let message = format!(
                "Two-factor authentication cleared for '{}'. The account is now protected by its password alone.",
                args.access_key
            );
            if formatter.is_json() {
                formatter.json(&UserOperationOutput {
                    success: true,
                    access_key: args.access_key,
                    message,
                    secret_key: None,
                });
            } else {
                formatter.println(&message);
            }
            ExitCode::Success
        }
        Err(error) => {
            let code = ExitCode::from_i32(error.exit_code()).unwrap_or(ExitCode::GeneralError);
            formatter.fail(
                code,
                &format!("Failed to clear two-factor authentication: {error}"),
            )
        }
    }
}

/// Confirm a break-glass reset, naming the target.
///
/// Removing somebody's second factor is not reversible from the operator's side
/// — the user has to enrol again — so a non-interactive run must say `--yes`
/// rather than have the confirmation silently skipped.
fn confirm_mfa_reset(access_key: &str, yes: bool, formatter: &Formatter) -> rc_core::Result<()> {
    let prompt = format!(
        "Clear two-factor authentication for '{}'? The account will be protected by its password alone. [y/N]",
        formatter.sanitize_text(access_key)
    );
    confirm(
        &Confirmation {
            prompt: &prompt,
            requires_yes: "Clearing a user's second factor requires --yes in non-interactive or JSON mode",
            declined: "Clearing two-factor authentication was declined",
        },
        yes,
        formatter,
    )
}

async fn execute_list(args: ListArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    match client.list_users().await {
        Ok(users) => {
            if formatter.is_json() {
                let output = UserListOutput {
                    users: users.into_iter().map(UserInfo::from).collect(),
                };
                formatter.json(&output);
            } else if users.is_empty() {
                formatter.println("No users found.");
            } else {
                for user in users {
                    let status_icon = match user.status {
                        UserStatus::Enabled => formatter.style_size(""),
                        UserStatus::Disabled => formatter.style_date(""),
                    };
                    let styled_key = formatter.style_name(&user.access_key);
                    let policies = user.policies().join(", ");
                    if policies.is_empty() {
                        formatter.println(&format!("{status_icon} {styled_key}"));
                    } else {
                        let styled_policies = formatter.style_date(&policies);
                        formatter.println(&format!(
                            "{status_icon} {styled_key} (policies: {styled_policies})"
                        ));
                    }
                }
            }
            ExitCode::Success
        }
        Err(e) => {
            formatter.error(&format!("Failed to list users: {e}"));
            ExitCode::GeneralError
        }
    }
}

async fn execute_add(args: AddArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    if args.access_key.is_empty() {
        return formatter.fail_with_suggestion(
            ExitCode::UsageError,
            "Access key cannot be empty",
            "Provide a non-empty access key for the new user.",
        );
    }

    if args.secret_key.len() < 8 {
        return formatter.fail_with_suggestion(
            ExitCode::UsageError,
            "Secret key must be at least 8 characters long",
            "Provide a secret key that is at least 8 characters long.",
        );
    }

    match client.create_user(&args.access_key, &args.secret_key).await {
        Ok(user) => {
            if formatter.is_json() {
                let output = UserOperationOutput {
                    success: true,
                    access_key: user.access_key.clone(),
                    message: format!("User '{}' created successfully", user.access_key),
                    secret_key: user.secret_key,
                };
                formatter.json(&output);
            } else {
                let styled_key = formatter.style_name(&user.access_key);
                formatter.success(&format!("User '{styled_key}' created successfully."));
            }
            ExitCode::Success
        }
        Err(e) => formatter.fail(
            ExitCode::GeneralError,
            &format!("Failed to create user: {e}"),
        ),
    }
}

async fn execute_info(args: InfoArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    match client.get_user(&args.access_key).await {
        Ok(user) => {
            if formatter.is_json() {
                formatter.json(&UserInfo::from(user));
            } else {
                let styled_key = formatter.style_name(&user.access_key);
                let status = match user.status {
                    UserStatus::Enabled => formatter.style_size("enabled"),
                    UserStatus::Disabled => formatter.style_date("disabled"),
                };
                formatter.println(&format!("Access Key: {styled_key}"));
                formatter.println(&format!("Status:     {status}"));

                let policies = user.policies();
                if policies.is_empty() {
                    formatter.println("Policies:   (none)");
                } else {
                    formatter.println(&format!("Policies:   {}", policies.join(", ")));
                }

                if user.member_of.is_empty() {
                    formatter.println("Groups:     (none)");
                } else {
                    formatter.println(&format!("Groups:     {}", user.member_of.join(", ")));
                }
            }
            ExitCode::Success
        }
        Err(rc_core::Error::NotFound(_)) => {
            formatter.error(&format!("User '{}' not found", args.access_key));
            ExitCode::NotFound
        }
        Err(e) => {
            formatter.error(&format!("Failed to get user info: {e}"));
            ExitCode::GeneralError
        }
    }
}

async fn execute_remove(args: RemoveArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    match client.delete_user(&args.access_key).await {
        Ok(()) => {
            if formatter.is_json() {
                let output = UserOperationOutput {
                    success: true,
                    access_key: args.access_key.clone(),
                    message: format!("User '{}' removed successfully", args.access_key),
                    secret_key: None,
                };
                formatter.json(&output);
            } else {
                let styled_key = formatter.style_name(&args.access_key);
                formatter.success(&format!("User '{styled_key}' removed successfully."));
            }
            ExitCode::Success
        }
        Err(rc_core::Error::NotFound(_)) => {
            formatter.error(&format!("User '{}' not found", args.access_key));
            ExitCode::NotFound
        }
        Err(e) => {
            formatter.error(&format!("Failed to remove user: {e}"));
            ExitCode::GeneralError
        }
    }
}

async fn execute_enable(args: EnableArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    match client
        .set_user_status(&args.access_key, UserStatus::Enabled)
        .await
    {
        Ok(()) => {
            if formatter.is_json() {
                let output = UserOperationOutput {
                    success: true,
                    access_key: args.access_key.clone(),
                    message: format!("User '{}' enabled successfully", args.access_key),
                    secret_key: None,
                };
                formatter.json(&output);
            } else {
                let styled_key = formatter.style_name(&args.access_key);
                formatter.success(&format!("User '{styled_key}' enabled successfully."));
            }
            ExitCode::Success
        }
        Err(e) => {
            formatter.error(&format!("Failed to enable user: {e}"));
            ExitCode::GeneralError
        }
    }
}

async fn execute_disable(args: DisableArgs, formatter: &Formatter) -> ExitCode {
    let client = match get_admin_client(&args.alias, formatter) {
        Ok(c) => c,
        Err(code) => return code,
    };

    match client
        .set_user_status(&args.access_key, UserStatus::Disabled)
        .await
    {
        Ok(()) => {
            if formatter.is_json() {
                let output = UserOperationOutput {
                    success: true,
                    access_key: args.access_key.clone(),
                    message: format!("User '{}' disabled successfully", args.access_key),
                    secret_key: None,
                };
                formatter.json(&output);
            } else {
                let styled_key = formatter.style_name(&args.access_key);
                formatter.success(&format!("User '{styled_key}' disabled successfully."));
            }
            ExitCode::Success
        }
        Err(e) => {
            formatter.error(&format!("Failed to disable user: {e}"));
            ExitCode::GeneralError
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::Parser;

    #[derive(Debug, Parser)]
    struct TestCli {
        #[command(subcommand)]
        command: UserCommands,
    }

    #[test]
    fn passwd_parses_a_target_and_an_environment_source() {
        let cli = TestCli::parse_from([
            "user",
            "passwd",
            "local",
            "analyst",
            "--password-from-env",
            "NEW_PW",
        ]);
        match cli.command {
            UserCommands::Passwd(args) => {
                assert_eq!(args.alias, "local");
                assert_eq!(args.access_key, "analyst");
                assert_eq!(args.password_from_env.as_deref(), Some("NEW_PW"));
            }
            other => panic!("unexpected command: {other:?}"),
        }
    }

    #[test]
    fn passwd_requires_a_target_access_key() {
        // Without a target this would be ambiguous with the self-service
        // `account passwd`, so clap must reject it rather than guess.
        assert!(TestCli::try_parse_from(["user", "passwd", "local"]).is_err());
    }

    #[test]
    fn mfa_status_parses_a_target() {
        let cli = TestCli::parse_from(["user", "mfa", "status", "local", "analyst"]);
        match cli.command {
            UserCommands::Mfa(UserMfaCommands::Status(args)) => {
                assert_eq!(args.access_key, "analyst");
            }
            other => panic!("unexpected command: {other:?}"),
        }
    }

    #[test]
    fn mfa_reset_carries_an_explicit_confirmation_flag() {
        let cli = TestCli::parse_from(["user", "mfa", "reset", "local", "analyst", "--yes"]);
        match cli.command {
            UserCommands::Mfa(UserMfaCommands::Reset(args)) => {
                assert!(args.yes);
                assert_eq!(args.access_key, "analyst");
            }
            other => panic!("unexpected command: {other:?}"),
        }
    }

    #[test]
    fn a_json_mode_reset_without_confirmation_is_a_usage_error() {
        // Never silently proceed: a scripted break-glass must be deliberate.
        let formatter = Formatter::new(crate::output::OutputConfig {
            json: true,
            ..Default::default()
        });

        let error = confirm_mfa_reset("analyst", false, &formatter).expect_err("must refuse");
        assert!(matches!(error, rc_core::Error::InvalidPath(_)), "{error:?}");
        assert!(error.to_string().contains("--yes"), "{error}");
    }

    #[test]
    fn an_explicit_yes_skips_confirmation_even_in_json_mode() {
        let formatter = Formatter::new(crate::output::OutputConfig {
            json: true,
            ..Default::default()
        });

        confirm_mfa_reset("analyst", true, &formatter).expect("--yes must be honoured");
    }

    #[test]
    fn test_user_info_from_user() {
        let user = User {
            access_key: "testuser".to_string(),
            secret_key: None,
            status: UserStatus::Enabled,
            policy_name: Some("policy1,policy2".to_string()),
            member_of: vec!["group1".to_string()],
        };

        let info = UserInfo::from(user);
        assert_eq!(info.access_key, "testuser");
        assert_eq!(info.status, "enabled");
        assert_eq!(info.policies, vec!["policy1", "policy2"]);
        assert_eq!(info.member_of, vec!["group1"]);
    }
}