61
61
import org .junit .rules .RuleChain ;
62
62
import org .junit .rules .TestRule ;
63
63
import org .junit .runner .RunWith ;
64
+ import org .xmlpull .v1 .XmlPullParser ;
65
+ import org .xmlpull .v1 .XmlPullParserException ;
66
+ import org .xmlpull .v1 .XmlPullParserFactory ;
64
67
65
68
import java .io .File ;
66
69
import java .io .FileInputStream ;
67
70
import java .io .IOException ;
68
71
import java .io .InputStream ;
72
+ import java .io .InputStreamReader ;
73
+ import java .io .Reader ;
74
+ import java .nio .charset .StandardCharsets ;
69
75
import java .util .Collection ;
70
76
import java .util .List ;
77
+ import java .util .Locale ;
71
78
72
79
import javax .crypto .Cipher ;
73
80
import javax .crypto .SecretKey ;
@@ -183,7 +190,9 @@ public void testPlainVaultExportHtml() {
183
190
onView (withText (R .string .export_format_html )).inRoot (RootMatchers .isPlatformPopup ()).perform (click ());
184
191
onView (withId (android .R .id .button1 )).perform (click ());
185
192
onView (withId (R .id .checkbox_accept )).perform (click ());
186
- doExport ();
193
+ File file = doExport ();
194
+
195
+ checkHtmlExport (file );
187
196
}
188
197
189
198
@ Test
@@ -196,7 +205,9 @@ public void testEncryptedVaultExportHtml() {
196
205
onView (withText (R .string .export_format_html )).inRoot (RootMatchers .isPlatformPopup ()).perform (click ());
197
206
onView (withId (android .R .id .button1 )).perform (click ());
198
207
onView (withId (R .id .checkbox_accept )).perform (click ());
199
- doExport ();
208
+ File file = doExport ();
209
+
210
+ checkHtmlExport (file );
200
211
}
201
212
202
213
@ Test
@@ -380,6 +391,26 @@ private void readTxtExport(File file) {
380
391
checkReadEntries (entries );
381
392
}
382
393
394
+ private void checkHtmlExport (File file ) {
395
+ try (InputStream inStream = new FileInputStream (file )) {
396
+ Reader inReader = new InputStreamReader (inStream , StandardCharsets .UTF_8 );
397
+ XmlPullParserFactory factory = XmlPullParserFactory .newInstance ();
398
+ XmlPullParser parser = factory .newPullParser ();
399
+ parser .setInput (inReader );
400
+ while (parser .getEventType () != XmlPullParser .START_TAG ) {
401
+ parser .next ();
402
+ }
403
+ if (!parser .getName ().toLowerCase (Locale .ROOT ).equals ("html" )) {
404
+ throw new RuntimeException ("not an html document!" );
405
+ }
406
+ while (parser .getEventType () != XmlPullParser .END_DOCUMENT ) {
407
+ parser .next ();
408
+ }
409
+ } catch (IOException | XmlPullParserException e ) {
410
+ throw new RuntimeException ("Unable to read html export file" , e );
411
+ }
412
+ }
413
+
383
414
private void checkReadEntries (Collection <VaultEntry > entries ) {
384
415
List <VaultEntry > vectors = VaultEntries .get ();
385
416
assertEquals (vectors .size (), entries .size ());
0 commit comments