Skip to content

Commit 2aa9d56

Browse files
committed
Remove support for deprecated sqlite3 userauth extension
This commit removes support for the deprecated sqlite3 userauth extension. This change is roughly equivalent to: mattn#1344.
1 parent a153589 commit 2aa9d56

File tree

11 files changed

+268
-1060
lines changed

11 files changed

+268
-1060
lines changed

.github/workflows/go.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
os: [ubuntu-latest, macos-latest]
22-
go: ['1.22', '1.23']
22+
go: ['1.23', '1.24']
2323
fail-fast: false
2424
env:
2525
OS: ${{ matrix.os }}
@@ -46,8 +46,11 @@ jobs:
4646
- name: 'Tags: libsqlite3'
4747
run: go test -race -v -tags "libsqlite3"
4848

49+
- name: 'Tags: userauth deprecated'
50+
run: make test_userauth_fails test_userauth_fails_libsqlite3
51+
4952
- name: 'Tags: full'
50-
run: go test -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_os_trace sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_userauth sqlite_vacuum_incr sqlite_vtable"
53+
run: go test -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_os_trace sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_vacuum_incr sqlite_vtable"
5154

5255
- name: 'Tags: vacuum'
5356
run: go test -v -tags "sqlite_vacuum_full"

Makefile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Benchmark options
2+
NO_TESTS = ^$
3+
# BENCHMARKS = ^BenchmarkIndex('\$'|Hard|Torture|Periodic(Unicode)?)
4+
BENCH_SUITE = BenchmarkSuite
5+
BENCH_QUERY = BenchmarkSuite/.*BenchmarkQuery$
6+
BENCH_EXEC_STEP = BenchmarkSuite/.*BenchmarkExecStep$
7+
8+
# TODO: join these into a single list
9+
ALL_TEST_TAGS := sqlite_allow_uri_authority
10+
ALL_TEST_TAGS += sqlite_app_armor
11+
ALL_TEST_TAGS += sqlite_column_metadata
12+
ALL_TEST_TAGS += sqlite_foreign_keys
13+
ALL_TEST_TAGS += sqlite_fts5
14+
ALL_TEST_TAGS += sqlite_icu
15+
ALL_TEST_TAGS += sqlite_introspect
16+
ALL_TEST_TAGS += sqlite_json
17+
ALL_TEST_TAGS += sqlite_math_functions
18+
ALL_TEST_TAGS += sqlite_preupdate_hook
19+
ALL_TEST_TAGS += sqlite_secure_delete
20+
ALL_TEST_TAGS += sqlite_see
21+
ALL_TEST_TAGS += sqlite_stat4
22+
ALL_TEST_TAGS += sqlite_trace
23+
ALL_TEST_TAGS += sqlite_unlock_notify
24+
ALL_TEST_TAGS += sqlite_vacuum_incr
25+
ALL_TEST_TAGS += sqlite_vtable
26+
27+
space := $(subst ,, )
28+
comma := ,
29+
30+
ALL_TEST_TAGS_JOINED = $(subst $(space),$(comma),$(ALL_TEST_TAGS))
31+
32+
# GO_VERSION = $(shell go version | grep -oE 'go[1-9]\.[0-9]+(\.[0-9]+)?')
33+
# ifeq (,$(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.2[2-9]'))
34+
# export GOEXPERIMENT=cgocheck2
35+
# endif
36+
37+
.PHONY: all
38+
all: build
39+
40+
.PHONY: build
41+
build:
42+
@go build -tags "libsqlite3"
43+
44+
.PHONY: test
45+
test:
46+
@GOEXPERIMENT=cgocheck2 go test -tags "libsqlite3" -v
47+
48+
.PHONY: test_all
49+
test_all:
50+
@GOEXPERIMENT=cgocheck2 go test -tags "$(ALL_TEST_TAGS_JOINED)" -v
51+
52+
# TODO: merge with the above target
53+
.PHONY: test_all_libsqlite3
54+
test_all_libsqlite3:
55+
GOEXPERIMENT=cgocheck2 go test -tags "$(ALL_TEST_TAGS_JOINED),libsqlite3" -v
56+
57+
.PHONY: qtest
58+
qtest:
59+
@GOEXPERIMENT=cgocheck2 go test -tags "libsqlite3"
60+
61+
.PHONY: short
62+
short:
63+
@go test -tags "libsqlite3" -short
64+
65+
.PHONY: testrace
66+
testrace:
67+
@GOEXPERIMENT=cgocheck2 go test -tags "libsqlite3" -race
68+
69+
.PHONY: test_userauth_fails
70+
test_userauth_fails:
71+
@./scripts/test-userauth-fails.bash
72+
73+
.PHONY: test_userauth_fails_libsqlite3
74+
test_userauth_fails_libsqlite3:
75+
@./scripts/test-userauth-fails.bash -libsqlite3
76+
77+
.PHONY: testfull
78+
testfull:
79+
@./scripts/test-full.bash -v
80+
81+
.PHONY: testfull_race
82+
testfull_race:
83+
@./scripts/test-full.bash -v -race
84+
85+
.PHONY: bench
86+
bench:
87+
@go test -tags "libsqlite3 darwin" -run $(NO_TESTS) -bench $(BENCH_SUITE) -benchmem
88+
89+
.PHONY: bench_stmt_rows
90+
bench_stmt_rows:
91+
@go test -tags "libsqlite3 darwin" -run $(NO_TESTS) -bench $(BENCH_QUERY) -benchmem
92+
93+
.PHONY: bench_exec_step
94+
bench_exec_step:
95+
@go test -tags "libsqlite3 darwin" -run $(NO_TESTS) -bench $(BENCH_EXEC_STEP) -benchmem
96+
97+
.PHONY: bench_mem
98+
bench_mem:
99+
@go test -tags "libsqlite3 darwin" -run $(NO_TESTS) \
100+
-bench $(BENCH_SUITE) \
101+
-benchmem -memprofilerate 1 -memprofile mem.out -benchtime 5s
102+
103+
.PHONY: bench_cpu
104+
bench_cpu:
105+
@go test -tags "libsqlite3 darwin" -run $(NO_TESTS) \
106+
-bench $(BENCH_SUITE) \
107+
-cpuprofile cpu.out -benchtime 5s
108+
109+
.PHONY: tags
110+
tags:
111+
@\grep -ohP '(?<=//go:build )\w+(\s+\w+)?' *.go | sort -u

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,21 @@ For example the TDM-GCC Toolchain can be found [here](https://jmeubank.github.io
468468
469469
# User Authentication
470470
471-
This package supports the SQLite User Authentication module.
471+
### ***This is deprecated***
472+
473+
~~This package supports the SQLite User Authentication module.~~
474+
475+
User authentication deprecated as of [#28](https://github.com/charlievieth/go-sqlite3/pull/28)
476+
and building with the `sqlite_userauth` tag will cause [`Open()`](https://pkg.go.dev/github.com/charlievieth/go-sqlite3#SQLiteDriver.Open)
477+
to fail.
478+
479+
<details>
480+
<summary>Deprecated User Authentication</summary>
472481
473482
## Compile
474483
484+
### WARN: THIS IS DEPRECATED
485+
475486
To use the User authentication module, the package has to be compiled with the tag `sqlite_userauth`. See [Features](#features).
476487
477488
## Usage
@@ -577,6 +588,8 @@ The following functions are available for User authentication from the `*SQLiteC
577588
578589
When using attached databases, SQLite will use the authentication from the `main` database for the attached database(s).
579590
591+
</details>
592+
580593
# Extensions
581594
582595
If you want your own extension to be listed here, or you want to add a reference to an extension; please submit an Issue for this.

error_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func TestCorruptDbErrors(t *testing.T) {
4343
_, err = db.Exec("drop table foo")
4444
}
4545

46-
sqliteErr := err.(Error)
46+
sqliteErr, ok := err.(Error)
47+
if !ok {
48+
t.Fatalf("Not a sqlite3.Error: %#v", err)
49+
}
4750
if sqliteErr.Code != ErrNotADB {
4851
t.Error("wrong error code for corrupted DB")
4952
}
@@ -113,7 +116,10 @@ func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
113116
if err == nil {
114117
t.Error("No error!")
115118
} else {
116-
sqliteErr := err.(Error)
119+
sqliteErr, ok := err.(Error)
120+
if !ok {
121+
t.Fatalf("Not a sqlite3.Error: %#v", err)
122+
}
117123
if sqliteErr.Code != ErrConstraint {
118124
t.Errorf("Wrong basic error code: %d != %d",
119125
sqliteErr.Code, ErrConstraint)

scripts/test-userauth-fails.bash

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# Test that the userauth tests fail, but don't panic.
4+
# Pass "-libsqlite3" as an argument to the script to
5+
# run the tests with the "libsqlite3" build tag.
6+
7+
set -euo pipefail
8+
9+
OUT="$(mktemp -t 'go-sqlite3.XXXXXX')"
10+
trap 'rm "${OUT}"' EXIT
11+
12+
function test_sqlite_userauth() {
13+
local tags='sqlite_userauth'
14+
while (( $# > 0 )); do
15+
if [[ -n $1 ]]; then
16+
tags+=",$1"
17+
fi
18+
shift
19+
done
20+
21+
echo "Running: \`go test -tags=${tags}\`"
22+
if go test -tags="${tags}" &> "${OUT}"; then
23+
cat "${OUT}"
24+
echo >&2 ''
25+
echo >&2 'FAIL: tests passed: expected them to fail'
26+
return 2
27+
fi
28+
29+
if \grep -qF 'panic:' "${OUT}"; then
30+
cat "${OUT}"
31+
echo >&2 ''
32+
echo >&2 'FAIL: test panicked'
33+
return 2
34+
fi
35+
36+
echo "PASS"
37+
}
38+
39+
function main() {
40+
local tags=''
41+
if [[ ${1:-} == '-libsqlite3' ]]; then
42+
tags='libsqlite3'
43+
fi
44+
test_sqlite_userauth "${tags}"
45+
}
46+
47+
main "$@"

sqlite3.go

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,64 +1906,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
19061906
}
19071907

19081908
// Preform Authentication
1909-
if err := conn.Authenticate(authUser, authPass); err != nil {
1910-
return err
1911-
}
1912-
1913-
// Register: authenticate
1914-
// Authenticate will perform an authentication of the provided username
1915-
// and password against the database.
1916-
//
1917-
// If a database contains the SQLITE_USER table, then the
1918-
// call to Authenticate must be invoked with an
1919-
// appropriate username and password prior to enable read and write
1920-
//access to the database.
1921-
//
1922-
// Return SQLITE_OK on success or SQLITE_ERROR if the username/password
1923-
// combination is incorrect or unknown.
1924-
//
1925-
// If the SQLITE_USER table is not present in the database file, then
1926-
// this interface is a harmless no-op returnning SQLITE_OK.
1927-
if err := conn.registerAuthFunc("authenticate", conn.authenticate, true); err != nil {
1928-
return err
1929-
}
1930-
//
1931-
// Register: auth_user_add
1932-
// auth_user_add can be used (by an admin user only)
1933-
// to create a new user. When called on a no-authentication-required
1934-
// database, this routine converts the database into an authentication-
1935-
// required database, automatically makes the added user an
1936-
// administrator, and logs in the current connection as that user.
1937-
// The AuthUserAdd only works for the "main" database, not
1938-
// for any ATTACH-ed databases. Any call to AuthUserAdd by a
1939-
// non-admin user results in an error.
1940-
if err := conn.registerAuthFunc("auth_user_add", conn.authUserAdd, true); err != nil {
1941-
return err
1942-
}
1943-
//
1944-
// Register: auth_user_change
1945-
// auth_user_change can be used to change a users
1946-
// login credentials or admin privilege. Any user can change their own
1947-
// login credentials. Only an admin user can change another users login
1948-
// credentials or admin privilege setting. No user may change their own
1949-
// admin privilege setting.
1950-
if err := conn.registerAuthFunc("auth_user_change", conn.authUserChange, true); err != nil {
1951-
return err
1952-
}
19531909
//
1954-
// Register: auth_user_delete
1955-
// auth_user_delete can be used (by an admin user only)
1956-
// to delete a user. The currently logged-in user cannot be deleted,
1957-
// which guarantees that there is always an admin user and hence that
1958-
// the database cannot be converted into a no-authentication-required
1959-
// database.
1960-
if err := conn.registerAuthFunc("auth_user_delete", conn.authUserDelete, true); err != nil {
1961-
return err
1962-
}
1963-
1964-
// Register: auth_enabled
1965-
// auth_enabled can be used to check if user authentication is enabled
1966-
if err := conn.registerAuthFunc("auth_enabled", conn.authEnabled, true); err != nil {
1910+
// NB: This will always fail if built with the "sqlite_userauth"
1911+
// build tag since user authentication is now deprecated.
1912+
if err := conn.Authenticate(authUser, authPass); err != nil {
19671913
return err
19681914
}
19691915

@@ -1980,6 +1926,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
19801926
}
19811927

19821928
// Check if user wants to activate User Authentication
1929+
//
1930+
// NB: This will always fail if built with the "sqlite_userauth"
1931+
// build tag since user authentication is now deprecated.
19831932
if authCreate {
19841933
// Before going any further, we need to check that the user
19851934
// has provided an username and password within the DSN.
@@ -1992,8 +1941,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
19921941
}
19931942

19941943
// Check if User Authentication is Enabled
1995-
authExists := conn.AuthEnabled()
1996-
if !authExists {
1944+
if !conn.AuthEnabled() {
19971945
if err := conn.AuthUserAdd(authUser, authPass, true); err != nil {
19981946
return err
19991947
}

0 commit comments

Comments
 (0)