/ Check-in [1764ade2]
Login

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

Overview
Comment:Test edge cases in the zonefile module. Fix a broken error message in the same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | zonefile
Files: files | file ages | folders
SHA3-256: 1764ade22b52eba0226ae2e6e837a1b0967023eabd7d50e9f87c5e7042ea2f12
User & Date: dan 2018-02-24 08:26:21
Context
2018-02-26
07:58
Add extra parameter to zonefileCodecCreate() to indicate whether the new object will be used for mock-encryption or mock-decryption. check-in: 231832c4 user: dan tags: zonefile
2018-02-24
08:26
Test edge cases in the zonefile module. Fix a broken error message in the same. check-in: 1764ade2 user: dan tags: zonefile
2018-02-23
21:01
Fix a problem with handling "k >= ?" constraints in the zonefile module. check-in: 9a99afaf user: dan tags: zonefile
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/zonefile/zonefile.c.

  2309   2309     i64 iFileid;
  2310   2310   
  2311   2311     if( pTab->pIdToName==0 ){
  2312   2312       rc = zonefilePrepare(pTab->db, &pTab->pIdToName, &pTab->base.zErrMsg, 
  2313   2313           "SELECT filename FROM %Q.'%q_shadow_file' WHERE fileid=?",
  2314   2314           pTab->zDb, pTab->zName
  2315   2315       );
  2316         -    if( rc!=SQLITE_OK ){
  2317         -      zonefileTransferError(pCtx);
  2318         -      return SQLITE_ERROR;
  2319         -    }
         2316  +    if( rc==SQLITE_ERROR ) zonefileTransferError(pCtx);
  2320   2317     }
  2321   2318   
  2322         -  iFileid = sqlite3_column_int64(pCsr->pSelect,1);
  2323         -  sqlite3_bind_int64(pTab->pIdToName, 1, iFileid);
  2324         -  if( SQLITE_ROW==sqlite3_step(pTab->pIdToName) ){
  2325         -    *pzFile = (const char*)sqlite3_column_text(pTab->pIdToName, 0);
  2326         -  }else{
  2327         -    rc = sqlite3_reset(pTab->pIdToName);
  2328         -    if( rc==SQLITE_OK ){
  2329         -      rc = SQLITE_CORRUPT_VTAB;
         2319  +  if( rc==SQLITE_OK ){
         2320  +    iFileid = sqlite3_column_int64(pCsr->pSelect,1);
         2321  +    sqlite3_bind_int64(pTab->pIdToName, 1, iFileid);
         2322  +    if( SQLITE_ROW==sqlite3_step(pTab->pIdToName) ){
         2323  +      *pzFile = (const char*)sqlite3_column_text(pTab->pIdToName, 0);
  2330   2324       }else{
  2331         -      zonefileTransferError(pCtx);
         2325  +      rc = sqlite3_reset(pTab->pIdToName);
         2326  +      if( rc==SQLITE_OK ){
         2327  +        rc = SQLITE_CORRUPT_VTAB;
         2328  +      }else{
         2329  +        zonefileTransferError(pCtx);
         2330  +      }
  2332   2331       }
  2333   2332     }
  2334   2333   
  2335   2334     return rc;
  2336   2335   }
  2337   2336   
  2338   2337   static void zonefileReleaseFile(ZonefileCsr *pCsr){

Changes to ext/zonefile/zonefile1.test.

   227    227   
   228    228   do_execsql_test 3.1 {
   229    229     CREATE VIRTUAL TABLE cc USING zonefile;
   230    230     INSERT INTO cc_files(filename,ekey) VALUES('test.zonefile','0123456789');
   231    231     SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k)
   232    232   } {1 1 1}
   233    233   
   234         -do_execsql_test 3.2 {
          234  +do_execsql_test 3.2.1 {
   235    235     DELETE FROM cc_files;
   236    236     INSERT INTO cc_files(filename,ekey) VALUES('test.zonefile','abcdefghij');
   237    237     SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k)
   238    238   } {0 0 0}
   239    239   
          240  +do_execsql_test 3.2.2 {
          241  +  SELECT rowid,sz FROM cc;
          242  +} {1000 44 1001 55 1002 66}
          243  +
   240    244   do_execsql_test 3.3 {
   241    245     UPDATE cc_files SET ekey = '0123456789';
   242    246     SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k)
   243    247   } {1 1 1}
   244    248   
   245    249   close [open test.zonefile w+]
   246    250   do_catchsql_test 3.4 {
................................................................................
   252    256     SELECT header FROM cc_files
   253    257   } {1 {failed to open file "test.zonefile" for reading}}
   254    258   
   255    259   do_execsql_test 3.6 {
   256    260     SELECT ekey FROM cc_files
   257    261   } {{}}
   258    262   
          263  +forcedelete test.zonefile
          264  +do_catchsql_test 3.7 {
          265  +  SELECT * FROM cc;
          266  +} {1 {failed to open file "test.zonefile" for reading}}
          267  +
   259    268   #-------------------------------------------------------------------------
   260    269   # Check that a file that uses an unknown compression method is handled
   261    270   # correctly (an error is returned).
   262    271   #
   263    272   reset_db
   264    273   load_static_extension db zonefile
   265    274   do_execsql_test 4.0 {
................................................................................
   555    564     2   "k >= 100"
   556    565     3   "k <= 100"
   557    566     4   "k < 55"
   558    567     5   "k LIKE '1%'"
   559    568     6   "k BETWEEN 10 AND 20"
   560    569     7   "k > 100 AND k < 200"
   561    570   } {
   562         -  do_execsql_test 11.$tn.1 [subst {
          571  +  do_execsql_test 11.1.$tn.1 [subst {
   563    572       SELECT count(*) FROM nm WHERE $cond
   564    573     }] [db one "SELECT count(*) FROM data WHERE $cond"]
   565    574   
   566         -  do_execsql_test 11.$tn.2 [subst {
          575  +  do_execsql_test 11.1.$tn.2 [subst {
   567    576       SELECT count(*) FROM nm WHERE $cond AND
   568    577         v!=(SELECT v FROM data WHERE k=nm.k);
   569    578     }] 0
   570    579   }
          580  +
          581  +close [open test1.zonefile w+]
          582  +do_catchsql_test 11.2.1 {
          583  +  SELECT * FROM nm WHERE k=24;
          584  +} {1 {SQL logic error}}
          585  +forcedelete test1.zonefile
          586  +do_catchsql_test 11.2.2 {
          587  +  SELECT * FROM nm WHERE k=24;
          588  +} {1 {failed to open file "test1.zonefile" for reading}}
          589  +
          590  +do_catchsql_test 11.3.1 {
          591  +  DELETE FROM nm_shadow_file;
          592  +  SELECT * FROM nm WHERE k=24;
          593  +} {1 {database disk image is malformed}}
          594  +do_catchsql_test 11.3.2 {
          595  +  DROP TABLE nm_shadow_file;
          596  +  SELECT * FROM nm WHERE k=24;
          597  +} {1 {no such table: main.nm_shadow_file}}
          598  +db close
          599  +sqlite3 db test.db
          600  +load_static_extension db zonefile
          601  +do_catchsql_test 11.3.3 {
          602  +  SELECT * FROM nm WHERE k=24;
          603  +} {1 {no such table: main.nm_shadow_file}}
          604  +
          605  +#-------------------------------------------------------------------------
          606  +#
          607  +reset_db
          608  +load_static_extension db zonefile
          609  +do_execsql_test 11.0 {
          610  +  CREATE TABLE data(k INTEGER PRIMARY KEY, frame, idx, v BLOB);
          611  +  INSERT INTO data VALUES(1, 1, -1, randomblob(200));
          612  +  INSERT INTO data VALUES(2, 2, -1, randomblob(200));
          613  +  INSERT INTO data VALUES(3, 3, -1, randomblob(200));
          614  +  SELECT zonefile_write('test.zonefile', 'data',
          615  +      '{"encryptionType":"xor","encryptionKey":"pass"}'
          616  +  );
          617  +
          618  +  CREATE VIRTUAL TABLE nm USING zonefile(cachesize=2);
          619  +  INSERT INTO nm_files(filename,ekey) VALUES('test.zonefile','pass');
          620  +} {{}}
          621  +
          622  +set i 0
          623  +foreach id {1 2 3 2 3 1} {
          624  +  do_execsql_test 11.1.$i {
          625  +    SELECT data.v=nm.v FROM data,nm WHERE data.k=$id AND nm.k=$id
          626  +  } 1
          627  +  incr i
          628  +}
   571    629   
   572    630   finish_test
   573    631   

Changes to ext/zonefile/zonefilefault.test.

    42     42   }
    43     43   
    44     44   set sql {
    45     45       SELECT zonefile_write('test.zonefile', 'tt',
    46     46           '{"compressionTypeContent":"zstd_global_dict"}'
    47     47       );
    48     48   }
    49         -
           49  +set HAVE_ZSTD 0
    50     50   if {[catch { db eval $sql }]==0} {
           51  +  set HAVE_ZSTD 1
           52  +}
           53  +
           54  +if {$HAVE_ZSTD} {
    51     55     do_faultsim_test 1.2 -faults oom* -prep {
    52     56       sqlite3 db test.db
    53     57       load_static_extension db zonefile
    54     58     } -body {
    55     59       execsql {
    56     60         SELECT zonefile_write('test.zonefile', 'tt',
    57     61             '{"compressionTypeContent":"zstd_global_dict"}'
................................................................................
    78     82     INSERT INTO tt VALUES(5, -1, -1, randomblob(100));
    79     83     INSERT INTO tt VALUES(6, -1, -1, randomblob(100));
    80     84     INSERT INTO tt VALUES(7, -1, -1, randomblob(100));
    81     85     INSERT INTO tt VALUES(8, -1, -1, randomblob(100));
    82     86     INSERT INTO tt VALUES(9, -1, -1, randomblob(100));
    83     87     CREATE VIRTUAL TABLE ttz USING zonefile;
    84     88   }
    85         -if {[catch { db eval $sql }]==0} {
           89  +if {$HAVE_ZSTD} {
    86     90     faultsim_save_and_close
    87     91     do_faultsim_test 1.4 -faults oom* -prep {
    88     92       faultsim_restore_and_reopen
    89     93       load_static_extension db zonefile
    90     94     } -body {
    91     95       execsql {
    92     96         SELECT zonefile_write('test.zonefile', 'tt',
................................................................................
   147    151   } -body {
   148    152     execsql { DELETE FROM zz_files }
   149    153   } -test {
   150    154     faultsim_test_result {0 {}}
   151    155   }
   152    156   
   153    157   #-------------------------------------------------------------------------
          158  +#
   154    159   reset_db
   155    160   faultsim_save_and_close
   156         -do_faultsim_test 3 -faults oom* -prep {
          161  +do_faultsim_test 3.1 -faults oom* -prep {
   157    162     faultsim_restore_and_reopen
   158    163     load_static_extension db zonefile
   159    164   } -body {
   160    165     execsql { CREATE VIRTUAL TABLE t1 USING zonefile(cachesize=5) }
   161    166   } -test {
   162    167     faultsim_test_result {0 {}}
   163    168   }
          169  +
          170  +faultsim_save_and_close
          171  +do_faultsim_test 3.2 -faults oom* -prep {
          172  +  faultsim_restore_and_reopen
          173  +  load_static_extension db zonefile
          174  +} -body {
          175  +  execsql { DROP TABLE t1 }
          176  +} -test {
          177  +  faultsim_test_result {0 {}}
          178  +}
          179  +
          180  +#-------------------------------------------------------------------------
          181  +#
          182  +reset_db
          183  +load_static_extension db zonefile
          184  +do_execsql_test 4.0 {
          185  +  CREATE TABLE zz(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB);
          186  +  INSERT INTO zz VALUES(1, -1, -1, randomblob(100));
          187  +  INSERT INTO zz VALUES(2, -1, -1, randomblob(100));
          188  +  INSERT INTO zz VALUES(3, -1, -1, randomblob(100));
          189  +  SELECT zonefile_write('test.zonefile', 'zz');
          190  +  CREATE VIRTUAL TABLE zone USING zonefile;
          191  +  INSERT INTO zone_files(filename) VALUES('test.zonefile');
          192  +} {{}}
          193  +
          194  +faultsim_save_and_close
          195  +do_faultsim_test 4.1 -faults oom* -prep {
          196  +  faultsim_restore_and_reopen
          197  +  load_static_extension db zonefile
          198  +} -body {
          199  +  execsql { SELECT v IS NULL FROM zone WHERE k = 2 }
          200  +} -test {
          201  +  faultsim_test_result {0 0}
          202  +}
          203  +
          204  +
          205  +if {$HAVE_ZSTD} {
          206  +  set params {
          207  +      {"encryptionType":"xor","encryptionKey":"pass",
          208  +       "compressionTypeContent":"zstd_global_dict"
          209  +      }
          210  +  }
          211  +} else {
          212  +  set params { {"encryptionType":"xor","encryptionKey":"pass" } }
          213  +}
          214  +do_execsql_test 4.2 {
          215  +  SELECT zonefile_write('test.zonefile', 'zz', $params);
          216  +  CREATE VIRTUAL TABLE zone2 USING zonefile;
          217  +  INSERT INTO zone2_files(filename,ekey) VALUES('test.zonefile','pass');
          218  +} {{}}
          219  +
          220  +faultsim_save_and_close
          221  +do_faultsim_test 4.3 -faults oom* -prep {
          222  +  faultsim_restore_and_reopen
          223  +  load_static_extension db zonefile
          224  +  execsql { UPDATE zone2_files SET ekey='pass' }
          225  +} -body {
          226  +  execsql { SELECT v IS NULL FROM zone2 WHERE k = 2 }
          227  +} -test {
          228  +  faultsim_test_result {0 0}
          229  +}
          230  +
          231  +#-------------------------------------------------------------------------
          232  +reset_db
          233  +do_faultsim_test 4.3 -faults oom* -prep {
          234  +  faultsim_restore_and_reopen
          235  +} -body {
          236  +  load_static_extension db zonefile
          237  +} -test {
          238  +  faultsim_test_result {0 {}} {1 {initialization of zonefile failed: }}
          239  +}
   164    240   
   165    241   finish_test
   166    242