From cf7a81b22a4d47286cffa805efb4ea087827f897 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 30 Aug 2022 17:42:40 -0700 Subject: [PATCH] add option to sign on import.. If the identity changed, generate a new uuid, and set created_by and modified appropriately... --- ui/fixtures/cmd.import.json | 22 ++++++++++++++++++++++ ui/medashare/cli.py | 20 +++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 ui/fixtures/cmd.import.json diff --git a/ui/fixtures/cmd.import.json b/ui/fixtures/cmd.import.json new file mode 100644 index 0000000..56feea8 --- /dev/null +++ b/ui/fixtures/cmd.import.json @@ -0,0 +1,22 @@ +[ +{ + "title": "gen ident", + "cmd": [ "genident", "name=A Test User" ], + "exit": 0 +}, +{ + "title": "that a sign import can be done", + "cmd": [ "import", "--sign" ], + "stdin": "{\"created_by_ref\": \"2de7a389-410c-4755-8c62-f3254c7e971e\", \"dir\": \"\", \"filename\": \"FreeBSD-14.0-CURRENT-arm64-aarch64-ROCK64-20220331-d53927b0bae-254105.img.xz\", \"hashes\": [\"sha512:3eba2aa09a79fd7adec32ace93c6725e75b91a55192b5bfa827b893fae1c2cdbc040e282138387797f245c1f27da5e8ff7a02f59ff75c73b3d999d1e0a8752ad\"], \"id\": \"d9e8fc1a-9794-5e70-b67b-11d708ec8947\", \"modified\": \"2022-08-02T07:52:50.216428Z\", \"mtime\": \"2022-03-31T10:15:14.000000Z\", \"sig\": \"F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA\", \"size\": 551750948, \"type\": \"file\", \"uuid\": \"89544934-6ed9-46ca-b8d0-77c5209f798d\"}\n" +}, +{ + "special": "verify store object cnt", + "comment": "and the objects were imported", + "count": 1 +}, +{ + "title": "that the created_by_ref was changed", + "cmd": [ "dump" ], + "stdout_nre": "2de7a389-410c-4755-8c62-f3254c7e971|2022-08-02T07:52:50.216428Z|F3Ch1BQB57RAgFNKNF5btCRZS3jFmafhvcdoWuu6WHo5JzyhuQ7jNvZkv4tzgWqlMfPecLJMMmSAMcwqorykDWi854ZfKUm3F-JOTk8R7qRKdHd23rwVGDEXtVHv-kynkh8WemPsfc2V1HT8JKG9NhwA|89544934-6ed9-46ca-b8d0-77c5209f798d" +} +] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index d3d9d4a..e48fa85 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -975,8 +975,21 @@ def cmd_import(options): inp = inp.strip() jobj, endpos = jd.raw_decode(inp) + if options.sign: + cbr = _makeuuid(jobj['created_by_ref']) + if cbr != persona.uuid: + # new owner + jobj['created_by_ref'] = persona.uuid + + # drop old parts + jobj.pop('uuid', None) + jobj.pop('modified', None) + obj = MDBase.create_obj(jobj) + if options.sign: + obj = persona.sign(obj) + objstr.loadobj(obj) inp = inp[endpos:] @@ -1042,6 +1055,8 @@ def main(): parser_dump.set_defaults(func=cmd_dump) parser_import = subparsers.add_parser('import', help='import objects encoded as json') + parser_import.add_argument('--sign', action='store_true', + help='import as new identity, and sign objects (if created_by_ref is different, new uuid is created)') parser_import.set_defaults(func=cmd_import) parser_drop = subparsers.add_parser('drop', help='drop the object specified by UUID') @@ -1590,8 +1605,11 @@ class _TestCases(unittest.TestCase): # with the correct output self.maxDiff = None + outnre = cmd.get('stdout_nre') outre = cmd.get('stdout_re') - if outre: + if outnre: + self.assertNotRegex(stdout.getvalue(), outnre) + elif outre: self.assertRegex(stdout.getvalue(), outre) else: self.assertEqual(stdout.getvalue(), cmd.get('stdout', ''))