/ Check-in [dbbcbf00]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test cases and minor fixes for the zonefile module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | zonefile
Files: files | file ages | folders
SHA3-256:dbbcbf0066ef82c789981feff78d95861a836e6e23a22ad3bb698dd257062f75
User & Date: dan 2018-02-23 19:21:19
Context
2018-02-23
21:01
Fix a problem with handling "k >= ?" constraints in the zonefile module. check-in: 9a99afaf user: dan tags: zonefile
19:21
Add test cases and minor fixes for the zonefile module. check-in: dbbcbf00 user: dan tags: zonefile
14:09
Fix a problem causing SQLITE_HAVE_LZ4 builds of zonefile to fail unless SQLITE_HAVE_ZLIB is also defined. check-in: 994aa77d user: dan tags: zonefile
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/zonefile/zonefile.c.

   342    342     const char **pzKey              /* OUT: Pointer to key buffer */
   343    343   ){
   344    344     if( pGlobal->nHash ){
   345    345       ZonefileKey *pKey;
   346    346       u32 iHash = zonefileKeyHash(zDb, zTab, iFileid);
   347    347       for(pKey=pGlobal->aHash[iHash%pGlobal->nHash]; pKey; pKey=pKey->pHashNext){
   348    348         if( pKey->iFileid==iFileid 
   349         -       && 0==sqlite3_stricmp(zDb, pKey->zDb)
   350    349          && 0==sqlite3_stricmp(zTab, pKey->zName)
          350  +       && 0==sqlite3_stricmp(zDb, pKey->zDb)
   351    351         ){
   352    352           *pzKey = pKey->zKey;
   353    353           return pKey->nKey;
   354    354         }
   355    355       }
   356    356     }
   357    357   
................................................................................
   811    811   ** Return zero if the two SQL values passed as arguments are equal, or
   812    812   ** non-zero otherwise. Values with different types are considered unequal,
   813    813   ** even if they both contain the same numeric value (e.g. 2 and 2.0).
   814    814   */
   815    815   static int zonefileCompareValue(sqlite3_value *p1, sqlite3_value *p2){
   816    816     int eType;
   817    817     assert( p1 );
   818         -  if( p2==0 ) return 1;
   819    818     eType = sqlite3_value_type(p1);
   820    819     if( sqlite3_value_type(p2)!=eType ) return 1;
   821    820     switch( eType ){
   822    821       case SQLITE_INTEGER:
   823    822         return sqlite3_value_int64(p1)!=sqlite3_value_int64(p2);
   824    823       case SQLITE_FLOAT:
   825    824         return sqlite3_value_double(p1)!=sqlite3_value_double(p2);
................................................................................
   861    860     for(i=0; i<sizeof(a)/sizeof(a[0]); i++){
   862    861       if( 0==sqlite3_stricmp(zName, a[i].zName) ){
   863    862         *peType = a[i].eType;
   864    863         return SQLITE_OK;
   865    864       }
   866    865     }
   867    866   
   868         -  *pzErr = sqlite3_mprintf("unknown encryption type: %s", zName);
          867  +  *pzErr = sqlite3_mprintf("unknown encryption method: %s", zName);
   869    868     return SQLITE_ERROR;
   870    869   }
   871    870   
   872    871   static int zonefileGetParams(
   873    872     sqlite3_context *pCtx,          /* Leave any error message here */
   874    873     const char *zJson,              /* JSON configuration parameter (or NULL) */
   875    874     ZonefileParam *p                /* Populate this object before returning */
................................................................................
  1033   1032     ZonefileCompress *pMethod,      /* Compression method object */
  1034   1033     void *pCmp,                     /* Compression handle */
  1035   1034     ZonefileCodec *pCodec,          /* Compression method, if any */
  1036   1035     ZonefileBuffer *pTo,            /* Append new data here */
  1037   1036     ZonefileBuffer *pFrom           /* Input buffer */
  1038   1037   ){
  1039   1038     int rc = SQLITE_OK;
  1040         -  if( pFrom->n ){
  1041         -    int nNonce = pCodec ? zonefileCodecNonceSize(pCodec) : 0;
  1042         -    int nOrig = pTo->n;
  1043         -    if( pMethod->eType==ZONEFILE_COMPRESSION_NONE ){
  1044         -      if( zonefileBufferGrow(pCtx, pTo, pFrom->n + nNonce) ){
  1045         -        rc = SQLITE_ERROR;
  1046         -      }else{
  1047         -        zonefileAppendBlob(pTo, pFrom->a, pFrom->n);
  1048         -      }
         1039  +  int nNonce = pCodec ? zonefileCodecNonceSize(pCodec) : 0;
         1040  +  int nOrig = pTo->n;
         1041  +  if( pMethod->eType==ZONEFILE_COMPRESSION_NONE ){
         1042  +    if( zonefileBufferGrow(pCtx, pTo, pFrom->n + nNonce) ){
         1043  +      rc = SQLITE_ERROR;
  1049   1044       }else{
  1050         -      int nReq = pMethod->xCompressBound(pCmp, pFrom->n);
  1051         -      if( zonefileBufferGrow(pCtx, pTo, nReq + nNonce) ) return SQLITE_ERROR;
  1052         -      rc = pMethod->xCompress(pCmp, &pTo->a[pTo->n], &nReq, pFrom->a, pFrom->n);
  1053         -      pTo->n += nReq;
  1054         -      if( rc!=SQLITE_OK ){
  1055         -        return rc;
  1056         -      }
         1045  +      zonefileAppendBlob(pTo, pFrom->a, pFrom->n);
  1057   1046       }
         1047  +  }else{
         1048  +    int nReq = pMethod->xCompressBound(pCmp, pFrom->n);
         1049  +    if( zonefileBufferGrow(pCtx, pTo, nReq + nNonce) ) return SQLITE_ERROR;
         1050  +    rc = pMethod->xCompress(pCmp, &pTo->a[pTo->n], &nReq, pFrom->a, pFrom->n);
         1051  +    pTo->n += nReq;
         1052  +  }
  1058   1053   
  1059         -    /* Encrypt the data just appended to buffer pTo. */
  1060         -    if( pCodec ){
  1061         -      zonefileCodecEncode(pCodec, &pTo->a[nOrig], pTo->n - nOrig);
  1062         -      pTo->n += nNonce;
  1063         -    }
         1054  +  /* Encrypt the data just appended to buffer pTo. */
         1055  +  if( rc==SQLITE_OK && pCodec ){
         1056  +    zonefileCodecEncode(pCodec, &pTo->a[nOrig], pTo->n - nOrig);
         1057  +    pTo->n += nNonce;
  1064   1058     }
  1065         -  return SQLITE_OK;
         1059  +  return rc;
  1066   1060   }
  1067   1061   
  1068   1062   /*
  1069   1063   ** Append nByte bytes of garbage data to the file opened with pFd. Return
  1070   1064   ** SQLITE_OK if successful, or SQLITE_ERROR if an error occurs.
  1071   1065   **
  1072   1066   ** Parameter nByte is only ever non-zero when running tests. So it doesn't
................................................................................
  1613   1607     }
  1614   1608     switch( i ){
  1615   1609       case 0: /* filename */
  1616   1610         sqlite3_result_value(ctx, sqlite3_column_value(pCsr->pSelect, 0));
  1617   1611         break;
  1618   1612       case 1: /* ekey */
  1619   1613         break;
  1620         -    case 2: { /* header */
         1614  +    default: {
  1621   1615         const char *zFile = (const char*)sqlite3_column_text(pCsr->pSelect, 0);
  1622   1616         zonefileJsonHeader(ctx, zFile);
         1617  +      assert( i==2 );
  1623   1618         break;
  1624   1619       }
  1625   1620     }
  1626   1621     return SQLITE_OK;
  1627   1622   }
  1628   1623   
  1629   1624   /* 
................................................................................
  1680   1675     u8 *aOut = sqlite3_malloc(nOut);
  1681   1676   
  1682   1677     assert( pMethod->eType!=ZONEFILE_COMPRESSION_NONE );
  1683   1678     if( aOut==0 ){
  1684   1679       rc = SQLITE_NOMEM;
  1685   1680     }else{
  1686   1681       rc = pMethod->xUncompress(pCmp, aOut, nOut, aIn, nIn);
  1687         -    if( rc ){
  1688         -      sqlite3_free(aOut);
  1689         -      aOut = 0;
  1690         -    }
         1682  +  }
         1683  +  if( rc ){
         1684  +    sqlite3_free(aOut);
         1685  +    aOut = 0;
  1691   1686     }
  1692   1687   
  1693   1688     *paOut = aOut;
  1694   1689     *pnOut = nOut;
  1695   1690     return rc;
  1696   1691   }
  1697   1692   

Changes to ext/zonefile/zonefile1.test.

   105    105     do_catchsql_test 2.1 {
   106    106       WITH p(n,v) AS (
   107    107           VALUES('compressionTypeIndexData', 'zstd_global_dict')
   108    108       )
   109    109       SELECT zonefile_write('test.zonefile', 'bb', json_group_object(n,v)) FROM p;
   110    110     } {1 {compressor "zstd_global_dict" may not be used to compress the zonefile index}}
   111    111   }
   112         -# puts $COMPRESSION_METHODS
   113    112   
   114    113   set extra_header 0
   115    114   set cachesize 0
   116    115   foreach cmp $COMPRESSION_METHODS { foreach cmpidx $COMPRESSION_METHODS {
   117    116     if {$cmpidx == "zstd_global_dict"} continue
   118    117     reset_db
   119    118     load_static_extension db zonefile
................................................................................
   239    238   } {0 0 0}
   240    239   
   241    240   do_execsql_test 3.3 {
   242    241     UPDATE cc_files SET ekey = '0123456789';
   243    242     SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k)
   244    243   } {1 1 1}
   245    244   
          245  +close [open test.zonefile w+]
          246  +do_catchsql_test 3.4 {
          247  +  SELECT header FROM cc_files
          248  +} {1 {failed to read header from file: "test.zonefile"}}
          249  +
          250  +forcedelete test.zonefile
          251  +do_catchsql_test 3.5 {
          252  +  SELECT header FROM cc_files
          253  +} {1 {failed to open file "test.zonefile" for reading}}
          254  +
          255  +do_execsql_test 3.6 {
          256  +  SELECT ekey FROM cc_files
          257  +} {{}}
          258  +
          259  +#-------------------------------------------------------------------------
          260  +# Check that a file that uses an unknown compression method is handled
          261  +# correctly (an error is returned).
          262  +#
          263  +reset_db
          264  +load_static_extension db zonefile
          265  +do_execsql_test 4.0 {
          266  +  CREATE TABLE dd(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB);
          267  +  INSERT INTO dd VALUES(1000, 1, -1, randomblob(44));
          268  +  INSERT INTO dd VALUES(1001, 1, -1, randomblob(55));
          269  +  INSERT INTO dd VALUES(1002, 2, -1, randomblob(66));
          270  +  SELECT zonefile_write('test.zonefile', 'dd');
          271  +  CREATE VIRTUAL TABLE x1 USING zonefile;
          272  +} {{}}
          273  +
          274  +do_test 4.1 {
          275  +  hexio_write test.zonefile 5 77
          276  +} {1}
          277  +do_execsql_test 4.2 {
          278  +  INSERT INTO x1_files(filename) VALUES('test.zonefile');
          279  +} {}
          280  +do_catchsql_test 4.3 {
          281  +  SELECT * FROM x1
          282  +} {1 {unsupported compression method: 119}}
          283  +do_test 4.4 {
          284  +  hexio_write test.zonefile 4 77
          285  +} {1}
          286  +do_catchsql_test 4.5 {
          287  +  DELETE FROM x1_files;
          288  +  INSERT INTO x1_files(filename) VALUES('test.zonefile');
          289  +} {1 {unsupported compression method: 119}}
          290  +
          291  +do_test 4.6 {
          292  +  hexio_write test.zonefile 0 00
          293  +} {1}
          294  +do_catchsql_test 4.7 {
          295  +  INSERT INTO x1_files(filename) VALUES('test.zonefile');
          296  +} {1 {failed to read zonefile header from file "test.zonefile"}}
          297  +
          298  +#-------------------------------------------------------------------------
          299  +# Test using various types in the "frame" field of an input table.
          300  +#
          301  +reset_db
          302  +load_static_extension db zonefile
          303  +if {[lsearch $COMPRESSION_METHODS zlib]>=0} {
          304  +  do_execsql_test 5.0 {
          305  +    CREATE TABLE "a b"(k INTEGER PRIMARY KEY,frame INTEGER,idx INTEGER,v BLOB);
          306  +    INSERT INTO "a b" VALUES(1, 0.5, -1, randomblob(44));
          307  +    INSERT INTO "a b" VALUES(2, 0.5, -1, randomblob(55));
          308  +    INSERT INTO "a b" VALUES(3, 1.5, -1, randomblob(55));
          309  +    INSERT INTO "a b" VALUES(4, 1.5, -1, randomblob(55));
          310  +    INSERT INTO "a b" VALUES(5,   2, -1, randomblob(55));
          311  +    INSERT INTO "a b" VALUES(6,   2, -1, randomblob(55));
          312  +    INSERT INTO "a b" VALUES(7, 200, -1, randomblob(55));
          313  +    INSERT INTO "a b" VALUES(8, 200, -1, randomblob(55));
          314  +    INSERT INTO "a b" VALUES(9, 300, -1, randomblob(55));
          315  +    INSERT INTO "a b" VALUES(10, 300, -1, randomblob(55));
          316  +    INSERT INTO "a b" VALUES(11, NULL, -1, randomblob(55));
          317  +    INSERT INTO "a b" VALUES(12, NULL, -1, randomblob(55));
          318  +    INSERT INTO "a b" VALUES(13, 'f1', -1, randomblob(55));
          319  +    INSERT INTO "a b" VALUES(14, 'f1', -1, randomblob(55));
          320  +    INSERT INTO "a b" VALUES(15, 'frame2', -1, randomblob(55));
          321  +    INSERT INTO "a b" VALUES(16, 'frame2', -1, randomblob(55));
          322  +    INSERT INTO "a b" VALUES(17, x'1234', -1, randomblob(55));
          323  +    INSERT INTO "a b" VALUES(18, x'1234', -1, randomblob(55));
          324  +    INSERT INTO "a b" VALUES(19, x'abcd', -1, randomblob(55));
          325  +    INSERT INTO "a b" VALUES(20, x'abcd', -1, randomblob(55));
          326  +  
          327  +    SELECT zonefile_write('test.zonefile', 'a b',
          328  +      '{"compressionTypeContent":"zlib"}'
          329  +    );
          330  +  } {{}}
          331  +
          332  +  do_execsql_test 5.1 {
          333  +    CREATE VIRTUAL TABLE abc USING zonefile; 
          334  +    INSERT INTO abc_files(filename) VALUES('test.zonefile');
          335  +    SELECT group_concat(k) FROM abc_shadow_idx GROUP BY fofst
          336  +  } {
          337  +    11,12   1,2   3,4   5,6   7,8  
          338  +     9,10  13,14 15,16 17,18 19,20
          339  +  }
          340  +}
          341  +
          342  +do_execsql_test 6.0 {
          343  +  CREATE TABLE "ab"(k INTEGER PRIMARY KEY,frame INTEGER,idx INTEGER,v BLOB);
          344  +  INSERT INTO "ab" VALUES(1, 0.5, -1, randomblob(44));
          345  +  INSERT INTO "ab" VALUES(2, 0.5, -1, randomblob(55));
          346  +  INSERT INTO "ab" VALUES(3, 1.5, -1, randomblob(55));
          347  +  INSERT INTO "ab" VALUES(4, 1.5, -1, randomblob(55));
          348  +}
          349  +do_catchsql_test 6.1.1 {
          350  +  SELECT zonefile_write('test.zonefile', 'ab',
          351  +      '{"debugExtendedHeaderSize":-1}'
          352  +  );
          353  +} {1 {debugExtendedHeaderSize value out of range: -1}}
          354  +do_catchsql_test 6.1.2 {
          355  +  SELECT zonefile_write('test.zonefile', 'ab',
          356  +      '{"debugExtendedHeaderSize":256}'
          357  +  );
          358  +} {1 {debugExtendedHeaderSize value out of range: 256}}
          359  +
          360  +do_catchsql_test 6.2 {
          361  +  SELECT zonefile_write('test.zonefile', 'ab',
          362  +      '{"unknown":256}'
          363  +  );
          364  +} {1 {unknown parameter name: "unknown"}}
          365  +
          366  +forcedelete test.dir
          367  +file mkdir test.dir
          368  +do_catchsql_test 6.3 {
          369  +  SELECT zonefile_write('test.dir', 'ab');
          370  +} {1 {failed to open file "test.dir" for writing}}
          371  +
          372  +do_catchsql_test 6.4 {
          373  +  CREATE VIRTUAL TABLE zzz USING zonefile;
          374  +  INSERT INTO zzz_files(filename) VALUES('nosuchfile.zonefile');
          375  +} {1 {failed to open file "nosuchfile.zonefile" for reading}}
          376  +
          377  +do_catchsql_test 6.4 {
          378  +  INSERT INTO zzz_files(filename) VALUES('test.dir');
          379  +} {1 {failed to read zonefile header from file "test.dir"}}
          380  +
          381  +#-------------------------------------------------------------------------
          382  +# Check that errors generated when building a dictionary are handled.
          383  +# The zstd library routines for building a dictionary throw an error
          384  +# if they are provided with too little data.
          385  +#
          386  +# Also test that zstd_global_dict cannot be used to compress the zonefile
          387  +# index (as there is nowhere in the file format to store the dictionary
          388  +# for this compression).
          389  +#
          390  +reset_db
          391  +load_static_extension db zonefile
          392  +if {[lsearch $COMPRESSION_METHODS zstd_global_dict]>=0} {
          393  +  do_execsql_test 7.0 {
          394  +    CREATE TABLE "ab"(k INTEGER PRIMARY KEY,frame INTEGER,idx INTEGER,v BLOB);
          395  +    INSERT INTO "ab" VALUES(1, -1, -1, 'abc');
          396  +  }
          397  +
          398  +  do_catchsql_test 7.1 {
          399  +    SELECT zonefile_write('test.zonefile', 'ab',
          400  +      '{"compressionTypeContent":"zstd_global_dict"}'
          401  +    );
          402  +  } {1 {error generating dictionary}}
          403  +
          404  +  do_catchsql_test 7.2 {
          405  +    SELECT zonefile_write('test.zonefile', 'ab',
          406  +      '{"compressionTypeIndexData":"zstd_global_dict"}'
          407  +    );
          408  +  } {1 {compressor "zstd_global_dict" may not be used to compress the zonefile index}}
          409  +}
          410  +
          411  +#-------------------------------------------------------------------------
          412  +#
          413  +reset_db
          414  +load_static_extension db zonefile
          415  +do_catchsql_test 8.1 {
          416  +  CREATE VIRTUAL TABLE one USING zonefile_files;
          417  +} {1 {do not create zonefile_files tables directly!}}
          418  +do_catchsql_test 8.2 {
          419  +  CREATE VIRTUAL TABLE onetwothree USING zonefile_files;
          420  +} {1 {do not create zonefile_files tables directly!}}
   246    421   
   247    422   
   248    423   finish_test
   249    424   

Changes to ext/zonefile/zonefileenc.test.

    48     48         SELECT zonefile_write('test' || $i || '.zonefile', 'zz', 
    49     49           json_group_object(n, v)
    50     50         ) FROM p;
    51     51       }
    52     52     }
    53     53   } {}
    54     54   
    55         -do_test 1.2 {
    56         -  execsql {
    57         -    CREATE VIRTUAL TABLE gg USING zonefile;
    58         -  }
    59         -  for {set i 0} {$i < $nFile} {incr i} {
    60         -    execsql { 
    61         -      INSERT INTO gg_files(filename) VALUES('test' || $i || '.zonefile')
    62         -    }
    63         -  }
    64         -} {}
           55  +proc k {i} { lindex $::K [expr $i % [llength $::K]] }
           56  +db func k k
           57  +
           58  +do_execsql_test 1.2 {
           59  +  CREATE VIRTUAL TABLE gg USING zonefile;
           60  +}
           61  +for {set i 0} {$i < $nFile} {incr i} {
           62  +  do_execsql_test 1.2.$i { 
           63  +    INSERT INTO gg_files(filename, ekey) 
           64  +    VALUES('test' || $i || '.zonefile', k($i));
           65  +    SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v!=gg.v;
           66  +  } 0
           67  +}
           68  +
           69  +db close
           70  +sqlite3 db test.db
           71  +load_static_extension db zonefile
           72  +db func k k
    65     73   
    66     74   do_catchsql_test 1.3 {
    67     75     SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v!=gg.v;
    68     76   } {1 {missing encryption key for file "test0.zonefile"}}
    69     77   do_execsql_test 1.4 {
    70     78     UPDATE gg_files SET ekey = 'braking' WHERE filename='test0.zonefile';
    71     79   }
    72     80   do_catchsql_test 1.5 {
    73     81     SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v!=gg.v;
    74     82   } {1 {missing encryption key for file "test1.zonefile"}}
    75     83   
    76         -proc k {i} {
    77         -  lindex $::K [expr $i % [llength $::K]]
    78         -}
    79         -db func k k
    80     84   do_execsql_test 1.6 {
    81     85     UPDATE gg_files SET ekey = k(rowid-1);
    82     86   }
    83     87   do_execsql_test 1.7 {
    84     88     SELECT count(*) FROM rr JOIN gg USING(k) WHERE rr.v!=gg.v;
    85     89   } {0}
    86     90   do_execsql_test 1.8 {
................................................................................
   114    118   }
   115    119   foreach {tn alg id} {
   116    120     1 aes_128_ctr 1
   117    121     2 aes_128_cbc 2
   118    122     3 AES_256_CTR 3
   119    123     4 Aes_256_CBC 4
   120    124   } {
   121         -  do_catchsql_test 2.$tn {
          125  +  do_catchsql_test 2.1.$tn {
   122    126       WITH p(n,v) AS (
   123    127           VALUES('encryptionType', $alg) UNION ALL
   124    128           VALUES('encryptionKey', 'secret')
   125    129       )
   126    130       SELECT zonefile_write('test' || $i || '.zonefile', 'zz', 
   127    131             json_group_object(n, v)
   128    132       ) FROM p;
   129    133     } "1 {unsupported encryption method: $id}"
   130    134   }
          135  +
          136  +foreach {tn alg} {
          137  +  1 nosuchmethod! 
          138  +} {
          139  +  do_catchsql_test 2.1.$tn {
          140  +    WITH p(n,v) AS (
          141  +        VALUES('encryptionType', $alg) UNION ALL
          142  +        VALUES('encryptionKey', 'secret')
          143  +    )
          144  +    SELECT zonefile_write('test' || $i || '.zonefile', 'zz', 
          145  +          json_group_object(n, v)
          146  +    ) FROM p;
          147  +  } "1 {unknown encryption method: $alg}"
          148  +}
          149  +
          150  +#-------------------------------------------------------------------------
          151  +# Test some hash collisions in the encryption key table.
          152  +#
          153  +
          154  +# This is the same hash function used internally to store keys.
          155  +#
          156  +proc hash {zDb zTab iFile} {
          157  +  binary scan $zDb c*  A
          158  +  binary scan $zTab c* B
          159  +  set h 0
          160  +  foreach i $A { set h [expr ($h + ($h << 3) + $i) & 0xFFFFFFFF] }
          161  +  foreach i $B { set h [expr ($h + ($h << 3) + $i) & 0xFFFFFFFF] }
          162  +  return [expr $h ^ $iFile]
          163  +}
          164  +
          165  +do_test 3.0 {
          166  +  set h1 [expr [hash main zone 1] % 512]
          167  +  for {set i 0} {1} {incr i} {
          168  +    set h2 [expr [hash "aux$i" zone 1] % 512]
          169  +    if {$h1==$h2} break
          170  +  }
          171  +  set i
          172  +} 52
          173  +
          174  +reset_db
          175  +load_static_extension db zonefile
          176  +forcedelete test.db2
          177  +
          178  +do_execsql_test 3.1 {
          179  +  CREATE TABLE zz(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB);
          180  +  INSERT INTO zz VALUES(222, -1, -1, randomblob(60));
          181  +  WITH p(n,v) AS (
          182  +      VALUES('encryptionType', 'xor') UNION ALL
          183  +      VALUES('encryptionKey', 'pass')
          184  +  )
          185  +  SELECT zonefile_write('test1.zonefile', 'zz', 
          186  +      json_group_object(n, v)
          187  +  ) FROM p;
          188  +
          189  +  DELETE FROM zz;
          190  +  INSERT INTO zz VALUES(333, -1, -1, randomblob(80));
          191  +  WITH p(n,v) AS (
          192  +      VALUES('encryptionType', 'xor') UNION ALL
          193  +      VALUES('encryptionKey', 'pass')
          194  +  )
          195  +  SELECT zonefile_write('test2.zonefile', 'zz', 
          196  +      json_group_object(n, v)
          197  +  ) FROM p;
          198  +} {{} {}}
          199  +
          200  +do_execsql_test 3.2 {
          201  +  ATTACH 'test.db2' AS aux52;
          202  +  CREATE VIRTUAL TABLE main.zone USING zonefile;
          203  +  CREATE VIRTUAL TABLE aux52.zone USING zonefile;
          204  +  INSERT INTO main.zone_files(filename, ekey) VALUES('test1.zonefile', 'pass');
          205  +  INSERT INTO aux52.zone_files(filename, ekey) VALUES('test2.zonefile', 'pass');
          206  +}
          207  +
          208  +do_execsql_test 3.3 {
          209  +  SELECT v IS NULL FROM main.zone;
          210  +  SELECT v IS NULL FROM aux52.zone;
          211  +} {0 0}
          212  +
          213  +do_test 3.4 {
          214  +  set h1 [expr [hash main zone 1] % 512]
          215  +  for {set i 0} {1} {incr i} {
          216  +    set h2 [expr [hash "aux$i" zone 2] % 512]
          217  +    if {$h1==$h2} break
          218  +  }
          219  +  set i
          220  +} 682
          221  +
          222  +forcedelete test.db3
          223  +do_execsql_test 3.5 {
          224  +  ATTACH 'test.db3' AS aux682;
          225  +  CREATE VIRTUAL TABLE aux682.zone USING zonefile;
          226  +  INSERT INTO aux682.zone_files(filename, ekey) VALUES('test1.zonefile','pass');
          227  +  INSERT INTO aux682.zone_files(filename, ekey) VALUES('test2.zonefile','pass');
          228  +  INSERT INTO main.zone_files(filename, ekey) VALUES('test2.zonefile','pass');
          229  +}
          230  +
          231  +do_execsql_test 3.6 {
          232  +  SELECT v IS NULL FROM main.zone;
          233  +  SELECT v IS NULL FROM aux682.zone;
          234  +  SELECT v IS NULL FROM main.zone;
          235  +} {0 0 0 0 0 0}
          236  +
   131    237   
   132    238   finish_test
   133    239   

Changes to ext/zonefile/zonefilefault.test.

    58     58         );
    59     59       }
    60     60     } -test {
    61     61       faultsim_test_result {0 {{}}}
    62     62     }
    63     63   }
    64     64   
           65  +do_execsql_test 1.3.0 { UPDATE tt SET frame = NULL; }
           66  +do_faultsim_test 1.3 -faults oom* -prep {
           67  +  sqlite3 db test.db
           68  +  load_static_extension db zonefile
           69  +} -body {
           70  +  execsql {
           71  +    SELECT zonefile_write('test.zonefile', 'tt');
           72  +  }
           73  +} -test {
           74  +  faultsim_test_result {0 {{}}}
           75  +}
           76  +
           77  +do_execsql_test 1.4.0 {
           78  +  INSERT INTO tt VALUES(5, -1, -1, randomblob(100));
           79  +  INSERT INTO tt VALUES(6, -1, -1, randomblob(100));
           80  +  INSERT INTO tt VALUES(7, -1, -1, randomblob(100));
           81  +  INSERT INTO tt VALUES(8, -1, -1, randomblob(100));
           82  +  INSERT INTO tt VALUES(9, -1, -1, randomblob(100));
           83  +  CREATE VIRTUAL TABLE ttz USING zonefile;
           84  +}
           85  +if {[catch { db eval $sql }]==0} {
           86  +  faultsim_save_and_close
           87  +  do_faultsim_test 1.4 -faults oom* -prep {
           88  +    faultsim_restore_and_reopen
           89  +    load_static_extension db zonefile
           90  +  } -body {
           91  +    execsql {
           92  +      SELECT zonefile_write('test.zonefile', 'tt',
           93  +          '{"compressionTypeIndexData":"zstd"}'
           94  +      );
           95  +    }
           96  +  } -test {
           97  +    faultsim_test_result {0 {{}}}
           98  +  }
           99  +
          100  +  faultsim_save_and_close
          101  +  do_faultsim_test 1.5 -faults oom* -prep {
          102  +    faultsim_restore_and_reopen
          103  +    load_static_extension db zonefile
          104  +  } -body {
          105  +    execsql {
          106  +      INSERT INTO ttz_files(filename) VALUES('test.zonefile');
          107  +    }
          108  +  } -test {
          109  +    faultsim_test_result {0 {}}
          110  +  }
          111  +}
          112  +
          113  +#-------------------------------------------------------------------------
          114  +#
    65    115   do_execsql_test 2.0 {
    66    116     SELECT zonefile_write('test.zonefile', 'tt',
    67    117         '{"encryptionType":"xor", "encryptionKey":"secret"}'
    68    118     );
    69    119     CREATE VIRTUAL TABLE zz USING zonefile;
    70    120   } {{}}
    71    121   
    72    122   faultsim_save_and_close
    73         -do_faultsim_test 2 -faults oom* -prep {
          123  +do_faultsim_test 2.1 -faults oom* -prep {
    74    124     faultsim_restore_and_reopen
    75    125     load_static_extension db zonefile
    76    126   } -body {
    77    127     execsql {
    78    128       INSERT INTO zz_files(filename, ekey) VALUES('test.zonefile', 'secret')
    79    129     }
    80    130   } -test {
    81    131     faultsim_test_result {0 {}}
    82    132   }
          133  +
          134  +faultsim_save_and_close
          135  +do_faultsim_test 2.2 -faults oom* -prep {
          136  +  faultsim_restore_and_reopen
          137  +  load_static_extension db zonefile
          138  +} -body {
          139  +  execsql { SELECT json_extract(header, '$.magicNumber') FROM zz_files }
          140  +} -test {
          141  +  faultsim_test_result {0 1179332920}
          142  +}
    83    143   
    84    144   finish_test
    85    145