@@ -93,28 +93,39 @@ void testCreateDecryptDocRSA() throws IOException {
9393 @ Test
9494 void testSuccessfulCreateDecryptDocWithPassword () throws IOException {
9595 encrypt (PASSWORD_OPTION );
96- decrypt (PASSWORD_OPTION , SUCCESSFUL_EXIT_CODE );
96+ decryptSuccessfully (PASSWORD_OPTION );
9797 }
9898
9999 @ Test
100100 @ Disabled ("Requires user interaction for inserting password 'myPlainTextPassword'" )
101101 void testSuccessfulCreateDecryptDocWithPasswordWhenItIsInsertedInteractively ()
102102 throws IOException {
103103 encrypt (PASSWORD_OPTION );
104- decrypt ("--password=" , SUCCESSFUL_EXIT_CODE );
104+ decryptSuccessfully ("--password=" );
105105 }
106106
107107 @ Test
108- void testSuccessfulCreateDecryptDocWithPasswordWhenLabelIsMissing ()
109- throws IOException {
108+ void testSuccessfulCreateDecryptDocWithPasswordWhenLabelIsMissing () throws IOException {
110109 encrypt (PASSWORD_OPTION );
111- decrypt ("--password=:myPlainTextPassword" , SUCCESSFUL_EXIT_CODE );
110+ decryptSuccessfully ("--password=:myPlainTextPassword" );
111+ }
112+
113+ @ Test
114+ void testSuccessfulCreateDecryptDocWithMissingLabelInPassword () throws IOException {
115+ encrypt ("--password=:myPlainTextPassword" );
116+ decryptSuccessfully ("--password=:myPlainTextPassword" );
117+ }
118+
119+ @ Test
120+ void testSuccessfulCreateDecryptDocWithMissingLabelInSecretKey () throws IOException {
121+ encrypt ("--secret=:base64,aejUgxxSQXqiiyrxSGACfMiIRBZq5KjlCwr/xVNY/B0=" );
122+ decryptSuccessfully ("--secret=:base64,aejUgxxSQXqiiyrxSGACfMiIRBZq5KjlCwr/xVNY/B0=" );
112123 }
113124
114125 @ Test
115126 void testSuccessfulCreateDecryptDocWithSecret () throws IOException {
116127 encrypt (SECRET_OPTION );
117- decrypt (SECRET_OPTION , SUCCESSFUL_EXIT_CODE );
128+ decryptSuccessfully (SECRET_OPTION );
118129 }
119130
120131 @ Test
@@ -135,9 +146,7 @@ void failToEncryptDocWhenSecretInPlainText() {
135146 void shouldFailToEncryptDocWithSecretButDecryptWithPassword () {
136147 encrypt (SECRET_OPTION );
137148
138- assertThrowsException (() ->
139- decrypt (PASSWORD_OPTION , FAILURE_EXIT_CODE )
140- );
149+ assertThrowsException (() -> failToDecrypt (PASSWORD_OPTION ));
141150 }
142151
143152 /**
@@ -149,29 +158,25 @@ void shouldFailToEncryptDocWithSecretButDecryptWithPassword() {
149158 void shouldFailToEncryptDocWithPasswordButDecryptWithSecret () {
150159 encrypt (PASSWORD_OPTION );
151160
152- assertThrowsException (() ->
153- decrypt (SECRET_OPTION , FAILURE_EXIT_CODE )
154- );
161+ assertThrowsException (() -> failToDecrypt (SECRET_OPTION ));
155162 }
156163
157164 @ Test
158165 void shouldFailToEncryptDocWithPasswordIfItsValidationHasFailed () {
159166 String passwordForEncrypt = "--password=passwordlabel:short" ;
160- assertThrowsException (() ->
161- encrypt (passwordForEncrypt )
162- );
167+ assertThrowsException (() -> encrypt (passwordForEncrypt ));
163168 }
164169
165170 @ Test
166171 void shouldSucceedToEncryptDocWithTwoKeysAndDecryptWithPassword () throws IOException {
167172 encryptWithTwoKeys (PASSWORD_OPTION , SECRET_OPTION );
168- decrypt (PASSWORD_OPTION , SUCCESSFUL_EXIT_CODE );
173+ decryptSuccessfully (PASSWORD_OPTION );
169174 }
170175
171176 @ Test
172177 void shouldSucceedToEncryptDocWithTwoKeysAndDecryptWithSecret () throws IOException {
173178 encryptWithTwoKeys (PASSWORD_OPTION , SECRET_OPTION );
174- decrypt (SECRET_OPTION , SUCCESSFUL_EXIT_CODE );
179+ decryptSuccessfully (SECRET_OPTION );
175180 }
176181
177182 @ Test
@@ -218,7 +223,7 @@ void shouldFailWithTheSameOutputDirectoryWhenReEncrypt(@TempDir Path tempPath) {
218223 @ Test
219224 void infoShouldDisplayKeyLabelInDefaultFormatForPassword () throws IOException {
220225 encrypt (PASSWORD_OPTION );
221- decrypt (PASSWORD_OPTION , SUCCESSFUL_EXIT_CODE );
226+ decryptSuccessfully (PASSWORD_OPTION );
222227
223228 String expectedKeyLabel = "Password: V:1, LABEL:passwordlabel, TYPE:pw" ;
224229 executeInfo (expectedKeyLabel , cdocFile );
@@ -229,7 +234,7 @@ void infoShouldDisplayKeyLabelInPlainText() throws IOException {
229234 setUpKeyLabelFormat (false );
230235
231236 encrypt (PASSWORD_OPTION );
232- decrypt (PASSWORD_OPTION , SUCCESSFUL_EXIT_CODE );
237+ decryptSuccessfully (PASSWORD_OPTION );
233238
234239 String expectedKeyLabel = "Password: LABEL:passwordlabel" ;
235240 executeInfo (expectedKeyLabel , cdocFile );
@@ -240,7 +245,7 @@ void infoShouldDisplayKeyLabelInPlainText() throws IOException {
240245 @ Test
241246 void infoShouldDisplayKeyLabelInDefaultFormatForSecret () throws IOException {
242247 encrypt (SECRET_OPTION );
243- decrypt (SECRET_OPTION , SUCCESSFUL_EXIT_CODE );
248+ decryptSuccessfully (SECRET_OPTION );
244249
245250 String expectedKeyLabel
246251 = "SymmetricKey: V:1, LABEL:label_b64secret, TYPE:secret" ;
@@ -252,7 +257,7 @@ void infoShouldDisplayKeyLabelInPlainTextForSecret() throws IOException {
252257 setUpKeyLabelFormat (false );
253258
254259 encrypt (SECRET_OPTION );
255- decrypt (SECRET_OPTION , SUCCESSFUL_EXIT_CODE );
260+ decryptSuccessfully (SECRET_OPTION );
256261
257262 String expectedKeyLabel = "SymmetricKey: LABEL:label_b64secret" ;
258263 executeInfo (expectedKeyLabel , cdocFile );
@@ -287,7 +292,7 @@ private void successfullyDecryptDocWithPublicKey(
287292 String privateKeyArg = "--key=" + privateKey ;
288293
289294 encrypt (publicKeyArg );
290- decrypt (privateKeyArg , SUCCESSFUL_EXIT_CODE );
295+ decryptSuccessfully (privateKeyArg );
291296 }
292297
293298 private void reEncryptCDocAndTestToDecrypt (
@@ -374,6 +379,14 @@ private void encryptWithTwoKeys(String encryptionArgument1, String encryptionArg
374379 executeEncryption (encryptArgs , cdocFile );
375380 }
376381
382+ private void decryptSuccessfully (String decryptArgs ) throws IOException {
383+ decrypt (decryptArgs , SUCCESSFUL_EXIT_CODE );
384+ }
385+
386+ private void failToDecrypt (String decryptArgs ) throws IOException {
387+ decrypt (decryptArgs , FAILURE_EXIT_CODE );
388+ }
389+
377390 private void decrypt (String decryptionArgument , int expectedDecryptExitCode )
378391 throws IOException {
379392
0 commit comments