tests,json: Add the bulk of tests

* t-json.c (tests): Register new tests.
* t-createkey.in.json,
  t-createkey.out.json,
  t-decrypt-verify.in.json,
  t-decrypt-verify.out.json,
  t-decrypt.in.json,
  t-decrypt.out.json,
  t-delete.in.json,
  t-delete.out.json,
  t-encrypt-sign.in.json,
  t-encrypt-sign.out.json,
  t-encrypt.in.json,
  t-encrypt.out.json,
  t-export-secret-info.in.json,
  t-export-secret-info.out.json,
  t-export.in.json,
  t-export.out.json,
  t-json.c,
  t-keylist-secret.in.json,
  t-keylist-secret.out.json,
  t-keylist.in.json,
  t-keylist.out.json,
  t-verify.in.json,
  t-verify.out.json,
  t-version.in.json,
  t-version.out.json: New.

--
Except for help and getmore there is now a test for each command.
This commit is contained in:
Andre Heinecke 2018-11-14 15:15:21 +01:00
parent 9a31fdcb11
commit dd4b80a5f6
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
25 changed files with 443 additions and 1 deletions

View File

@ -0,0 +1,5 @@
{
"op": "createkey",
"userid": "foo@bar.baz",
"algo": "rsa1024"
}

View File

@ -0,0 +1,3 @@
{
"fingerprint": "*"
}

View File

@ -0,0 +1,5 @@
{
"op": "decrypt",
"base64": true,
"data": "hQEOA2rm1+5GqHH4EAP+NCYW3vVuCLDTUYhBaKHNgp4fMq9TNACH2NiZyVSaYLe0VE+2LLurHN/XLwlP7xhl2XijBUe6Q7M+KyoPd9iNIgX9q914dPUN0Q3sJinSbujnFzsy0L2x6kgUJCK/XA7rp0VpmJGUWIQYAET8Xx6SaWd2XxIdIITUz2MqrTzWrgED/iOuRxuT4loNJ/DM2YrOZr0He25SxJskg0t1bik2nM+wHAbJrSa6BqPJYU4scnG6AH0RRxFV177ADjOcBLeutXw7DE+6YOExWZD2Fb0oax/ppDulMudrJnj6Wg5/EHbBLDF96Xd6vQX1rcHmrxImvaQNbavEKswlDZgoYwaV7PYPhQEOAwQHH7gHKHE0EAP/So0a3deCbXVSPkABRO3yZa6kHcVuO5+lTsunfxav1TwaMkBOiK6usRz2zt3rjozNrh3vXn3o2WpFKebwhIUF0q2qPw3OKIGq9jFT63t+DPjpbSorAevmVqXWdmaqDPJZ/QIY6NkBhprTdIGPSTFh66eggQLz+BBUVx2myM7AqgcD/3PnOGIiqINQzFkfa6lHiV/TZ8AaMNfvyx4FFG4Zi45ZnDwLCJZ+J7ATXzECauEDLzhjk8M9OP0PwFT1WsnWefKDSLzbO5hEnf8NYdY6i8f2MJKYcnpeI4PZA3OK9ovmAoJl31K+/vBJRP4kiJ4Weu7fzMi6Zz87tfHDEpbRR7N80qoBTlT7I044LG5OJKgQukb7HOv+c668i56UzZVgz+LCsFpjYEFTlrPVR5Me3PjSSb8M+tt9NUjenNnghJEcxeD902YJcqgRWPotouzx5fKDTay/LofFqckEWGlP5pnkeNfYIBIaSSrG/KcdQ0rPOAxKrZzIifYVwnJm/ISxU6uMpNfDJGOJppf4xqXgTKBdIsCljg5LlgNvGhNMYaXQkGQInzXvLSUbxLerWw=="
}

View File

@ -0,0 +1,56 @@
{
"dec_info": {
"symkey_algo": "TWOFISH.CFB",
"wrong_key_usage": false,
"is_de_vs": false,
"is_mime": false,
"legacy_cipher_nomdc": false,
"recipients": [{
"keyid": "6AE6D7EE46A871F8",
"pubkey_algo_name": "ELG-E",
"status_string": "Success",
"status_code": 0
}, {
"keyid": "04071FB807287134",
"pubkey_algo_name": "ELG-E",
"status_string": "No secret key",
"status_code": 117440529
}]
},
"info": {
"is_mime": false,
"signatures": [{
"summary": {
"sigsum": [],
"valid": false,
"green": false,
"red": false,
"revoked": false,
"key-expired": false,
"sig-expired": false,
"key-missing": false,
"crl-missing": false,
"crl-too-old": false,
"bad-policy": false,
"sys-error": false
},
"wrong_key_usage": false,
"chain_model": false,
"is_de_vs": false,
"status_string": "Success",
"fingerprint": "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"validity_string": "unknown",
"pubkey_algo_name": "DSA",
"hash_algo_name": "RIPEMD160",
"status_code": 0,
"timestamp": 1542200353,
"exp_timestamp": 0,
"pka_trust": 0,
"validity": 0,
"validity_reason": 0
}]
},
"type": "plaintext",
"base64": false,
"data": "Hello world"
}

View File

@ -0,0 +1,5 @@
{
"op": "decrypt",
"data": "hQEOA2rm1+5GqHH4EAQAhzzu7VYpE9vFVdqkAALRHSyz8698b8MES7j5ldzXGVnGSWmN0+YXGyWyeB5tnAXAvUiV10tzoiNaPXoNeOFrHQOWrDsQ1vYukdtblDc3FW/Ywf7aelcFIGh9qydmkPX/EPeULsbgdZp6sybGoPpEuxzb4CYeRjogB9VvPCRAPb4D/1hRdpoVgWI78JvaeI+xwrP71RuHggZEsM8FSYFBD8c5dY+iAHbPSBI6QSZMvMHCu8YVlV40rHFjjoKQ1ox9DHHyvaZkwAZbI/U7+CYZoPoXMAARjCCCW4TIB3VrM70QLjnLSVfWaCtTnYp2KWaRae0Ze7yPt/h1dYe4ofn/O3UH0kEBqJ99Srtrmr9UWdgikgrWCz5TAV27g2vsZubfMe8vC1QnqASazyBy74ibvrXrIvHnhHQvPCkZFRdbgYhV/+KQIQ==",
"base64": true
}

View File

@ -0,0 +1,16 @@
{
"dec_info": {
"wrong_key_usage": false,
"is_de_vs": false,
"is_mime": false,
"legacy_cipher_nomdc": false,
"recipients": [{
"pubkey_algo_name": "ELG-E",
"status_string": "Success",
"status_code": 0
}]
},
"type": "plaintext",
"base64": false,
"data": "Hello\n"
}

View File

@ -0,0 +1,4 @@
{
"op": "delete",
"key": "E8143C489C8D41124DC40D0B47AF4B6961F04784"
}

View File

@ -0,0 +1,3 @@
{
"success": true
}

View File

@ -0,0 +1,8 @@
{
"op": "encrypt",
"keys": ["alpha@example.net", "victor@example.org"],
"signing_keys": ["A0FF4590BB6122EDEF6E3C542D727CC768697734"],
"data": "Hello world",
"armor": true,
"always-trust": true
}

View File

@ -0,0 +1,4 @@
{
"type": "ciphertext",
"base64": false
}

View File

@ -0,0 +1,8 @@
{
"op": "encrypt",
"keys": ["bravo@example.net", "alpha@example.net"],
"data": "Hello world",
"file_name": "test.txt",
"armor": false,
"always-trust": true
}

View File

@ -0,0 +1,4 @@
{
"type": "ciphertext",
"base64": true
}

View File

@ -0,0 +1,6 @@
{
"op": "export",
"keys": "alpha@example.net",
"armor": true,
"with-sec-fprs":true
}

View File

@ -0,0 +1,6 @@
{
"type": "keys",
"base64": false,
"data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQGiBDbjjp4RBAC2ZbFDX0wmJI8yLDYQdIiZeAuHLmfyHsqXaLGUMZtWiAvn/hNp\nctwahmzKm5oXinHUvUkLOQ0s8rOlu15nhw4azc30rTP1LsIkn5zORNnFdgYC6RKy\nhOeim/63+/yGtdnTm49lVfaCqwsEmBCEkXaeWDGq+ie1b89J89T6n/JquwCgoQkj\nVeVGG+B/SzJ6+yifdHWQVkcD/RXDyLXX4+WHGP2aet51XlKojWGwsZmc9LPPYhwU\n/RcUO7ce1QQb0XFlUVFBhY0JQpM/ty/kNi+aGWFzigbQ+HAWZkUvA8+VIAVneN+p\n+SHhGIyLTXKpAYTq46AwvllZ5Cpvf02Cp/+W1aVyA0qnBWMyeIxXmR9HOi6lxxn5\ncjajA/9VZufOXWqCXkBvz4Oy3Q5FbjQQ0/+ty8rDn8OTaiPi41FyUnEi6LO+qyBS\n09FjnZj++PkcRcXW99SNxmEJRY7MuNHt5wIvEH2jNEOJ9lszzZFBDbuwsjXHK35+\nlPbGEy69xCP26iEafysKKbRXJhE1C+tk8SnK+Gm62sivmK/5arQpQWxwaGEgVGVz\ndCAoZGVtbyBrZXkpIDxhbHBoYUBleGFtcGxlLm5ldD6IVQQTEQIAFQUCNuOOngML\nCgMDFQMCAxYCAQIXgAAKCRAtcnzHaGl3NDl4AKCBLmRplv/8ZfSqep5IjqEAuaXv\nWwCgl6NEzT+/WewPTGcwZY+pLkycLv2IVQQTEQIAFQUCNuOOngMLCgMDFQMCAxYC\nAQIXgAAKCRAtcnzHaGl3NDl4AJ4rouHB+LpCkNi5C59jHEa1kbANzACgmddtrNSj\n1yPyTCwUwRghPUomECS0EEFsaWNlIChkZW1vIGtleSmIVQQTEQIAFQUCNuO2qwML\nCgMDFQMCAxYCAQIXgAAKCRAtcnzHaGl3NCeMAJ9MeUVrago5Jc6PdwdeN5OMwby3\n7QCghW65cZTQlD1bBlIq/QM8bz9AN4G0J0FsZmEgVGVzdCAoZGVtbyBrZXkpIDxh\nbGZhQGV4YW1wbGUubmV0PohVBBMRAgAVBQI247hYAwsKAwMVAwIDFgIBAheAAAoJ\nEC1yfMdoaXc0t8IAoJPwa6j+Vm5Vi3Nvuo8JZri4PJ/DAJ9dqbmaJdB8FdJnHfGh\n1rXK3y/JcrkBDQQ2448PEAQAnI3XH1f0uyN9fZnw72zsHMw706g7EW29nD4UDQG4\nOzRZViSrUa5n39eI7QrfTO+1meVvs0y8F/PvFst5jH68rPLnGSrXz4sTl1T4cop1\nFBkquvCAKwPLy0lE7jjtCyItOSwIOo8xoTfY4JEEXmcqsbm+KHv9yYSF/YK4Cf7b\nIzcAAwcD/Rnl5jKxoucDA96pD2829TKsLFQSau+Xiy8bvOSSDdlyABsOkNBSaeKO\n3eAQEKgDM7dzjVNTnAlpQ0EQ8Y9Z8pxOWYEQYlaMrnRBC4DZ2IadzEhLlIOz5BVp\n/jfhrr8oVVBwKZXsrz9PZLz+e4Yn+siUUvlei9boD9L2ZgSOHakPiEYEGBECAAYF\nAjbjjw8ACgkQLXJ8x2hpdzQgqQCfcDXmD8uNVdKg/C9vqI3JSndqknsAnRxzVeHi\n/iJ73OCKtvFrHbV9Gogq\n=6f6v\n-----END PGP PUBLIC KEY BLOCK-----\n",
"sec-fprs": ["A0FF4590BB6122EDEF6E3C542D727CC768697734"]
}

View File

@ -0,0 +1,5 @@
{
"op": "export",
"keys": "victor@example.org",
"armor": true
}

View File

@ -0,0 +1,5 @@
{
"type": "keys",
"base64": false,
"data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQGiBDbjs5oRBACjAxqGzA6j190iiN/1vJvS5jYLQ1H3xxhzXdZ6ZxjPJkslX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a4NmILiEUEGBECAAYFAjbjs74ACgkQR69LaWHwR4RT3QCgnMlRAiGtvL5l\nD4Gdo5F0KEP5zZEAlA6Ri9WmZ9Xiqw5R3Bsg+As8sJ4=\n=FRd4\n-----END PGP PUBLIC KEY BLOCK-----\n"
}

View File

@ -36,7 +36,15 @@
#include "../../src/cJSON.h"
/* Register tests here */
static const char*tests[] = { "t-keylist", "t-config", "t-keylist", NULL };
static const char*tests[] = { "t-config", "t-version",
"t-keylist", "t-keylist-secret", "t-decrypt", "t-config-opt",
"t-encrypt", "t-encrypt-sign", "t-sign", "t-verify",
"t-decrypt-verify", "t-export", "t-createkey",
"t-export-secret-info",
/* For these two the order is important
* as t-import imports the deleted key from t-delete */
"t-delete", "t-import",
NULL };
static int verbose = 0;

View File

@ -0,0 +1,5 @@
{
"op": "keylist",
"keys": [ "bravo@example.net", "alpha@example.net" ],
"with-secret": true
}

View File

@ -0,0 +1,163 @@
{
"keys": [{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"secret": true,
"is_qualified": false,
"protocol": "OpenPGP",
"fingerprint": "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"subkeys": [{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": false,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "DSA",
"pubkey_algo_string": "dsa1024",
"keyid": "2D727CC768697734",
"keygrip": "76F7E2B35832976B50A27A282D9B87E44577EB66",
"pubkey_algo": 17,
"length": 1024,
"timestamp": 920882846,
"expires": 0
}, {
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": false,
"can_certify": false,
"can_authenticate": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "ELG-E",
"pubkey_algo_string": "elg1024",
"keyid": "6AE6D7EE46A871F8",
"keygrip": "A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD",
"pubkey_algo": 16,
"length": 1024,
"timestamp": 920882959,
"expires": 0
}],
"userids": [{
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Alfa Test (demo key) <alfa@example.net>",
"name": "Alfa Test",
"email": "alfa@example.net",
"comment": "demo key",
"address": "alfa@example.net"
}, {
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Alpha Test (demo key) <alpha@example.net>",
"name": "Alpha Test",
"email": "alpha@example.net",
"comment": "demo key",
"address": "alpha@example.net"
}, {
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Alice (demo key)",
"name": "Alice",
"email": "",
"comment": "demo key",
"origin": 0,
"last_update": 0
}]
}, {
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"secret": true,
"is_qualified": false,
"protocol": "OpenPGP",
"fingerprint": "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
"owner_trust": "unknown",
"origin": 0,
"last_update": 0,
"subkeys": [{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": false,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "DSA",
"pubkey_algo_string": "dsa1024",
"keyid": "FE180B1DA9E3B0B2",
"keygrip": "6D62909991D2331E5F4F605BC4DD738F30E6D26B",
"pubkey_algo": 17,
"length": 1024,
"timestamp": 920888034,
"expires": 0
}, {
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": false,
"can_certify": false,
"can_authenticate": false,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "ELG-E",
"pubkey_algo_string": "elg1024",
"keyid": "5381EA4EE29BA37F",
"keygrip": "6BBF325FADDC1109AE36CD535CA77AB9CFADD1F2",
"pubkey_algo": 16,
"length": 1024,
"timestamp": 920888071,
"expires": 0
}],
"userids": [{
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Bob (demo key)",
"name": "Bob",
"email": "",
"comment": "demo key"
}, {
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Bravo Test (demo key) <bravo@example.net>",
"name": "Bravo Test",
"email": "bravo@example.net",
"comment": "demo key",
"address": "bravo@example.net"
}]
}]
}

View File

@ -0,0 +1,5 @@
{
"op": "keylist",
"keys": [ "zulu@example.net" ],
"with-secret": false
}

View File

@ -0,0 +1,65 @@
{
"keys": [{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"secret": false,
"is_qualified": false,
"protocol": "OpenPGP",
"fingerprint": "23FD347A419429BACCD5E72D6BC4778054ACD246",
"subkeys": [{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": false,
"can_sign": true,
"can_certify": true,
"can_authenticate": true,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "DSA",
"pubkey_algo_string": "dsa1024",
"pubkey_algo": 17,
"length": 1024,
"timestamp": 920892875,
"expires": 0
}, {
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": false,
"can_certify": false,
"can_authenticate": false,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "ELG-E",
"pubkey_algo_string": "elg1024",
"pubkey_algo": 16,
"length": 1024,
"timestamp": 920892914,
"expires": 0
}],
"userids": [{
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "Zulu Test (demo key) <zulu@example.net>",
"name": "Zulu Test",
"email": "zulu@example.net",
"comment": "demo key",
"address": "zulu@example.net"
}]
}]
}

View File

@ -0,0 +1,5 @@
{
"op": "verify",
"data": "Hello world",
"signature": "-----BEGIN PGP SIGNATURE-----\n\niHAEABECADAWIQSg/0WQu2Ei7e9uPFQtcnzHaGl3NAUCW+we3RIcYWxwaGFAZXhh\nbXBsZS5uZXQACgkQLXJ8x2hpdzSwIgCfdfk+n6SsYwa9SYfBwr/o4FmWsa8Anj3V\n8p3ahr3rxNbK7cDbSk/p1zD0\n=oS5d\n-----END PGP SIGNATURE-----"
}

View File

@ -0,0 +1,35 @@
{
"info": {
"is_mime": false,
"signatures": [{
"summary": {
"sigsum": [],
"valid": false,
"green": false,
"red": false,
"revoked": false,
"key-expired": false,
"sig-expired": false,
"key-missing": false,
"crl-missing": false,
"crl-too-old": false,
"bad-policy": false,
"sys-error": false
},
"wrong_key_usage": false,
"chain_model": false,
"is_de_vs": false,
"status_string": "Success",
"fingerprint": "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"validity_string": "unknown",
"pubkey_algo_name": "DSA",
"hash_algo_name": "SHA1",
"status_code": 0,
"timestamp": 1542201053,
"exp_timestamp": 0,
"pka_trust": 0,
"validity": 0,
"validity_reason": 0
}]
}
}

View File

@ -0,0 +1,3 @@
{
"op": "version"
}

View File

@ -0,0 +1,10 @@
{
"info": [{
"protocol": "OpenPGP"
}, {
"protocol": "spawn",
"fname": "/nonexistent",
"version": "1.0.0",
"req_version": "1.0.0"
}]
}