1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Add cipher parameters to TEST_STORAGE_GET() macro.

This commit is contained in:
Cynthia Shang 2021-07-09 15:59:17 -04:00 committed by David Steele
parent 3c8819e10f
commit f2ec4e00a4
3 changed files with 27 additions and 6 deletions

View File

@ -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"/>

View File

@ -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

View File

@ -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)