libdoltlite-sys 0.38.23

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 02-March-2022
#
#-------------------------------------------------------------------------
#
# This file tests the effects of providing the delete() utility
# with a bad SAS, or with a read-only SAS.
#

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

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


# Tests:
#
#   1. Test the effects of a bad SAS (one that will not even 
#      authorize reading the manifest file).
#
#   2. Test the effects of a readonly SAS.
#

bcv_create_container zzzz
bcv_upload_new_db zzzz x1.db {
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES(1, 2);
}
bcv_upload_new_db zzzz x2.db {
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES(3, 4);
}
bcv_upload_new_db zzzz x3.db {
  CREATE TABLE t1(a, b);
  INSERT INTO t1 VALUES(5, 6);
}

bcv_mkdir testdir
set cmd [bcvfs_create testdir bcvfs]
bcvfs_attach $cmd zzzz
sqlite3 db / -vfs bcvfs
sqlite3_bcvfs_register_vtab db
do_execsql_test 1.0 {
  SELECT container, database FROM bcv_database
} {
 zzzz x1.db
 zzzz x2.db
 zzzz x3.db
}

do_test 1.1 {
  set bcv [bcv_open zzzz -auth willnotwork]
  $bcv delete x2.db
} {403}
do_test 1.2 {
  $bcv errcode
} {403}
do_test 1.3 {
  string match {download manifest failed (403) - HTTP/1.1 403*} [$bcv errmsg]
} {1}
do_execsql_test 1.4 {
  SELECT container, database FROM bcv_database
} {
 zzzz x1.db
 zzzz x2.db
 zzzz x3.db
}
$bcv close

do_test 2.1 {
  set bcv [bcv_open zzzz -auth [make_readonly_sas zzzz]]
  $bcv delete x2.db
} {403}
do_test 2.2 {
  $bcv errcode
} {403}
do_test 2.3 {
  string match {upload manifest failed (403) - HTTP/1.1 403*} [$bcv errmsg]
} {1}
do_execsql_test 2.4 {
  SELECT container, database FROM bcv_database
} {
 zzzz x1.db
 zzzz x2.db
 zzzz x3.db
}
$bcv close



db close
$cmd destroy

finish_test