@@ -1082,14 +1082,104 @@ func TestHelpIncludesVersion(t *testing.T) {
10821082 }
10831083}
10841084
1085+ func TestVaultDestroyByOwner (t * testing.T ) {
1086+ addr , alice , _ := testServerSetupMultiUser (t )
1087+
1088+ // Create vault and set a secret
1089+ sshRun (t , addr , alice .cfg , alice .ag , "vault create doomed" )
1090+ sshRunWithStdin (t , addr , alice .cfg , alice .ag , "set doomed:secret/key" , "value" )
1091+
1092+ // Destroy the vault — type vault name to confirm
1093+ out , err := sshRunWithStdin (t , addr , alice .cfg , alice .ag , "vault destroy doomed" , "doomed\n " )
1094+ if err != nil {
1095+ t .Fatalf ("vault destroy: %v (output: %q)" , err , out )
1096+ }
1097+ if ! strings .Contains (out , "destroyed" ) {
1098+ t .Errorf ("vault destroy output = %q, expected 'destroyed'" , out )
1099+ }
1100+
1101+ // vault list should no longer include "doomed"
1102+ listOut , err := sshRun (t , addr , alice .cfg , alice .ag , "vault list" )
1103+ if err != nil {
1104+ t .Fatalf ("vault list: %v" , err )
1105+ }
1106+ if strings .Contains (listOut , "doomed" ) {
1107+ t .Errorf ("vault list still contains 'doomed' after destroy: %q" , listOut )
1108+ }
1109+
1110+ // get on the vault secret should fail
1111+ _ , err = sshRun (t , addr , alice .cfg , alice .ag , "get doomed:secret/key" )
1112+ if err == nil {
1113+ t .Error ("expected error getting secret from destroyed vault" )
1114+ }
1115+ }
1116+
1117+ func TestVaultDestroyNonOwnerFails (t * testing.T ) {
1118+ addr , alice , bob := testServerSetupMultiUser (t )
1119+
1120+ // Alice creates vault and invites Bob
1121+ sshRun (t , addr , alice .cfg , alice .ag , "vault create protected" )
1122+ tokenOut , _ := sshRun (t , addr , alice .cfg , alice .ag , "vault invite protected bob" )
1123+ token := strings .TrimSpace (tokenOut )
1124+ sshRun (t , addr , bob .cfg , bob .ag , "vault accept protected " + token )
1125+
1126+ // Bob (member) attempts destroy — should fail
1127+ _ , err := sshRunWithStdin (t , addr , bob .cfg , bob .ag , "vault destroy protected" , "protected\n " )
1128+ if err == nil {
1129+ t .Error ("expected error when non-owner tries to destroy vault" )
1130+ }
1131+
1132+ // Vault should still exist
1133+ listOut , err := sshRun (t , addr , alice .cfg , alice .ag , "vault list" )
1134+ if err != nil {
1135+ t .Fatalf ("vault list: %v" , err )
1136+ }
1137+ if ! strings .Contains (listOut , "protected" ) {
1138+ t .Errorf ("vault list missing 'protected' after failed destroy: %q" , listOut )
1139+ }
1140+ }
1141+
1142+ func TestVaultDestroyCancelledOnMismatch (t * testing.T ) {
1143+ addr , alice , _ := testServerSetupMultiUser (t )
1144+
1145+ sshRun (t , addr , alice .cfg , alice .ag , "vault create keepsafe" )
1146+
1147+ // Send wrong name at confirmation
1148+ out , err := sshRunWithStdin (t , addr , alice .cfg , alice .ag , "vault destroy keepsafe" , "wrong-name\n " )
1149+ if err != nil {
1150+ t .Fatalf ("vault destroy (mismatch): %v (output: %q)" , err , out )
1151+ }
1152+ if ! strings .Contains (out , "cancelled" ) {
1153+ t .Errorf ("vault destroy mismatch output = %q, expected 'cancelled'" , out )
1154+ }
1155+
1156+ // Vault should still exist
1157+ listOut , err := sshRun (t , addr , alice .cfg , alice .ag , "vault list" )
1158+ if err != nil {
1159+ t .Fatalf ("vault list: %v" , err )
1160+ }
1161+ if ! strings .Contains (listOut , "keepsafe" ) {
1162+ t .Errorf ("vault list missing 'keepsafe' after cancelled destroy: %q" , listOut )
1163+ }
1164+ }
1165+
1166+ func TestVaultDestroyPersonalRejected (t * testing.T ) {
1167+ addr , alice := testServerSetup (t )
1168+
1169+ _ , err := sshRunWithStdin (t , addr , alice .cfg , alice .ag , "vault destroy personal" , "personal\n " )
1170+ if err == nil {
1171+ t .Error ("expected error when trying to destroy personal vault" )
1172+ }
1173+ }
1174+
10851175func TestHelpIncludesVaultCommands (t * testing.T ) {
10861176 addr , alice := testServerSetup (t )
10871177
10881178 out , err := sshRun (t , addr , alice .cfg , alice .ag , "help" )
10891179 if err != nil {
10901180 t .Fatalf ("help: %v" , err )
10911181 }
1092- for _ , want := range []string {"vault create" , "vault invite" , "vault accept" , "vault promote" , "vault members" , "vault list" , "move" } {
1182+ for _ , want := range []string {"vault create" , "vault invite" , "vault accept" , "vault promote" , "vault members" , "vault destroy" , "vault list" , "move" } {
10931183 if ! strings .Contains (out , want ) {
10941184 t .Errorf ("help output missing %q" , want )
10951185 }
0 commit comments