kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit 6c2dfb4a966f2f644a865d3fb6c220aa8ef150b1
parent 4357d9996b10f50e81cda41a72561c546aadf5f6
Author: lash <dev@holbrook.no>
Date:   Sat, 11 May 2024 08:42:14 +0100

Generate static test content for content/cadir test

Diffstat:
MMakefile | 1+
Msrc/settings.c | 26+++++++++++++++++++++-----
Msrc/tests/Makefile | 6+++++-
Msrc/tests/cadir.c | 2+-
Msrc/tests/content.c | 6+++---
Msrc/tests/ledger.c | 2+-
Dsrc/tests/testdata_resource/1382ea21c44e0352916e17267351fcc2d890816a254caba354b2da23c2b33a9c50c5b4151ddab876d199e3c0bca26fcf75302427db5ca05e5f049f2a9f8dc9d4 | 7-------
Dsrc/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad | 7-------
Dsrc/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 | 7-------
Dsrc/tests/testdata_resource/f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7 | 2--
Mtestdata_asn1.py | 29+++++++++++++++++++++++------
11 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/Makefile b/Makefile @@ -42,6 +42,7 @@ testdata: testdata_schema rm -vrf testdata_mdb #python testdata.py python testdata_asn1.py + make -C src/tests testdata doc: pandoc -fgfm -tplain README.md > README diff --git a/src/settings.c b/src/settings.c @@ -11,7 +11,16 @@ #define KEE_SETTINGS_NAME "kee" #define KEE_SETTINGS_CAP 4096 -#define KEE_SETTINGS_ITEM_CAP 1024 +#define KEE_SETTINGS_ITEM_CAP 512 + +static void settings_get_path(struct kee_settings *z) { + char *p; + + p = getenv("KEE_PATH"); + if (p != NULL) { + memcpy(z->data, p, strlen(p)); + } +} /** * \todo make xdg optional @@ -25,19 +34,25 @@ int settings_new_from_xdg(struct kee_settings *z) { memset(z, 0, sizeof(struct kee_settings)); - z->key = (unsigned char*)"./testdata_crypt"; + //z->key = (unsigned char*)"./testdata_crypt"; - z->data = malloc(KEE_SETTINGS_CAP); + z->data = calloc(KEE_SETTINGS_CAP, 1); p = z->data; p += KEE_SETTINGS_ITEM_CAP; z->run = p; p += KEE_SETTINGS_ITEM_CAP; + z->key = p; + p += KEE_SETTINGS_ITEM_CAP; z->locktime = p; p += KEE_SETTINGS_ITEM_CAP; z->video_device = p; - s = xdgDataHome(&xdg); - sprintf((char*)z->data, "%s/%s", s, KEE_SETTINGS_NAME); + settings_get_path(z); + if (z->data == NULL) { + s = xdgDataHome(&xdg); + sprintf((char*)z->data, "%s/%s", s, KEE_SETTINGS_NAME); + } + sprintf((char*)z->key, "%s/crypt", z->data); s = xdgRuntimeDirectory(&xdg); sprintf((char*)z->run, "%s/%s", s, KEE_SETTINGS_NAME); @@ -45,6 +60,7 @@ int settings_new_from_xdg(struct kee_settings *z) { return ERR_OK; } + /*** * \todo verify default video exists */ diff --git a/src/tests/Makefile b/src/tests/Makefile @@ -20,7 +20,11 @@ obj_debug: util #test_run: $(wildcard test_*) # ./$< -test_run: + +testdata: + ln -sf ../../testdata testdata + +test_run: testdata ./test_cadir ./test_content ./test_sign diff --git a/src/tests/cadir.c b/src/tests/cadir.c @@ -13,7 +13,7 @@ int main(int argc, char **argv) { calculate_digest_algo(data, 3, digest, GCRY_MD_SHA512); l = 256; - cadiz.locator = "./testdata_resource"; + cadiz.locator = "./testdata/resource"; r = cadiz_resolve(&cadiz, digest, result, &l); if (r) { return 1; diff --git a/src/tests/content.c b/src/tests/content.c @@ -5,7 +5,7 @@ #include "hex.h" #include "cadiz.h" -const char hash_of_foo[] = "1382ea21c44e0352916e17267351fcc2d890816a254caba354b2da23c2b33a9c50c5b4151ddab876d199e3c0bca26fcf75302427db5ca05e5f049f2a9f8dc9d4"; +const char hash_of_foo[] = "184f2c1505c76d3c7b22116d9227a33c95be0a18e0ca15a4cbb983f68c31e9ce0e1a6d365a26b40c5884654c4d38778090185e5cbfad1efc16f30dc9a2231a84"; int main() { @@ -18,7 +18,7 @@ int main() { hex2bin(hash_of_foo, (unsigned char*)digest); - cadiz.locator = "./testdata_resource"; + cadiz.locator = "./testdata/resource"; /// \todo this causes a character to be emitted to console after main // l = 256; @@ -46,7 +46,7 @@ int main() { return 1; } - if (strcmp(content.subject, "Federal back single democratic growth fly image.")) { + if (strcmp(content.subject, "foo")) { kee_content_free(&content); return 1; } diff --git a/src/tests/ledger.c b/src/tests/ledger.c @@ -34,7 +34,7 @@ int test_parse() { Cadiz cadiz; char data[1024]; - cadiz.locator = "./testdata_resource"; + cadiz.locator = "./testdata/resource"; kee_ledger_init(&ledger); kee_ledger_reset_cache(&ledger); diff --git a/src/tests/testdata_resource/1382ea21c44e0352916e17267351fcc2d890816a254caba354b2da23c2b33a9c50c5b4151ddab876d199e3c0bca26fcf75302427db5ca05e5f049f2a9f8dc9d4 b/src/tests/testdata_resource/1382ea21c44e0352916e17267351fcc2d890816a254caba354b2da23c2b33a9c50c5b4151ddab876d199e3c0bca26fcf75302427db5ca05e5f049f2a9f8dc9d4 @@ -1,7 +0,0 @@ -Subject: Federal back single democratic growth fly image. -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: quoted-printable -MIME-Version: 1.0 - -Relate single collection month difference. Spring perhaps maintain purpose tr= -aditional. diff --git a/src/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad b/src/tests/testdata_resource/3aba8490187f543270b48e770bb272021f8fdb22f584080fc9d4d02553f4504624122d99ffc9254cdb8a2ef3826e47f60e1e7b5ec28b635fbba1141e3f486aad @@ -1,7 +0,0 @@ -Subject: Opportunity price prove nature system recent live. -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: quoted-printable -MIME-Version: 1.0 - -Listen place sport air. His product college. Hundred today perform technology= - challenge tree. diff --git a/src/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 b/src/tests/testdata_resource/c333b18dfa822c3ce875de07d54d932ed631aaa7f996153a120bda81e2f0717f4f5e67547019bcd8af0ba6ecba95313bbdc5e43385670d67c24ef76879514ad6 @@ -1,7 +0,0 @@ -Subject: Receive enter personal develop. -Content-Type: text/plain; charset="utf-8" -Content-Transfer-Encoding: quoted-printable -MIME-Version: 1.0 - -Half example bar ready none possible all. Carry field respond. Peace law acti= -vity right remain operation people. diff --git a/src/tests/testdata_resource/f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7 b/src/tests/testdata_resource/f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7 @@ -1 +0,0 @@ -foo -\ No newline at end of file diff --git a/testdata_asn1.py b/testdata_asn1.py @@ -50,7 +50,7 @@ def padbytes(b, padsize=4096): def db_init(d): - d = os.path.join(d, 'testdata_mdb') + d = os.path.join(d, 'testdata', 'mdb') logg.info('using d for db' + d) try: @@ -61,13 +61,24 @@ def db_init(d): return d +def data_add(data_dir, k, v): + fp = os.path.join(data_dir, k.hex()) + f = open(fp, 'wb') + f.write(v) + f.close() + + class LedgerContent(email.message.EmailMessage): - def __init__(self): + def __init__(self, subject=None, body=None): super(LedgerContent, self).__init__() self.set_default_type("text/plain") - self.add_header("Subject", fake.sentence()) - self.set_content(fake.paragraph()) + if subject == None: + subject = fake.sentence() + self.add_header("Subject", subject) + if body == None: + body = fake.paragraph() + self.set_content(body) def kv(self): @@ -439,15 +450,21 @@ def generate_ledger(dbi, data_dir, signer, bob_name, entry_count=3, alice=None, if __name__ == '__main__': d = os.path.dirname(__file__) - data_dir = os.path.join(d, 'testdata_resource') + data_dir = os.path.join(d, 'testdata', 'resource') try: shutil.rmtree(data_dir) except FileNotFoundError: pass os.makedirs(data_dir) + + v = b'foo' + h = hashlib.sha512() + h.update(v) + k = h.digest() + data_add(data_dir, k, v) d = os.path.dirname(__file__) - crypto_dir = os.path.join(d, 'testdata_crypt') + crypto_dir = os.path.join(d, 'testdata', 'crypt') try: shutil.rmtree(crypto_dir) except FileNotFoundError: