@@ -921,7 +921,7 @@ where
921
921
// Check the namespace name
922
922
{
923
923
let prompt = format ! (
924
- "Is this the correct namespace name: {}? (yes/no )" ,
924
+ "Is this the correct namespace name: {}? (y/n )" ,
925
925
manifest. namespace. name
926
926
) ;
927
927
if !prompter. prompt_is_yes ( & prompt) {
@@ -932,7 +932,7 @@ where
932
932
// Check the namespace nonce
933
933
{
934
934
let prompt = format ! (
935
- "Is this the correct namespace nonce: {}? (yes/no )" ,
935
+ "Is this the correct namespace nonce: {}? (y/n )" ,
936
936
manifest. namespace. nonce
937
937
) ;
938
938
if !prompter. prompt_is_yes ( & prompt) {
@@ -943,7 +943,7 @@ where
943
943
// Check pivot restart policy
944
944
{
945
945
let prompt = format ! (
946
- "Is this the correct pivot restart policy: {:?}? (yes/no )" ,
946
+ "Is this the correct pivot restart policy: {:?}? (y/n )" ,
947
947
manifest. pivot. restart
948
948
) ;
949
949
if !prompter. prompt_is_yes ( & prompt) {
@@ -954,7 +954,7 @@ where
954
954
// Check pivot arguments
955
955
{
956
956
let prompt = format ! (
957
- "Are these the correct pivot args:\n {:?}?\n (yes/no )" ,
957
+ "Are these the correct pivot args:\n {:?}?\n (y/n )" ,
958
958
manifest. pivot. args
959
959
) ;
960
960
if !prompter. prompt_is_yes ( & prompt) {
@@ -1352,7 +1352,7 @@ where
1352
1352
// Check the namespace name
1353
1353
{
1354
1354
let prompt = format ! (
1355
- "Is this the correct namespace name: {}? (yes/no )" ,
1355
+ "Is this the correct namespace name: {}? (y/n )" ,
1356
1356
manifest_envelope. manifest. namespace. name
1357
1357
) ;
1358
1358
if !prompter. prompt_is_yes ( & prompt) {
@@ -1363,7 +1363,7 @@ where
1363
1363
// Check the namespace nonce
1364
1364
{
1365
1365
let prompt = format ! (
1366
- "Is this the correct namespace nonce: {}? (yes/no )" ,
1366
+ "Is this the correct namespace nonce: {}? (y/n )" ,
1367
1367
manifest_envelope. manifest. namespace. nonce
1368
1368
) ;
1369
1369
if !prompter. prompt_is_yes ( & prompt) {
@@ -1374,7 +1374,7 @@ where
1374
1374
// Check that the IAM role is correct
1375
1375
{
1376
1376
let prompt = format ! (
1377
- "Does this AWS IAM role belong to the intended organization: {pcr3_preimage}? (yes/no )"
1377
+ "Does this AWS IAM role belong to the intended organization: {pcr3_preimage}? (y/n )"
1378
1378
) ;
1379
1379
if !prompter. prompt_is_yes ( & prompt) {
1380
1380
return false ;
@@ -1393,7 +1393,7 @@ where
1393
1393
let approvers = approvers. join ( "\n " ) ;
1394
1394
1395
1395
let prompt = format ! (
1396
- "The following manifest set members approved:\n {approvers}\n Is this ok? (yes/no )"
1396
+ "The following manifest set members approved:\n {approvers}\n Is this ok? (y/n )"
1397
1397
) ;
1398
1398
1399
1399
if !prompter. prompt_is_yes ( & prompt) {
@@ -1738,9 +1738,8 @@ pub(crate) fn shamir_reconstruct(
1738
1738
} )
1739
1739
. collect :: < Result < Vec < Vec < u8 > > , Error > > ( ) ?;
1740
1740
1741
- let secret = Zeroizing :: new (
1742
- qos_crypto:: shamir:: shares_reconstruct ( shares) . unwrap ( ) ,
1743
- ) ;
1741
+ let secret =
1742
+ Zeroizing :: new ( qos_crypto:: shamir:: shares_reconstruct ( shares) . unwrap ( ) ) ;
1744
1743
1745
1744
write_with_msg ( output_path. as_ref ( ) , & secret, "Reconstructed secret" ) ;
1746
1745
@@ -2129,7 +2128,26 @@ where
2129
2128
}
2130
2129
2131
2130
fn prompt_is_yes ( & mut self , question : & str ) -> bool {
2132
- self . prompt ( question) == "yes"
2131
+ // Fixed amount of attempts to avoid a "while true" loop
2132
+ let mut attempts = 3 ;
2133
+ // First prompt is the question. Subsequent prompts (if any) are the reminder to answer either yes or no.
2134
+ let mut prompt = question;
2135
+
2136
+ while attempts > 0 {
2137
+ let answer = self . prompt ( prompt) ;
2138
+
2139
+ if [ "yes" , "Yes" , "YES" , "Y" , "y" ] . contains ( & answer. as_ref ( ) ) {
2140
+ return true ;
2141
+ }
2142
+
2143
+ if [ "no" , "No" , "NO" , "N" , "n" ] . contains ( & answer. as_ref ( ) ) {
2144
+ return false ;
2145
+ }
2146
+
2147
+ attempts -= 1 ;
2148
+ prompt = "Please answer with either \" yes\" (y) or \" no\" (n)" ;
2149
+ }
2150
+ false
2133
2151
}
2134
2152
}
2135
2153
@@ -2557,7 +2575,7 @@ mod tests {
2557
2575
let Setup { manifest, .. } = setup ( ) ;
2558
2576
2559
2577
let mut vec_out: Vec < u8 > = vec ! [ ] ;
2560
- let vec_in = "ye \n " . as_bytes ( ) ;
2578
+ let vec_in = "No \n " . as_bytes ( ) ;
2561
2579
2562
2580
let mut prompter =
2563
2581
Prompter { reader : vec_in, writer : & mut vec_out } ;
@@ -2568,7 +2586,10 @@ mod tests {
2568
2586
) ) ;
2569
2587
2570
2588
let output = String :: from_utf8 ( vec_out) . unwrap ( ) ;
2571
- assert_eq ! ( & output, "Is this the correct namespace name: test-namespace? (yes/no)\n " ) ;
2589
+ assert_eq ! (
2590
+ & output,
2591
+ "Is this the correct namespace name: test-namespace? (y/n)\n "
2592
+ ) ;
2572
2593
}
2573
2594
2574
2595
#[ test]
@@ -2591,7 +2612,7 @@ mod tests {
2591
2612
2592
2613
assert_eq ! (
2593
2614
output[ 1 ] ,
2594
- "Is this the correct namespace nonce: 2? (yes/no )"
2615
+ "Is this the correct namespace nonce: 2? (y/n )"
2595
2616
) ;
2596
2617
}
2597
2618
@@ -2615,7 +2636,7 @@ mod tests {
2615
2636
2616
2637
assert_eq ! (
2617
2638
output[ 2 ] ,
2618
- "Is this the correct pivot restart policy: RestartPolicy::Never? (yes/no )"
2639
+ "Is this the correct pivot restart policy: RestartPolicy::Never? (y/n )"
2619
2640
) ;
2620
2641
}
2621
2642
@@ -2639,7 +2660,7 @@ mod tests {
2639
2660
2640
2661
assert_eq ! ( output[ 3 ] , "Are these the correct pivot args:" ) ;
2641
2662
assert_eq ! ( output[ 4 ] , "[\" --option1\" , \" argument\" ]?" ) ;
2642
- assert_eq ! ( output[ 5 ] , "(yes/no )" ) ;
2663
+ assert_eq ! ( output[ 5 ] , "(y/n )" ) ;
2643
2664
}
2644
2665
}
2645
2666
@@ -2690,7 +2711,7 @@ mod tests {
2690
2711
. get_mut ( 0 )
2691
2712
. unwrap ( )
2692
2713
. member
2693
- . alias = "yoloswag420blazeit " . to_string ( ) ;
2714
+ . alias = "not-a-member " . to_string ( ) ;
2694
2715
2695
2716
let member = share_set. members [ 0 ] . clone ( ) ;
2696
2717
assert ! ( !proxy_re_encrypt_share_programmatic_verifications(
@@ -2755,6 +2776,41 @@ mod tests {
2755
2776
) ) ;
2756
2777
}
2757
2778
2779
+ #[ test]
2780
+ fn accepts_with_some_typos_from_operator ( ) {
2781
+ let Setup { manifest_envelope, .. } = setup ( ) ;
2782
+
2783
+ let mut vec_out: Vec < u8 > = vec ! [ ] ;
2784
+ // Try all the accepted yes variants: y, yes, Yes, and YES!
2785
+ let vec_in = "y\n yes\n yea\n tes\n Yes\n YES\n " . as_bytes ( ) ;
2786
+
2787
+ let mut prompter =
2788
+ Prompter { reader : vec_in, writer : & mut vec_out } ;
2789
+
2790
+ assert ! ( proxy_re_encrypt_share_human_verifications(
2791
+ & manifest_envelope,
2792
+ "pr3" ,
2793
+ & mut prompter
2794
+ ) ) ;
2795
+
2796
+ let output = String :: from_utf8 ( vec_out) . unwrap ( ) ;
2797
+ let output: Vec < _ > = output. lines ( ) . collect ( ) ;
2798
+ assert_eq ! (
2799
+ output,
2800
+ vec![
2801
+ "Is this the correct namespace name: test-namespace? (y/n)" ,
2802
+ "Is this the correct namespace nonce: 2? (y/n)" ,
2803
+ "Does this AWS IAM role belong to the intended organization: pr3? (y/n)" ,
2804
+ "Please answer with either \" yes\" (y) or \" no\" (n)" ,
2805
+ "Please answer with either \" yes\" (y) or \" no\" (n)" ,
2806
+ "The following manifest set members approved:" ,
2807
+ "\t alias: 0" ,
2808
+ "\t alias: 1" ,
2809
+ "Is this ok? (y/n)" ,
2810
+ ]
2811
+ ) ;
2812
+ }
2813
+
2758
2814
#[ test]
2759
2815
fn exits_early_bad_namespace_name ( ) {
2760
2816
let Setup { manifest_envelope, .. } = setup ( ) ;
@@ -2772,7 +2828,10 @@ mod tests {
2772
2828
) ) ;
2773
2829
2774
2830
let output = String :: from_utf8 ( vec_out) . unwrap ( ) ;
2775
- assert_eq ! ( & output, "Is this the correct namespace name: test-namespace? (yes/no)\n " ) ;
2831
+ assert_eq ! (
2832
+ & output,
2833
+ "Is this the correct namespace name: test-namespace? (y/n)\n "
2834
+ ) ;
2776
2835
}
2777
2836
2778
2837
#[ test]
@@ -2795,7 +2854,7 @@ mod tests {
2795
2854
let output: Vec < _ > = output. lines ( ) . collect ( ) ;
2796
2855
assert_eq ! (
2797
2856
output. last( ) . unwrap( ) ,
2798
- & "Is this the correct namespace nonce: 2? (yes/no )"
2857
+ & "Is this the correct namespace nonce: 2? (y/n )"
2799
2858
) ;
2800
2859
}
2801
2860
@@ -2819,7 +2878,7 @@ mod tests {
2819
2878
let output: Vec < _ > = output. lines ( ) . collect ( ) ;
2820
2879
assert_eq ! (
2821
2880
output. last( ) . unwrap( ) ,
2822
- & "Does this AWS IAM role belong to the intended organization: pr3? (yes/no )"
2881
+ & "Does this AWS IAM role belong to the intended organization: pr3? (y/n )"
2823
2882
) ;
2824
2883
}
2825
2884
@@ -2828,7 +2887,7 @@ mod tests {
2828
2887
let Setup { manifest_envelope, .. } = setup ( ) ;
2829
2888
2830
2889
let mut vec_out: Vec < u8 > = vec ! [ ] ;
2831
- let vec_in = "yes\n yes\n yes\n y " . as_bytes ( ) ;
2890
+ let vec_in = "yes\n yes\n yes\n no " . as_bytes ( ) ;
2832
2891
2833
2892
let mut prompter =
2834
2893
Prompter { reader : vec_in, writer : & mut vec_out } ;
@@ -2848,8 +2907,37 @@ mod tests {
2848
2907
) ;
2849
2908
assert_eq ! ( output[ 4 ] , "\t alias: 0" ) ;
2850
2909
assert_eq ! ( output[ 5 ] , "\t alias: 1" ) ;
2851
- assert_eq ! ( output[ 6 ] , "Is this ok? (yes/no )" ) ;
2910
+ assert_eq ! ( output[ 6 ] , "Is this ok? (y/n )" ) ;
2852
2911
assert_eq ! ( output. len( ) , 7 ) ;
2853
2912
}
2913
+
2914
+ #[ test]
2915
+ fn exits_after_three_hesitations ( ) {
2916
+ let Setup { manifest_envelope, .. } = setup ( ) ;
2917
+
2918
+ let mut vec_out: Vec < u8 > = vec ! [ ] ;
2919
+ let vec_in = "maybe\n dunno\n unsure\n " . as_bytes ( ) ;
2920
+
2921
+ let mut prompter =
2922
+ Prompter { reader : vec_in, writer : & mut vec_out } ;
2923
+
2924
+ assert ! ( !proxy_re_encrypt_share_human_verifications(
2925
+ & manifest_envelope,
2926
+ "pr3" ,
2927
+ & mut prompter
2928
+ ) ) ;
2929
+
2930
+ let output = String :: from_utf8 ( vec_out) . unwrap ( ) ;
2931
+ let output: Vec < _ > = output. lines ( ) . collect ( ) ;
2932
+
2933
+ assert_eq ! (
2934
+ output,
2935
+ vec![
2936
+ "Is this the correct namespace name: test-namespace? (y/n)" ,
2937
+ "Please answer with either \" yes\" (y) or \" no\" (n)" ,
2938
+ "Please answer with either \" yes\" (y) or \" no\" (n)" ,
2939
+ ]
2940
+ ) ;
2941
+ }
2854
2942
}
2855
2943
}
0 commit comments