gardesk/garcard / 676af33

Browse files

Enrich policy context and neutralize fixtures

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
676af331f61d8111979ab807351a0f8ca321e28a
Parents
d4699f7
Tree
aeadb73

1 changed file

StatusFile+-
M garcard/src/agent.rs 73 18
garcard/src/agent.rsmodified
@@ -552,11 +552,39 @@ fn render_prompt_context(request: &ActiveRequest) -> String {
552552
         lines.push(format!("Icon: {}", request.icon_name.trim()));
553553
     }
554554
 
555
+    if let Some(vendor) = first_detail_value(
556
+        &request.details,
557
+        &[
558
+            "vendor",
559
+            "vendor_name",
560
+            "polkit.vendor",
561
+            "polkit.vendor_name",
562
+        ],
563
+    ) {
564
+        lines.push(format!("Vendor: {}", vendor));
565
+    }
566
+
567
+    if let Some(application) = first_detail_value(
568
+        &request.details,
569
+        &[
570
+            "application",
571
+            "application_name",
572
+            "program_name",
573
+            "polkit.program_name",
574
+        ],
575
+    ) {
576
+        lines.push(format!("Application: {}", application));
577
+    }
578
+
555579
     let detail_keys = [
556580
         "program",
581
+        "polkit.exec.path",
582
+        "polkit.exec.argv1",
557583
         "command_line",
558584
         "unit",
559585
         "verb",
586
+        "polkit.message",
587
+        "polkit.gettext_domain",
560588
         "polkit.retains_authorization_after_challenge",
561589
     ];
562590
     for key in detail_keys {
@@ -688,12 +716,30 @@ fn identity_options_from_subjects(identities: &[Subject]) -> Vec<String> {
688716
     options
689717
 }
690718
 
719
+fn first_detail_value(details: &Details, keys: &[&str]) -> Option<String> {
720
+    for key in keys {
721
+        let Some(value) = details.get(*key) else {
722
+            continue;
723
+        };
724
+        let trimmed = value.trim();
725
+        if !trimmed.is_empty() {
726
+            return Some(trimmed.to_string());
727
+        }
728
+    }
729
+
730
+    None
731
+}
732
+
691733
 fn detail_key_label(key: &str) -> &'static str {
692734
     match key {
693735
         "program" => "Program",
736
+        "polkit.exec.path" => "Executable",
737
+        "polkit.exec.argv1" => "Executable Arg",
694738
         "command_line" => "Command",
695739
         "unit" => "Unit",
696740
         "verb" => "Verb",
741
+        "polkit.message" => "Policy Message",
742
+        "polkit.gettext_domain" => "Text Domain",
697743
         "polkit.retains_authorization_after_challenge" => "Retains authorization",
698744
         _ => "Detail",
699745
     }
@@ -1419,7 +1465,7 @@ mod tests {
14191465
                 let mut first_line = String::new();
14201466
                 reader.read_line(&mut first_line).expect("read first line");
14211467
                 let first = first_line.trim().to_string();
1422
-                if first == "alice" {
1468
+                if first == "operator" {
14231469
                     let mut cookie = String::new();
14241470
                     reader.read_line(&mut cookie).expect("read cookie");
14251471
                 }
@@ -1459,8 +1505,8 @@ mod tests {
14591505
             detail_count: 0,
14601506
             details: HashMap::new(),
14611507
             cookie: "cookie-1".to_string(),
1462
-            username: "alice".to_string(),
1463
-            identity_options: vec!["alice".to_string()],
1508
+            username: "operator".to_string(),
1509
+            identity_options: vec!["operator".to_string()],
14641510
         };
14651511
         let mut prompts = SequencedPrompt::new(vec![
14661512
             PromptResponse::Submitted("correct horse".to_string()),
@@ -1489,7 +1535,7 @@ mod tests {
14891535
 
14901536
             let mut first_line = String::new();
14911537
             reader.read_line(&mut first_line).expect("read first line");
1492
-            if first_line.trim() == "alice" {
1538
+            if first_line.trim() == "operator" {
14931539
                 let mut cookie = String::new();
14941540
                 reader.read_line(&mut cookie).expect("read cookie");
14951541
             }
@@ -1517,8 +1563,8 @@ mod tests {
15171563
             detail_count: 0,
15181564
             details: HashMap::new(),
15191565
             cookie: "cookie-timeout".to_string(),
1520
-            username: "alice".to_string(),
1521
-            identity_options: vec!["alice".to_string()],
1566
+            username: "operator".to_string(),
1567
+            identity_options: vec!["operator".to_string()],
15221568
         };
15231569
         let mut prompts = SequencedPrompt::new(vec![PromptResponse::TimedOut]);
15241570
 
@@ -1535,7 +1581,13 @@ mod tests {
15351581
     #[test]
15361582
     fn render_prompt_context_includes_policy_details() {
15371583
         let mut details = HashMap::new();
1584
+        details.insert("vendor".to_string(), "Gardesk".to_string());
1585
+        details.insert("application_name".to_string(), "Meson".to_string());
15381586
         details.insert("program".to_string(), "/usr/bin/meson".to_string());
1587
+        details.insert(
1588
+            "polkit.exec.path".to_string(),
1589
+            "/usr/bin/pkexec".to_string(),
1590
+        );
15391591
         details.insert("command_line".to_string(), "meson install".to_string());
15401592
         details.insert(
15411593
             "polkit.retains_authorization_after_challenge".to_string(),
@@ -1548,35 +1600,38 @@ mod tests {
15481600
             detail_count: details.len(),
15491601
             details,
15501602
             cookie: "cookie-ctx".to_string(),
1551
-            username: "alice".to_string(),
1552
-            identity_options: vec!["alice".to_string()],
1603
+            username: "operator".to_string(),
1604
+            identity_options: vec!["operator".to_string()],
15531605
         };
15541606
 
15551607
         let context = render_prompt_context(&request);
15561608
         assert!(context.contains("Authentication is required to install this project"));
15571609
         assert!(context.contains("Action: com.mesonbuild.install.run"));
15581610
         assert!(context.contains("Icon: preferences-system"));
1611
+        assert!(context.contains("Vendor: Gardesk"));
1612
+        assert!(context.contains("Application: Meson"));
15591613
         assert!(context.contains("Program: /usr/bin/meson"));
1614
+        assert!(context.contains("Executable: /usr/bin/pkexec"));
15601615
         assert!(context.contains("Command: meson install"));
15611616
         assert!(context.contains("Retains authorization: 1"));
15621617
     }
15631618
 
15641619
     #[test]
15651620
     fn parse_identity_selection_accepts_blank_index_and_name() {
1566
-        let options = vec!["alice".to_string(), "root".to_string()];
1621
+        let options = vec!["operator".to_string(), "root".to_string()];
15671622
         assert_eq!(
1568
-            parse_identity_selection("", &options, "alice"),
1569
-            Some("alice".to_string())
1623
+            parse_identity_selection("", &options, "operator"),
1624
+            Some("operator".to_string())
15701625
         );
15711626
         assert_eq!(
1572
-            parse_identity_selection("2", &options, "alice"),
1627
+            parse_identity_selection("2", &options, "operator"),
15731628
             Some("root".to_string())
15741629
         );
15751630
         assert_eq!(
1576
-            parse_identity_selection("ROOT", &options, "alice"),
1631
+            parse_identity_selection("ROOT", &options, "operator"),
15771632
             Some("root".to_string())
15781633
         );
1579
-        assert_eq!(parse_identity_selection("99", &options, "alice"), None);
1634
+        assert_eq!(parse_identity_selection("99", &options, "operator"), None);
15801635
     }
15811636
 
15821637
     #[test]
@@ -1588,8 +1643,8 @@ mod tests {
15881643
             detail_count: 0,
15891644
             details: HashMap::new(),
15901645
             cookie: "cookie-identity".to_string(),
1591
-            username: "alice".to_string(),
1592
-            identity_options: vec!["alice".to_string(), "root".to_string()],
1646
+            username: "operator".to_string(),
1647
+            identity_options: vec!["operator".to_string(), "root".to_string()],
15931648
         };
15941649
         let mut prompts = SequencedPrompt::new(vec![PromptResponse::Submitted("2".to_string())]);
15951650
 
@@ -1610,8 +1665,8 @@ mod tests {
16101665
             detail_count: 0,
16111666
             details: HashMap::new(),
16121667
             cookie: "cookie-identity-cancel".to_string(),
1613
-            username: "alice".to_string(),
1614
-            identity_options: vec!["alice".to_string(), "root".to_string()],
1668
+            username: "operator".to_string(),
1669
+            identity_options: vec!["operator".to_string(), "root".to_string()],
16151670
         };
16161671
         let mut prompts = SequencedPrompt::new(vec![PromptResponse::Canceled]);
16171672