libdoltlite-sys 0.38.21

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 13-May-2022
#
#-------------------------------------------------------------------------
#
# This file contains tests verifying that 403 errors are handled 
# correctly in SAS mode - that the xAuth callback is invoked to obtain
# a new SAS when required, and that the 403 error (and sometimes message) 
# is propagated back to the user correctly.
#
# Specifically, the above is tested within prefetch operations.
#


#
#  1.*: Test that if a 403 error occurs, a new SAS is requested from
#       the callback.
#
#  2.*: Test that if the 403 error persists, it is returned to the caller.
#

source [file join [file dirname [info script]] test_common.tcl]
set testprefix bcvfs_auth3

if {$C(use_sas)==0} {
  finish_test
  return
}

bcv_mkdir testdir
bcv_create_container cont1
bcv_upload_new_db cont1 t1.db {
  CREATE TABLE x1(x, y);
  WITH s(i) AS (
    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4000
  )
  INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s;
}

set ::nAuthCallback 0
proc my_auth_callback {zStorage zAccount zContainer} {
  incr ::nAuthCallback
  set sas [make_sas $zContainer 2]
  return $sas
}

set cmd [bcvfs_create testdir bcvfs]
$cmd auth_callback my_auth_callback
bcvfs_attach $cmd cont1

sqlite3 db /cont1/t1.db -vfs bcvfs
sqlite3_bcvfs_register_vtab db

do_test 1.0 {
  $cmd prefetch_new pf cont1 t1.db
  pf run 1 1000
} {0}

wait_ms 3000

do_test 1.1 {
  pf run 1 1000
} {0}

do_execsql_test 1.2 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 7 1 0 0 {} 1 1 1
}

do_test 1.3 {
  while {[pf run 2 1000]==0} {}
  pf destroy
} {}

do_execsql_test 1.4 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 7 7 0 0 {} 1 0 1
}

db close
$cmd destroy

#-------------------------------------------------------------------------

bcv_mkdir testdir
set cmd [bcvfs_create testdir bcvfs]
$cmd auth_callback my_auth_callback
bcvfs_attach $cmd cont1

sqlite3 db /cont1/t1.db -vfs bcvfs
sqlite3_bcvfs_register_vtab db

do_test 2.0 {
  $cmd prefetch_new pf cont1 t1.db
  pf run 1 1000
} {0}

wait_ms 3000
proc my_auth_callback {zStorage zAccount zContainer} {
  return "nonsense"
}

do_test 2.1 {
  pf run 1 1000
} {0}

do_execsql_test 2.2 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 7 1 0 0 {} 1 1 1
}

do_test 2.3 {
  while {[pf run 2 1000]==0} {}
  pf errcode
} {403}
pf destroy

do_execsql_test 2.4 {
  SELECT * FROM bcv_database
} {
  cont1 t1.db 7 1 0 0 {} 1 0 1
}

db close
$cmd destroy

finish_test