]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add procedure in test-plugin and metadata-test to check MetaEmail table
authorEric Bollengier <eric@baculasystems.com>
Thu, 16 Sep 2021 10:50:20 +0000 (12:50 +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 [new file with mode: 0755]

index c1dd5cabc51e676302ce8e89519bab7d6e952aec..b2638613b8a1de994749693491b1a12c3742c6df 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2000-2022 Kern Sibbald
+   Copyright (C) 2000-2023 Kern Sibbald
 
    The original author of Bacula is Kern Sibbald, with contributions
    from many others, a complete list can be found in the file AUTHORS.
@@ -41,7 +41,7 @@ extern "C" {
 
 static const int dbglvl = 000;
 
-#define PLUGIN_LICENSE      "AGPLv3"
+#define PLUGIN_LICENSE      "Bacula Systems(R) SA"
 #define PLUGIN_AUTHOR       "Kern Sibbald"
 #define PLUGIN_DATE         "September 2017"
 #define PLUGIN_VERSION      "4"
@@ -707,7 +707,6 @@ 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();
@@ -720,34 +719,19 @@ 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   \"EmailReceivedTime\" : \"Sep 15, 2021, 12:39:19 PM\",\n   \"EmailSentTime\" : \"Sep 15, 2021, 12:39:19 PM\",\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 \"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   \"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");
-         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\": \"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   \"AttachmentOwner\" : \"xxxx\", \"AttachmentTenant\" : \"xxxx\", \"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!!!!!! CV.pdf\n");
-      return bRC_OK;
 
-   } else {
-      return bRC_Stop;
+      } else {
+         return bRC_Stop;
+      }
    }
 
    if (p_ctx->nb_obj < 2) {
@@ -788,7 +772,11 @@ static bRC endBackupFile(bpContext *ctx)
     * We would return bRC_More if we wanted startBackupFile to be
     * called again to backup another file
     */
-   return bRC_More;
+   if (p_ctx->nb_obj >= 8) {
+      return bRC_OK;
+   } else {
+      return bRC_More;
+   }
 }
 
 
diff --git a/regress/tests/metadata-test b/regress/tests/metadata-test
new file mode 100755 (executable)
index 0000000..a425ecd
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2021 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# Run test-plugin-fd.  Note, this plugin is for testing
+#   new features and probably should not be run in normal
+#   testing
+#
+TestName="metadata-test"
+JobName=TestPluginTest
+. scripts/functions
+
+scripts/cleanup
+scripts/copy-plugin-confs
+file=encrypt-bug.jpg
+rm -rf ${cwd}/tmp/*
+echo "${cwd}/build/src" >${cwd}/tmp/file-list
+
+# Build and install the test plugin
+cd ${cwd}/build/src/plugins/fd
+make
+if [ $? -ne 0 ]; then
+   print_debug "Failed to build test plugin!"
+   exit 1
+fi
+
+make install-test-plugin
+if [ $? -ne 0 ]; then
+   print_debug "Failed to install test plugin!"
+   exit 1
+fi
+
+cd ${cwd}
+
+start_test
+
+cat <<END_OF_DATA >${cwd}/tmp/bconcmds
+@output /dev/null
+messages
+@$out $tmp/log1.out
+label storage=File1 volume=TestVolume001
+run job=$JobName storage=File1 yes
+wait
+messages
+@$out $tmp/log2.out
+.jlist jobs
+sql
+SELECT EmailSubject, EmailFrom, EmailTo, JobId, FileIndex FROM MetaEmail;
+
+
+@$out $tmp/log3.out
+sql
+SELECT AttachmentName, JobId, FileIndex FROM MetaAttachment;
+
+quit
+END_OF_DATA
+
+run_bacula
+stop_bacula
+
+# Temporary check, to replace with list command
+nb=`grep eric@bacula $tmp/log2.out | wc -l`
+if [ $nb != 2 ]; then
+    print_debug "ERROR: Should find two emails in the catalog"
+    estat=1
+fi
+
+
+end_test