Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

highlevel: detect if spec properly mounted and unmodified #4047

Merged
merged 63 commits into from
Sep 28, 2021
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
a4be8d4
highlevel: Improve documentation
Sep 8, 2021
7d804b6
highlevel: Implement check for proper mount of specification file
Sep 8, 2021
4c8b61d
highlevel: Refactor specProperlyMounted(), implement check for proper…
Sep 8, 2021
4813a72
highlevel: Add documentation for specProperlyMounted()
Sep 8, 2021
44a2476
highlevel: Fix wrong resource management
Sep 8, 2021
96360f4
highlevel: Change name of specProperlyMounted() to checkSpecProperlyM…
Sep 8, 2021
b2140ef
highlevel: Improve documentation
Sep 8, 2021
e461630
highlevel: Add sanity check to elektraClose()
Sep 8, 2021
e602f93
highlevel: Reformat C code using `scripts/dev/reformat-c`
Sep 8, 2021
9263f3a
Add license for asmonier's sha-2
Sep 15, 2021
41296f9
Add source of amosnier's sha-2
Sep 15, 2021
8f22f07
Add commit hash to sha-256.c source files
Sep 15, 2021
b39ce1a
Add function to compute sha256 hash of a key set
Sep 15, 2021
4d3003d
Include meta keys in sha 256 calculation
Sep 15, 2021
d64dfd9
Configure builds to include computeSha256OfKeySetWithoutValues
Sep 15, 2021
38b87a2
Change name of function to computeSha256OfKeySetWithoutValues to be m…
Sep 15, 2021
5220d9d
Fix wrong call order of hash_to_string() and sha_256_close()
Sep 15, 2021
b27740b
Rename variable to easier understand code
Sep 15, 2021
86508d5
Improve token calculation so it works with cascading lookups.
Sep 15, 2021
2343a09
Add inline documentation to gen.cpp
Sep 16, 2021
bffe90d
Fix wrong variable name, addendum to 24fd8e24d248cde8b104f629fbca27c9…
Sep 16, 2021
ba142c2
Fix calculation of specification key.
Sep 16, 2021
a3e33d5
Fix order of declarations in header
Sep 17, 2021
a7d72b3
Add tests for sha-256
Sep 17, 2021
5649bce
Duplicate param ks in calculateSpecificationToken() before ksCut, so …
Sep 17, 2021
e5ae659
Change calculateSpecificationToken() to not take NULL terminator into…
Sep 17, 2021
caf94f2
Add tests for hash.c
Sep 17, 2021
4bcb5aa
Add error handling to hash.c
Sep 17, 2021
d45de58
Implement checking spec token in HL API and modularize elektraOpen().
Sep 17, 2021
0e3775e
Revert type of param that was accidentally changed in a previous commit.
Sep 17, 2021
9185107
Remove "minimal validation" in favor of the new checkSpecProperlyMoun…
Sep 17, 2021
222b62f
Add missing checks for NULL to prevent segfault
Sep 17, 2021
495fcff
Implement token calculation in kdb gen highlevel
Sep 17, 2021
282691a
Update contract in the generated C sources for kdb gen tests
Sep 17, 2021
acdbc54
Replace ksRewind()/ksNext() by ksAtCursor()
Sep 17, 2021
80c8287
Improve checkSpecProperlyMounted and checkSpecToken:
Sep 18, 2021
1e78456
Remove obsolete function specMountExecuted()
Sep 18, 2021
9d824a6
Change specification checks to not use contract passed from applicati…
Sep 18, 2021
04103b8
Improve usability of checkSpecificationMountPoint()'s error messages
Sep 18, 2021
9150eee
Fix token calculation: Set parentKey namespace already for kdbGet() i…
Sep 21, 2021
fb74162
Ignore array parents in token calculation
Sep 21, 2021
82a21ad
Remove debug print statements
Sep 21, 2021
436c7f7
Update token in *.expected.c files of highlevel code generator tests.
Sep 22, 2021
018162c
Execute scripts/dev/reformat-all
Sep 22, 2021
93e93d7
Add details about how to fix errors relating to specification mountin…
Sep 22, 2021
e3217ea
Add note to function documentation about ignored array parent keys.
Sep 22, 2021
c9e0717
Improve usability of error messages for problems with specification.
Sep 22, 2021
9a2e47d
Add release notes
Sep 22, 2021
b8af270
Merge branch 'master' into 3998-detect-spec-mounted
Sep 22, 2021
dbd1f3d
Reformat .c and .md files
Sep 22, 2021
55b9044
Update kdb gen and elektra highlevel documentation to reflect changes…
Sep 22, 2021
e0fa19b
Apply patch to man pages.
Sep 22, 2021
5492b76
Improve key hierarchy of spec/token
Sep 22, 2021
3487313
Improve key hierarchy of spec/mounted
Sep 22, 2021
a0f0bba
Change error message to only advise users to kdb rm -r the spec names…
Sep 22, 2021
85a977f
Remove unused data argument
Sep 22, 2021
8257864
Merge branch 'master' into 3998-detect-spec-mounted
Sep 23, 2021
103474a
Update contract key names ".../spec/token" and ".../spec/mounted" in …
Sep 23, 2021
39f9853
Execute reformat-all script
Sep 24, 2021
bcfe59b
Fix hash.c and highlevel.cpp so that calculateSpecificationToken() do…
Sep 27, 2021
af52c71
Update token value in *.expected.c files to match that now the namesp…
Sep 27, 2021
4150c73
Merge branch 'qwepoizt-master' into 3998-detect-spec-mounted
Sep 27, 2021
39230d5
Simplify detection of array parents
Sep 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for hash.c
Tobias Schubert committed Sep 17, 2021
commit caf94f22b02f44fdcc45ce547da268684ee14f22
78 changes: 78 additions & 0 deletions tests/ctest/test_hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file
*
* @brief Tests for src/libs/ease/hash.c.
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/

#include "../../src/libs/ease/hash.c"
#include "../../src/libs/ease/sha-256.c"
#include <tests_internal.h>

/**
* Test whether token calculation for KeySet is correct.
*
* Expected results calculated via GNU coreutils' sha256sum (GNU coreutils) 8.30.
*/
static void test_keySet (void) {
char hash_string[65];
KeySet * ks = ksNew (3,
keyNew ("/sw/application/myapp/#0/current", KEY_END),
KS_END);
Key * parentKey = keyNew("/sw/application/myapp/#0/current", KEY_END);

calculateSpecificationToken (hash_string, ks, parentKey);

const char * expected = "495c901c07beb0aedd636a4d20390f503cb5a4f5af2f69d32995804059867403";
succeed_if_fmt (strcmp(hash_string, expected) == 0, "Calculated token %s did not match expected result %s.", hash_string, expected);

keyDel(parentKey);
ksDel(ks);
}


/**
* Test whether token calculation for KeySet ignores keys not equal or below parentKey.
*
* Expected results calculated via GNU coreutils' sha256sum (GNU coreutils) 8.30.
*/
static void test_onlyKeysBelowParentKey (void) {
KeySet * ksOnlyWithKeysFromMyApp =
ksNew (3,
keyNew ("/sw/application/myapp/#0/current", KEY_META, "mountpoint", "test.ecf", KEY_END),
keyNew ("/sw/application/myapp/#0/current/mykey", KEY_META, "default", "1", KEY_END),
keyNew ("/sw/application/myapp/#0/current/myotherkey", KEY_META, "opt/arg", "required", KEY_END),
KS_END);
KeySet * ksWithKeysFromTwoApps = ksDup(ksOnlyWithKeysFromMyApp);
ksAppendKey (ksWithKeysFromTwoApps, keyNew ("/sw/application/myotherapp/#0/current/somekey", KEY_META, "opt/arg", "required", KEY_END));
ksAppendKey (ksOnlyWithKeysFromMyApp, keyNew ("/sw/application/myotherapp/#0/current/someotherkey", KEY_META, "opt/arg", "required", KEY_END));

Key * parentKeyForMyApp = keyNew("/sw/application/myapp/#0/current", KEY_END);

char hash_ksWithKeysFroMyApp[65];
char hash_ksWithKeysFromTwoApps[65];
calculateSpecificationToken (hash_ksWithKeysFroMyApp, ksOnlyWithKeysFromMyApp, parentKeyForMyApp);
calculateSpecificationToken (hash_ksWithKeysFromTwoApps, ksWithKeysFromTwoApps, parentKeyForMyApp);

succeed_if (strcmp(hash_ksWithKeysFroMyApp, hash_ksWithKeysFromTwoApps) == 0, "Token calculation did not properly cut out irrelevant keys! The hash for two different KeySets that have the same set of Keys below the parentKey should be the same, but it was different!");

keyDel(parentKeyForMyApp);
ksDel(ksOnlyWithKeysFromMyApp);
ksDel(ksWithKeysFromTwoApps);
}
qwepoizt marked this conversation as resolved.
Show resolved Hide resolved

int main (int argc, char ** argv)
{
printf ("HASH TESTS\n");
printf ("==================\n\n");

init (argc, argv);

test_keySet();
test_onlyKeysBelowParentKey();

printf ("\ntest_hash RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);

return nbError;
}