From: Klas Lindfors Date: Fri, 19 Apr 2013 14:05:45 +0000 (+0200) Subject: simple import test X-Git-Tag: v1.13.0~10 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b011e173180b3a96581034f2a4e432801a6c42d7;p=yubikey-personalization simple import test --- diff --git a/tests/test_json.c b/tests/test_json.c index d20486d..17259b1 100644 --- a/tests/test_json.c +++ b/tests/test_json.c @@ -30,21 +30,56 @@ #include #include +#include +#include "ykpers_lcl.h" #include +#include + +YK_STATUS *init_status(int major, int minor, int build) { + YK_STATUS *st = ykds_alloc(); + struct status_st *t; + + t = (struct status_st *) st; + + /* connected key details */ + t->versionMajor = major; + t->versionMinor = minor; + t->versionBuild = build; + + return st; +} void _test_ykp_export_ycfg_empty(void) { YKP_CONFIG *cfg = ykp_alloc(); char out[1024] = {0}; int res = ykp_export_config(cfg, out, 1024, YKP_FORMAT_YCFG); - assert(res == 0); + assert(res > 0); + ykp_free_config(cfg); +} + +void _test_ykp_import_ycfg_simple(void) { + YK_STATUS *st = init_status(2,2,3); + YKP_CONFIG *cfg = ykp_alloc(); + YK_CONFIG ycfg; + ykp_configure_version(cfg, st); + char data[1024] = "{ \"yubiProdConfig\": { \"mode\": \"oathHOTP\", \"options\": { \"fixedModhex\": false, \"oathDigits\": 6, \"fixedSeedvalue\": 0, \"randomSeed\": false, \"tabFirst\": false, \"tabBetween\": false, \"tabLast\": false, \"appendDelay1\": false, \"appendDelay2\": false, \"appendCR\": true, \"protectSecond\": false, \"sendRef\": false, \"ticketFirst\": false, \"pacing10MS\": false, \"pacing20MS\": false, \"allowHidtrig\": false, \"serialBtnVisible\": true, \"serialUsbVisible\": false, \"serialApiVisible\": true, \"useNumericKeypad\": false, \"fastTrig\": false, \"allowUpdate\": false, \"dormant\": false, \"ledInverted\": false } } }"; + int res = ykp_import_config(cfg, data, strlen(data), YKP_FORMAT_YCFG); + assert(res == 1); + + ycfg = cfg->ykcore_config; + assert((ycfg.tktFlags & TKTFLAG_OATH_HOTP) == TKTFLAG_OATH_HOTP); + assert((ycfg.tktFlags & TKTFLAG_APPEND_CR) == TKTFLAG_APPEND_CR); + ykp_free_config(cfg); + ykds_free(st); } int main(void) { _test_ykp_export_ycfg_empty(); + _test_ykp_import_ycfg_simple(); return 0; }