]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add tests for the list metadata command
authorEric Bollengier <eric@baculasystems.com>
Wed, 22 Sep 2021 15:01:06 +0000 (17:01 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 6 Sep 2023 07:49:00 +0000 (09:49 +0200)
bacula/src/plugins/fd/test-plugin-fd.c
regress/tests/metadata-test

index f29e2a7641a649c4877685e5c2dd7c41915b7483..45c5ade7d54b26897a6efbe4c3f020a04aeafc00 100644 (file)
@@ -707,6 +707,7 @@ static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
       if (p_ctx->job_level == 'F') {
          sp->type = FT_REG;
          sp->link = sp->fname = (char *)"/@testplugin/test1.zero";
+         stat("/etc/passwd", &sp->statp);
 
          /* Assign some metadata for the fake file */
          p_ctx->meta_mgr->reset();
@@ -719,19 +720,37 @@ static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
          }";
 
          /*TODO change payload to catalog packet when it's defined*/
-         const char *m2 = "{\n   \"EmailBodyPreview\" : \"pretium sollicitudin vocent vulputate te semper partiendo mi cu consectetur antiopam commodo nominavi facilis iaculis montes veniam congue vitae eam ponderum idque doctus condimentum patrioque epicurei amet nominavi possit ancillae quo bibendum definition\",\n   \"EmailCc\" : \"\",\n   \"EmailConversationId\" : \"AAQkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQAQAE9i5o-JJZ5HvgNdGUT4uEA=\",\n   \"EmailFolderName\" : \"jorgegea/users/jonis@jorgegea.onmicrosoft.com/email/REGRESS_20210915123756\",\n   \"EmailFrom\" : \"eric@bacula\",\n   \"EmailHasAttachment\" : 0,\n   \"EmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKyCAAB-S4yOymgVRpR5CA4-eilAAABABPgVAAA=\",\n   \"EmailImportance\" : \"NORMAL\",\n   \"EmailInternetMessageId\" : \"<AM9P190MB144311378E81EB6E8400641689DB9@AM9P190MB1443.EURP190.PROD.OUTLOOK.COM>\",\n   \"EmailIsDraft\" : 0,\n   \"EmailIsRead\" : 1,\n   \"EmailTime\" : \"Sep 15, 2021, 12:39:19 PM\",\n   \"EmailOwner\" : \"xxxx\",\n \"EmailSize\" : \"4096\",\n \"EmailTenant\": \"xxxxxx-xxxxxx-xxxxxx-xxxx\",\n  \"EmailSubject\" : \"Elaboraret Tellus - t\",\n   \"EmailTags\" : \"\",\n   \"EmailTo\" : \"jorge@bacula\",\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"EMAIL\",\n   \"Version\" : 1\n }";
+         const char *m2 = "{\n   \"EmailBodyPreview\" : \"pretium sollicitudin vocent vulputate te semper partiendo mi cu consectetur antiopam commodo nominavi facilis iaculis montes veniam congue vitae eam ponderum idque doctus condimentum patrioque epicurei amet nominavi possit ancillae quo bibendum definition\",\n   \"EmailCc\" : \"\",\n   \"EmailConversationId\" : \"AAQkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQAQAE9i5o-JJZ5HvgNdGUT4uEA=\",\n   \"EmailFolderName\" : \"jorgegea/users/jonis@jorgegea.onmicrosoft.com/email/REGRESS_20210915123756\",\n   \"EmailFrom\" : \"eric@bacula\",\n   \"EmailHasAttachment\" : 0,\n   \"EmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKyCAAB-S4yOymgVRpR5CA4-eilAAABABPgVAAA=\",\n   \"EmailImportance\" : \"NORMAL\",\n   \"EmailInternetMessageId\" : \"<AM9P190MB144311378E81EB6E8400641689DB9@AM9P190MB1443.EURP190.PROD.OUTLOOK.COM>\",\n   \"EmailIsDraft\" : 0,\n   \"EmailIsRead\" : 1,\n   \"EmailTime\" : \"Sep 15, 2021, 12:39:19 PM\",\n   \"EmailOwner\" : \"xxxx\",\n \"EmailSize\" : 4096,\n \"EmailTenant\": \"xxxxxx-xxxxxx-xxxxxx-xxxx\",\n  \"EmailSubject\" : \"Elaboraret Tellus - t\",\n   \"EmailTags\" : \"\",\n   \"EmailTo\" : \"jorge@bacula\",\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"EMAIL\",\n   \"Version\" : 1\n }";
 
-         const char *m3 = "{\n   \"AttachmentContentType\" : \"application/octet-stream\",\n   \"AttachmentEmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKybAAB-S4yOymgVRpR5CA4-eilAAABABUnfAAA=\",\n   \"AttachmentId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKybAAB-S4yOymgVRpR5CA4-eilAAABABUnfAAABEgAQAKT86cEi1S9PgA8I5xS0vKA=\",\n   \"AttachmentIsInline\" : 0,\n   \"AttachmentName\" : \"Ancillae.gen\",\n  \"AttachmentSize\" : \"81920\",\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"ATTACHMENT\",\n   \"Version\" : 1\n}";
+         const char *m3 = "{\n   \"AttachmentContentType\" : \"application/octet-stream\",\n   \"AttachmentEmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKybAAB-S4yOymgVRpR5CA4-eilAAABABUnfAAA=\",\n   \"AttachmentId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKybAAB-S4yOymgVRpR5CA4-eilAAABABUnfAAABEgAQAKT86cEi1S9PgA8I5xS0vKA=\",\n   \"AttachmentIsInline\" : 0,\n   \"AttachmentName\" : \"Ancillae.gen\",\n  \"AttachmentSize\" : 81920,\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"ATTACHMENT\",\n   \"Version\" : 1\n}";
          p_ctx->meta_mgr->add_packet(plugin_meta_blob, strlen(m1)+1, (void *)m1);
          p_ctx->meta_mgr->add_packet(plugin_meta_catalog_email, strlen(m2)+1, (void *)m2);
          p_ctx->meta_mgr->add_packet(plugin_meta_catalog_email, strlen(m3)+1, (void *)m3);
 
          sp->plug_meta = p_ctx->meta_mgr;
          Dmsg0(0, "Insert metadata!!!!!!\n");
-
-      } else {
-         return bRC_Stop;
+         return bRC_OK;
       }
+   } else if (p_ctx->nb_obj == 8) {
+      p_ctx->nb_obj++;
+      sp->type = FT_REG;
+      sp->link = sp->fname = (char *)"/@testplugin/test2.zero";
+      stat("/etc/passwd", &sp->statp);
+
+      /* Assign some metadata for the fake file */
+      p_ctx->meta_mgr->reset();
+
+      /*TODO change payload to catalog packet when it's defined*/
+      const char *m2 = "{\n   \"EmailBodyPreview\" : \"Hello John, say hello to Veronica. Best Regards\",\n   \"EmailCc\" : \"veronica@gmail.com\",\n   \"EmailConversationId\" : \"AAQkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQAQAE9i5o-JJZ5HvgNdGUTddEA=\",\n   \"EmailFolderName\" : \"jorgegea/users/jonis@jorgegea.onmicrosoft.com/email/REGRESS_20210915123756\",\n   \"EmailFrom\" : \"eric@bacula\",\n   \"EmailHasAttachment\" : 1,\n   \"EmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2Yx\",\n   \"EmailImportance\" : \"IMPORTANT\",\n   \"EmailInternetMessageId\" : \"<AM9P190MB144311378E81EB6E8400641689Ddd@AM9P190MB1443.EURP190.PROD.OUTLOOK.COM>\",\n   \"EmailIsDraft\" : 1,\n   \"EmailIsRead\" : 0,\n   \"EmailTime\" : \"Sep 15, 2021, 12:40:19 PM\",\n   \"EmailOwner\" : \"xxxx\",\n \"EmailSize\" : 4096,\n \"EmailTenant\": \"xxxxxx-xxxxxx-xxxxxx-xxxx\",\n  \"EmailSubject\" : \"Hello From regress\",\n   \"EmailTags\" : \"draft,important,work\",\n   \"EmailTo\" : \"john@bacula\",\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"EMAIL\",\n   \"Version\" : 1\n }";
+      const char *m3 = "{\n   \"AttachmentContentType\" : \"application/octet-stream\",\n   \"AttachmentEmailId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2Yx\",\n   \"AttachmentId\" : \"AAMkAGZmZjBlMjI0LTMxMmEtNDFkMi1hM2YxLWEzNjI5MjY4M2JkMQBGAAAAAAChUr1sDFmcSYm7PK3nvLVxBwB-S4yOymgVRpR5CA4-eilAAABABKybAAB-S4yOymgVRpR5CA4-eilAAABABUnfAAABEgAQAKT86cEi1S9PgA8I5xS0vKA=\",\n   \"AttachmentIsInline\" : 0,\n   \"AttachmentName\" : \"CV.pdf\",\n  \"AttachmentSize\" : 81920,\n   \"Plugin\" : \"m365\",\n   \"Type\" : \"ATTACHMENT\",\n   \"Version\" : 1\n}";
+      p_ctx->meta_mgr->add_packet(plugin_meta_catalog_email, strlen(m2)+1, (void *)m2);
+      p_ctx->meta_mgr->add_packet(plugin_meta_catalog_email, strlen(m3)+1, (void *)m3);
+      sp->plug_meta = p_ctx->meta_mgr;
+      Dmsg0(0, "Insert metadata!!!!!!\n");
+      return bRC_OK;
+
+   } else {
+      return bRC_Stop;
    }
 
    if (p_ctx->nb_obj < 2) {
@@ -772,11 +791,7 @@ static bRC endBackupFile(bpContext *ctx)
     * We would return bRC_More if we wanted startBackupFile to be
     * called again to backup another file
     */
-   if (p_ctx->nb_obj >= 8) {
-      return bRC_OK;
-   } else {
-      return bRC_More;
-   }
+   return bRC_More;
 }
 
 
index a425ecdf7cbe99ef6a0b34e9a86f7e2799fa40fc..d36ca30e8df8c0bcc1c75cba977f05b169255d05 100755 (executable)
@@ -53,6 +53,34 @@ SELECT EmailSubject, EmailFrom, EmailTo, JobId, FileIndex FROM MetaEmail;
 sql
 SELECT AttachmentName, JobId, FileIndex FROM MetaAttachment;
 
+setdebug level=50 tags=sql trace=1 dir
+@$out $tmp/log4.out
+.jlist metadata type=email all="eric iaculis"
+@$out $tmp/log5.out
+.jlist metadata type=email all="eric iaculis" jobid=10
+@$out $tmp/log6.out
+.jlist metadata type=email all="eric iaculis" limit=1
+@$out $tmp/log8.out
+.jlist metadata type=email all=eric orderby=time
+@$out $tmp/log9.out
+.jlist metadata type=email all=eric orderby=time order=desc
+@$out $tmp/log10.out
+.jlist metadata type=email from=eric to=john subject=regress bodypreview=regards
+@$out $tmp/log11.out
+.jlist metadata type=email bodypreview=veronica
+@$out $tmp/log12.out
+.jlist metadata type=email hasattachment=1
+@$out $tmp/log13.out
+.jlist metadata type=email minsize=10 maxsize=100000
+@$out $tmp/log14.out
+.jlist metadata type=email minsize=100000 hasattachment=1
+@$out $tmp/log15.out
+.jlist metadata type=email client=test1-fd
+@$out $tmp/log16.out
+.jlist metadata type=email client=$HOST-fd
+@$out $tmp/log17.out
+.jlist metadata type=email tags=important
+setdebug level=0 tags= dir
 quit
 END_OF_DATA
 
@@ -61,10 +89,152 @@ stop_bacula
 
 # Temporary check, to replace with list command
 nb=`grep eric@bacula $tmp/log2.out | wc -l`
-if [ $nb != 2 ]; then
+if [ $nb != 4 ]; then
     print_debug "ERROR: Should find two emails in the catalog"
     estat=1
 fi
 
+# Should find 2 mails with both words
+grep '{' $tmp/log4.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 2);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log4.out"
+    estat=1
+fi
+
+# Should find nothing (jobid=10)
+grep '\[' $tmp/log5.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 0);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log5.out"
+    estat=1
+fi
+
+# Should find one line (limit=1)
+grep '{' $tmp/log6.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 1);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log6.out"
+    estat=1
+fi
+
+# Should find 4 emails sorted by time ASC
+grep '{' $tmp/log8.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 4 && $j->[0]->{emailtime} eq "2021-09-15 12:39:19");'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log8.out"
+    estat=1
+fi
+
+# Should find 4 emails sorted by time DESC
+grep '{' $tmp/log9.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 4 && $j->[0]->{emailtime} eq "2021-09-15 12:40:19");'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log9.out"
+    estat=1
+fi
+
+# Should find 2 emails, matching all criteria
+grep '{' $tmp/log10.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 2);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log10.out"
+    estat=1
+fi
+
+# Should find 2 emails, matching bodypreview criteria
+grep '{' $tmp/log11.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 2);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log11.out"
+    estat=1
+fi
+
+# Should find 2 emails, matching hasattachment
+grep '{' $tmp/log12.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 2);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log12.out"
+    estat=1
+fi
+
+# Should find 4 emails, size filter
+grep '{' $tmp/log13.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 4 && $j->[0]->{emailsize} < 100000);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log13.out"
+    estat=1
+fi
+
+# Should find 0 email, size filter
+grep '\[' $tmp/log14.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 0);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log14.out"
+    estat=1
+fi
+
+# Should find 0 email, client filter
+grep '\[' $tmp/log15.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 0);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log15.out"
+    estat=1
+fi
+
+# Should find 4 email, client filter OK
+grep '{' $tmp/log16.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 4);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log16.out"
+    estat=1
+fi
+
+# Should find 2 email, tags filter
+grep '{' $tmp/log17.out | perl -MJSON -e '
+$l = <>;
+$j = JSON::decode_json($l) ;
+exit (scalar(@$j) == 2);'
+
+if [ $? != 1 ]; then
+    print_debug "ERROR: Incorrect data in $tmp/log17.out"
+    estat=1
+fi
 
 end_test