pgbackrest.git / summary / log / commit / refs

commit    f2ec4e00a4c4c388a8f1b094381fd566a3dc9aa7
Author:   Cynthia Shang <cynthia.shang@crunchydata.com>
Commit:   David Steele <david@pgmasters.net>
Date:     Fri Jul 09 19:59:17 2021 +0000

    Add cipher parameters to TEST_STORAGE_GET() macro.


doc/xml/release.xml | 1 + test/src/common/harnessStorage.c | 26 ++++++++++++++++++++++---- test/src/common/harnessStorage.h | 6 ++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 831f9bef3..2bba1439d 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -173,6 +173,7 @@ <commit subject="Update command/control and command/command tests to use standard patterns."> <github-pull-request id="1456"/> </commit> + <commit subject="Add cipher parameters to TEST_STORAGE_GET() macro."/> <release-item-contributor-list> <release-item-contributor id="cynthia.shang"/> diff --git a/test/src/common/harnessStorage.c b/test/src/common/harnessStorage.c index 230960b7e..91538700d 100644 --- a/test/src/common/harnessStorage.c +++ b/test/src/common/harnessStorage.c @@ -175,7 +175,7 @@ hrnStorageInfoListCallback(void *callbackData, const StorageInfo *info) /**********************************************************************************************************************************/ void -testStorageGet(const Storage *const storage, const char *const file, const char *const expected, const TestStorageGetParam param) +testStorageGet(const Storage *const storage, const char *const file, const char *const expected, TestStorageGetParam param) { hrnTestResultBegin(__func__, false); @@ -184,10 +184,28 @@ testStorageGet(const Storage *const storage, const char *const file, const char const String *const fileFull = storagePathP(storage, STR(file)); - printf("test content of '%s'", strZ(fileFull)); + // Declare an information filter for displaying paramaters to the output + String *const filter = strNew(); + + StorageRead *read = storageNewReadP(storage, fileFull); + IoFilterGroup *filterGroup = ioReadFilterGroup(storageReadIo(read)); + + // Add decrypt filter + if (param.cipherType != 0 && param.cipherType != cipherTypeNone) + { + // Default to main cipher pass + if (param.cipherPass == NULL) + param.cipherPass = TEST_CIPHER_PASS; + + ioFilterGroupAdd(filterGroup, cipherBlockNew(cipherModeDecrypt, param.cipherType, BUFSTRZ(param.cipherPass), NULL)); + + strCatFmt(filter, "enc[%s,%s] ", strZ(strIdToStr(param.cipherType)), param.cipherPass); + } + + printf("test content of %s'%s'", strEmpty(filter) ? "" : strZ(filter), strZ(fileFull)); hrnTestResultComment(param.comment); - hrnTestResultZ(strZ(strNewBuf(storageGetP(storageNewReadP(storage, fileFull)))), expected, harnessTestResultOperationEq); + hrnTestResultZ(strZ(strNewBuf(storageGetP(read))), expected, harnessTestResultOperationEq); if (param.remove) storageRemoveP(storage, fileFull, .errorOnMissing = true); @@ -423,7 +441,7 @@ hrnStoragePut( ASSERT(param.compressType == compressTypeGz || param.compressType == compressTypeBz2); ioFilterGroupAdd(filterGroup, compressFilter(param.compressType, 1)); - strCatFmt(filter, "%scmp[%s]", strEmpty(filter) ? "" : "/", strZ(compressTypeStr(param.compressType))); + strCatFmt(filter, "%scmp[%s]", strEmpty(filter) ? "" : "/", strZ(compressTypeStr(param.compressType))); } // Add encrypted filter diff --git a/test/src/common/harnessStorage.h b/test/src/common/harnessStorage.h index e5394f4a7..0fc20bd57 100644 --- a/test/src/common/harnessStorage.h +++ b/test/src/common/harnessStorage.h @@ -17,14 +17,16 @@ typedef struct TestStorageGetParam { VAR_PARAM_HEADER; bool remove; // Remove file after testing? + CipherType cipherType; + const char *cipherPass; // If pass=null but cipherType set, defaults to TEST_CIPHER_PASS const char *comment; // Comment } TestStorageGetParam; -#define TEST_STORAGE_GET(storage, file, content, ...) \ +#define TEST_STORAGE_GET(storage, file, expected, ...) \ do \ { \ hrnTestLogPrefix(__LINE__); \ - testStorageGet(storage, file, content, (TestStorageGetParam){VAR_PARAM_INIT, __VA_ARGS__}); \ + testStorageGet(storage, file, expected, (TestStorageGetParam){VAR_PARAM_INIT, __VA_ARGS__}); \ } \ while (0) [parent: 3c8819e10f9e]