|
| 1 | +#include "test_util.h" |
| 2 | +#include "src/query_node.h" |
| 3 | +#include "src/obfuscation/obfuscation_api.h" |
| 4 | + |
| 5 | +#include <stdlib.h> |
| 6 | +#include <string.h> |
| 7 | + |
| 8 | +struct RSQueryNode; |
| 9 | +char *Obfuscate_QueryNode(struct RSQueryNode *node); |
| 10 | + |
| 11 | +enum { |
| 12 | + IndexSize = MAX_OBFUSCATED_INDEX_NAME, |
| 13 | + FieldSize = MAX_OBFUSCATED_FIELD_NAME, |
| 14 | + FieldPathSize = MAX_OBFUSCATED_PATH_NAME, |
| 15 | + DocumentSize = MAX_OBFUSCATED_DOCUMENT_NAME |
| 16 | +}; |
| 17 | + |
| 18 | +#define DEFINE_OBJECT_OBFUSCATION_TESTS(name) \ |
| 19 | +int testSimple ## name ## Obfuscation() { \ |
| 20 | + char obfuscated[name##Size]; \ |
| 21 | + Obfuscate_##name(1, obfuscated); \ |
| 22 | + return strcmp(obfuscated, #name"@1"); \ |
| 23 | +} \ |
| 24 | +int testMax ## name ## Obfuscation() { \ |
| 25 | + char obfuscated[name##Size]; \ |
| 26 | + Obfuscate_##name(UINT64_MAX, obfuscated); \ |
| 27 | + return strcmp(obfuscated, #name"@18446744073709551615"); \ |
| 28 | +} |
| 29 | + |
| 30 | +DEFINE_OBJECT_OBFUSCATION_TESTS(Index) |
| 31 | +DEFINE_OBJECT_OBFUSCATION_TESTS(Field) |
| 32 | +DEFINE_OBJECT_OBFUSCATION_TESTS(FieldPath) |
| 33 | +DEFINE_OBJECT_OBFUSCATION_TESTS(Document) |
| 34 | + |
| 35 | +int testTextObfuscation() { |
| 36 | + char *obfuscated = Obfuscate_Text("hello"); |
| 37 | + return strcmp(obfuscated, "Text"); |
| 38 | +} |
| 39 | + |
| 40 | +int testNumberObfuscation() { |
| 41 | + char *obfuscated = Obfuscate_Number(rand()); |
| 42 | + return strcmp(obfuscated, "Number"); |
| 43 | +} |
| 44 | + |
| 45 | +int testVectorObfuscation() { |
| 46 | + char *obfuscated = Obfuscate_Vector("hello", 5); |
| 47 | + return strcmp(obfuscated, "Vector"); |
| 48 | +} |
| 49 | + |
| 50 | +int testTagObfuscation() { |
| 51 | + char *obfuscated = Obfuscate_Tag("hello"); |
| 52 | + return strcmp(obfuscated, "Tag"); |
| 53 | +} |
| 54 | + |
| 55 | +int testGeoObfuscation() { |
| 56 | + char *obfuscated = Obfuscate_Geo(1, 2); |
| 57 | + return strcmp(obfuscated, "Geo"); |
| 58 | +} |
| 59 | + |
| 60 | +int testGeoShapeObfuscation() { |
| 61 | + char *obfuscated = Obfuscate_GeoShape(); |
| 62 | + return strcmp(obfuscated, "GeoShape"); |
| 63 | +} |
| 64 | + |
| 65 | +int testQueryNodeObfuscation() { |
| 66 | + const char* expected[] = { |
| 67 | + "Phrase", |
| 68 | + "Union", |
| 69 | + "Token", |
| 70 | + "Numeric", |
| 71 | + "Not", |
| 72 | + "Optional", |
| 73 | + "Geo", |
| 74 | + "Geometry", |
| 75 | + "Prefix", |
| 76 | + "Ids", |
| 77 | + "Wildcard", |
| 78 | + "Tag", |
| 79 | + "Fuzzy", |
| 80 | + "LexRange", |
| 81 | + "Vector", |
| 82 | + "WildcardQuery", |
| 83 | + "Null", |
| 84 | + "Missing" |
| 85 | + }; |
| 86 | + for (int i = QN_PHRASE; i < QN_MAX; ++i) { |
| 87 | + struct RSQueryNode node = { |
| 88 | + .type = i, |
| 89 | + }; |
| 90 | + char *obfuscated = Obfuscate_QueryNode(&node); |
| 91 | + ASSERT(strcmp(obfuscated, expected[i - 1]) == 0); |
| 92 | + } |
| 93 | + return 0; |
| 94 | +} |
| 95 | + |
| 96 | +TEST_MAIN({ |
| 97 | + TESTFUNC(testSimpleIndexObfuscation); |
| 98 | + TESTFUNC(testMaxIndexObfuscation); |
| 99 | + TESTFUNC(testSimpleFieldObfuscation); |
| 100 | + TESTFUNC(testMaxFieldObfuscation); |
| 101 | + TESTFUNC(testSimpleFieldPathObfuscation); |
| 102 | + TESTFUNC(testMaxFieldPathObfuscation); |
| 103 | + TESTFUNC(testSimpleDocumentObfuscation); |
| 104 | + TESTFUNC(testMaxDocumentObfuscation); |
| 105 | + TESTFUNC(testTextObfuscation); |
| 106 | + TESTFUNC(testNumberObfuscation); |
| 107 | + TESTFUNC(testVectorObfuscation); |
| 108 | + TESTFUNC(testTagObfuscation); |
| 109 | + TESTFUNC(testGeoObfuscation); |
| 110 | + TESTFUNC(testGeoShapeObfuscation); |
| 111 | + TESTFUNC(testQueryNodeObfuscation); |
| 112 | +}) |
0 commit comments