diff options
Diffstat (limited to 'tests/golite.go')
-rw-r--r-- | tests/golite.go | 637 |
1 files changed, 0 insertions, 637 deletions
diff --git a/tests/golite.go b/tests/golite.go index 2216883..03a3bd8 100644 --- a/tests/golite.go +++ b/tests/golite.go @@ -1,10 +1,3 @@ -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build cgo // +build cgo - package golite import ( @@ -305,12 +298,6 @@ func TestBackupError(t *testing.T) { t.Fatal("Failed to get the expected nil backup result.") } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build cgo // +build cgo func TestCallbackArgCast(t *testing.T) { intConv := callbackSyntheticForTests(reflect.ValueOf(int64(math.MaxInt64)), nil) @@ -412,12 +399,6 @@ func TestCallbackReturnAny(t *testing.T) { t.Errorf("Expected valid callback for any return type, got: %s", err) } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build cgo // +build cgo func TestSimpleError(t *testing.T) { e := ErrError.Error() @@ -673,61 +654,6 @@ func TestError_SystemErrno(t *testing.T) { t.Errorf("expected SystemErrno to be a not exists error, but got %v", serr.SystemErrno) } } -// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// TestCryptEncoders to increase coverage -func TestCryptEncoders(t *testing.T) { - tests := []struct { - enc string - salt string - expected string - }{ - {"sha1", "", "d033e22ae348aeb5660fc2140aec35850c4da997"}, - {"sha256", "", "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"}, - {"sha384", "", "9ca694a90285c034432c9550421b7b9dbd5c0f4b6673f05f6dbce58052ba20e4248041956ee8c9a2ec9f10290cdc0782"}, - {"sha512", "", "c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec"}, - {"ssha1", "salt", "9bc7aa55f08fdad935c3f8362d3f48bcf70eb280"}, - {"ssha256", "salt", "f9a81477552594c79f2abc3fc099daa896a6e3a3590a55ffa392b6000412e80b"}, - {"ssha384", "salt", "9ed776b477fcfc1b5e584989e8d770f5e17d98a7643546a63c2b07d4ab00f1348f6b8e73103d3a23554f727136e8c215"}, - {"ssha512", "salt", "3c4a79782143337be4492be072abcfe979dd703c00541a8c39a0f3df4bab2029c050cf46fddc47090b5b04ac537b3e78189e3de16e601e859f95c51ac9f6dafb"}, - } - - for _, e := range tests { - var fn func(pass []byte, hash any) []byte - switch e.enc { - case "sha1": - fn = CryptEncoderSHA1 - case "ssha1": - fn = CryptEncoderSSHA1(e.salt) - case "sha256": - fn = CryptEncoderSHA256 - case "ssha256": - fn = CryptEncoderSSHA256(e.salt) - case "sha384": - fn = CryptEncoderSHA384 - case "ssha384": - fn = CryptEncoderSSHA384(e.salt) - case "sha512": - fn = CryptEncoderSHA512 - case "ssha512": - fn = CryptEncoderSSHA512(e.salt) - } - - h := fn([]byte("admin"), nil) - if strings.Compare(fmt.Sprintf("%x", h), e.expected) != 0 { - t.Fatalf("Invalid %s hash: expected: %s; got: %x", strings.ToUpper(e.enc), e.expected, h) - } - } -} -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build go1.13 && cgo // +build go1.13,cgo func TestBeginTxCancel(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") @@ -828,12 +754,6 @@ func TestStmtReadonly(t *testing.T) { t.Error("insert seen as read-only") } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build go1.8 && cgo // +build go1.8,cgo func TestNamedParams(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") @@ -1291,12 +1211,6 @@ func TestFileCopyTruncate(t *testing.T) { t.Fatal("create table error:", err) } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build !sqlite_omit_load_extension // +build !sqlite_omit_load_extension func TestExtensionsError(t *testing.T) { sql.Register("sqlite3_TestExtensionsError", @@ -1347,7 +1261,6 @@ func TestLoadExtensionError(t *testing.T) { t.Fatal("expected error from sqlite3_enable_load_extension to be returned") } } -// //go:build sqlite_column_metadata // +build sqlite_column_metadata func TestColumnTableName(t *testing.T) { d := SQLiteDriver{} @@ -1382,12 +1295,6 @@ func TestColumnTableName(t *testing.T) { t.Fatalf("Incorrect table name returned expected: %s, got: %s", exp, got) } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build cgo // +build cgo func TestFTS3(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") @@ -1502,7 +1409,6 @@ func TestFTS4(t *testing.T) { t.Fatal("Result should be only one") } } -// //go:build sqlite_math_functions // +build sqlite_math_functions func TestMathFunctions(t *testing.T) { db, err := sql.Open("sqlite3", ":memory:") @@ -1524,13 +1430,6 @@ func TestMathFunctions(t *testing.T) { } } } -// Copyright (C) 2019 G.J.R. Timmer <gjr.timmer@gmail.com>. -// Copyright (C) 2018 segment.com <friends@segment.com> -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build sqlite_preupdate_hook // +build sqlite_preupdate_hook type preUpdateHookDataForTest struct { databaseName string @@ -1647,7 +1546,6 @@ func TestPreUpdateHook(t *testing.T) { } } */ -// //go:build !libsqlite3 || sqlite_serialize // +build !libsqlite3 sqlite_serialize func TestSerializeDeserialize(t *testing.T) { // Connect to the source database. @@ -1733,12 +1631,6 @@ func TestSerializeDeserialize(t *testing.T) { t.Fatalf("Destination table does not have the expected records") } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build sqlite_unlock_notify // +build sqlite_unlock_notify func TestUnlockNotify(t *testing.T) { tempFilename := TempFilename(t) @@ -1944,12 +1836,6 @@ func TestUnlockNotifyDeadlock(t *testing.T) { wg.Wait() } -// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build sqlite_userauth // +build sqlite_userauth var ( conn *SQLiteConn @@ -2079,514 +1965,6 @@ func init() { } } -/* -func TestUserAuthCreateDatabase(t *testing.T) { - f, db, c, err := connect(t, "", "admin", "admin") - if err != nil && c == nil && db == nil { - t.Fatal(err) - } - defer db.Close() - defer os.Remove(f) - - enabled, err := authEnabled(db) - if err != nil || !enabled { - t.Fatalf("UserAuth not enabled: %s", err) - } - - e, err := userExists(db, "admin") - if err != nil { - t.Fatal(err) - } - if e != 1 { - t.Fatal("UserAuth: admin does not exists") - } - a, err := isAdmin(db, "admin") - if err != nil { - t.Fatal(err) - } - if !a { - t.Fatal("UserAuth: User is not administrator") - } -} - -func TestUserAuthCreateDatabaseWithoutArgs(t *testing.T) { - _, db, c, err := connect(t, "", "", "") - if err == nil && c == nil && db == nil { - t.Fatal("Should have failed due to missing _auth_* parameters") - } - - _, db, c, err = connect(t, "", "", "admin") - if err == nil && c == nil && db == nil { - t.Fatal("Should have failed due to missing _auth_user parameter") - } - - _, db, c, err = connect(t, "", "admin", "") - if err == nil && c == nil && db == nil { - t.Fatal("Should have failed due to missing _auth_pass parameter") - } -} - -func TestUserAuthLogin(t *testing.T) { - f1, err := create(t, "admin", "admin") - if err != nil { - t.Fatal(err) - } - defer os.Remove(f1) - - f2, db2, c2, err := connect(t, f1, "admin", "admin") - if err != nil { - t.Fatal(err) - } - defer db2.Close() - if f1 != f2 { - t.Fatal("UserAuth: Database file mismatch") - } - - // Test lower level authentication - err = c2.Authenticate("admin", "admin") - if err != nil { - t.Fatalf("UserAuth: *SQLiteConn.Authenticate() Failed: %s", err) - } - - // Test Login Failed - _, _, _, err = connect(t, f1, "admin", "invalid") - if err == nil { - t.Fatal("Login successful while expecting to fail") - } - if err != ErrUnauthorized { - t.Fatal(err) - } - err = c2.Authenticate("admin", "invalid") - if err == nil { - t.Fatal("Login successful while expecting to fail") - } - if err != ErrUnauthorized { - t.Fatal(err) - } -} - -func TestUserAuthAddAdmin(t *testing.T) { - f, db, c, err := connect(t, "", "admin", "admin") - if err != nil && c == nil && db == nil { - t.Fatal(err) - } - defer db.Close() - defer os.Remove(f) - - // Add Admin User through SQL call - rv, err := addUser(db, "admin2", "admin2", 1) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Check if user was created - exists, err := userExists(db, "admin2") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'admin2' does not exists") - } - - // Check if user was created as an Administrator - admin, err := isAdmin(db, "admin2") - if err != nil { - t.Fatal(err) - } - if !admin { - t.Fatal("UserAuth: 'admin2' is not administrator") - } - - // Test *SQLiteConn - err = c.AuthUserAdd("admin3", "admin3", true) - if err != nil { - t.Fatal(err) - } - - // Check if user was created - exists, err = userExists(db, "admin2") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'admin3' does not exists") - } - - // Check if the user was created as an Administrator - admin, err = isAdmin(db, "admin3") - if err != nil { - t.Fatal(err) - } - if !admin { - t.Fatal("UserAuth: 'admin3' is not administrator") - } -} - -func TestUserAuthAddUser(t *testing.T) { - f1, db1, c, err := connect(t, "", "admin", "admin") - if err != nil && c == nil && db == nil { - t.Fatal(err) - } - defer os.Remove(f1) - - // Add user through SQL call - rv, err := addUser(db1, "user", "user", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Check if user was created - exists, err := userExists(db1, "user") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'user' does not exists") - } - - // Check if user was created as an Administrator - admin, err := isAdmin(db1, "user") - if err != nil { - t.Fatal(err) - } - if admin { - t.Fatal("UserAuth: 'user' is administrator") - } - - // Test *SQLiteConn - err = c.AuthUserAdd("user2", "user2", false) - if err != nil { - t.Fatal(err) - } - - // Check if user was created - exists, err = userExists(db1, "user2") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'user2' does not exists") - } - - // Check if the user was created as an Administrator - admin, err = isAdmin(db1, "user2") - if err != nil { - t.Fatal(err) - } - if admin { - t.Fatal("UserAuth: 'user2' is administrator") - } - - // Reconnect as normal user - db1.Close() - _, db2, c2, err := connect(t, f1, "user", "user") - if err != nil { - t.Fatal(err) - } - defer db2.Close() - - // Try to create admin user while logged in as normal user - rv, err = addUser(db2, "admin2", "admin2", 1) - if err != nil { - t.Fatal(err) - } - if rv != SQLITE_AUTH { - t.Fatal("Created admin user while not allowed") - } - - err = c2.AuthUserAdd("admin3", "admin3", true) - if err != ErrAdminRequired { - t.Fatal("Created admin user while not allowed") - } - - // Try to create normal user while logged in as normal user - rv, err = addUser(db2, "user3", "user3", 0) - if err != nil { - t.Fatal(err) - } - if rv != SQLITE_AUTH { - t.Fatal("Created user while not allowed") - } - - err = c2.AuthUserAdd("user4", "user4", false) - if err != ErrAdminRequired { - t.Fatal("Created user while not allowed") - } -} - -func TestUserAuthModifyUser(t *testing.T) { - f1, db1, c1, err := connect(t, "", "admin", "admin") - if err != nil && c1 == nil && db == nil { - t.Fatal(err) - } - defer os.Remove(f1) - - // Modify Password for current logged in admin - // through SQL - rv, err := modifyUser(db1, "admin", "admin2", 1) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to modify password for admin") - } - - // Modify password for current logged in admin - // through *SQLiteConn - err = c1.AuthUserChange("admin", "admin3", true) - if err != nil { - t.Fatal(err) - } - - // Modify Administrator Flag - // Because we are current logged in as 'admin' - // Changing our own admin flag should fail. - rv, err = modifyUser(db1, "admin", "admin3", 0) - if err != nil { - t.Fatal(err) - } - if rv != SQLITE_AUTH { - t.Fatal("Successfully changed admin flag while not allowed") - } - - // Modify admin flag through (*SQLiteConn) - // Because we are current logged in as 'admin' - // Changing our own admin flag should fail. - err = c1.AuthUserChange("admin", "admin3", false) - if err != ErrAdminRequired { - t.Fatal("Successfully changed admin flag while not allowed") - } - - // Add normal user - rv, err = addUser(db1, "user", "password", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - rv, err = addUser(db1, "user2", "user2", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Modify other user password and flag through SQL - rv, err = modifyUser(db1, "user", "pass", 1) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to modify password for user") - } - - // Modify other user password and flag through *SQLiteConn - err = c1.AuthUserChange("user", "newpass", false) - if err != nil { - t.Fatal(err) - } - - // Disconnect database for reconnect - db1.Close() - _, db2, c2, err := connect(t, f1, "user", "newpass") - if err != nil { - t.Fatal(err) - } - defer db2.Close() - - // Modify other user password through SQL - rv, err = modifyUser(db2, "user2", "newpass", 0) - if err != nil { - t.Fatal(err) - } - if rv != SQLITE_AUTH { - t.Fatal("Password change successful while not allowed") - } - - // Modify other user password and flag through *SQLiteConn - err = c2.AuthUserChange("user2", "invalid", false) - if err != ErrAdminRequired { - t.Fatal("Password change successful while not allowed") - } -} - -func TestUserAuthDeleteUser(t *testing.T) { - f1, db1, c, err := connect(t, "", "admin", "admin") - if err != nil && c == nil && db == nil { - t.Fatal(err) - } - defer os.Remove(f1) - - // Add Admin User 2 - rv, err := addUser(db1, "admin2", "admin2", 1) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - rv, err = addUser(db1, "admin3", "admin3", 1) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Check if user was created - exists, err := userExists(db1, "admin2") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'admin2' does not exists") - } - - exists, err = userExists(db1, "admin3") - if err != nil { - t.Fatal(err) - } - if exists != 1 { - t.Fatal("UserAuth: 'admin2' does not exists") - } - - // Delete user through SQL - rv, err = deleteUser(db1, "admin2") - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to delete admin2") - } - - // Verify user admin2 deleted - exists, err = userExists(db1, "admin2") - if err != nil { - t.Fatal(err) - } - if exists != 0 { - t.Fatal("UserAuth: 'admin2' still exists") - } - - // Delete user through *SQLiteConn - rv, err = deleteUser(db1, "admin3") - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to delete admin3") - } - - // Verify user admin3 deleted - exists, err = userExists(db1, "admin3") - if err != nil { - t.Fatal(err) - } - if exists != 0 { - t.Fatal("UserAuth: 'admin3' still exists") - } - - // Add normal user for reconnect and privileges check - rv, err = addUser(db1, "reconnect", "reconnect", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Add normal user for deletion through SQL - rv, err = addUser(db1, "user", "user", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - rv, err = addUser(db1, "user2", "user2", 0) - if err != nil { - t.Fatal(err) - } - if rv != 0 { - t.Fatal("Failed to add user") - } - - // Close database for reconnect - db1.Close() - - // Reconnect as normal user - _, db2, c2, err := connect(t, f1, "reconnect", "reconnect") - if err != nil { - t.Fatal(err) - } - defer db2.Close() - - // Delete user while logged in as normal user - // through SQL - rv, err = deleteUser(db2, "user") - if err != nil { - t.Fatal(err) - } - if rv != SQLITE_AUTH { - t.Fatal("Successfully deleted user wthout proper privileges") - } - - // Delete user while logged in as normal user - // through *SQLiteConn - err = c2.AuthUserDelete("user2") - if err != ErrAdminRequired { - t.Fatal("Successfully deleted user wthout proper privileges") - } -} -*/ - -func TestUserAuthEncoders(t *testing.T) { - cases := map[string]string{ - "sha1": "", - "ssha1": "salted", - "sha256": "", - "ssha256": "salted", - "sha384": "", - "ssha384": "salted", - "sha512": "", - "ssha512": "salted", - } - - for enc, salt := range cases { - f, err := createWithCrypt(t, "admin", "admin", enc, salt) - if err != nil { - t.Fatal(err) - } - defer os.Remove(f) - - _, db, _, err := connectWithCrypt(t, f, "admin", "admin", enc, salt) - if err != nil { - t.Fatal(err) - } - defer db.Close() - if e, err := authEnabled(db); err != nil && !e { - t.Fatalf("UserAuth (%s) not enabled %s", enc, err) - } - } -} -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build sqlite_vtable || vtable // +build sqlite_vtable vtable - type testModule struct { t *testing.T intarray []int @@ -3169,12 +2547,6 @@ func TestCreateModuleEponymousOnly(t *testing.T) { t.Logf("couldn't drop virtual table: %v", err) } } -// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// //go:build cgo // +build cgo func TempFilename(t testing.TB) string { f, err := ioutil.TempFile("", "go-sqlite3-test-") @@ -5673,7 +5045,6 @@ func MainTest() { { "TestExtendedErrorCodes_NotNull", TestExtendedErrorCodes_NotNull }, { "TestExtendedErrorCodes_Unique", TestExtendedErrorCodes_Unique }, { "TestError_SystemErrno", TestError_SystemErrno }, - { "TestCryptEncoders", TestCryptEncoders }, { "TestBeginTxCancel", TestBeginTxCancel }, { "TestStmtReadonly", TestStmtReadonly }, { "TestNamedParams", TestNamedParams }, @@ -5695,14 +5066,6 @@ func MainTest() { // { "TestUnlockNotify", TestUnlockNotify }, // { "TestUnlockNotifyMany", TestUnlockNotifyMany }, // { "TestUnlockNotifyDeadlock", TestUnlockNotifyDeadlock }, - // { "TestUserAuthCreateDatabase", TestUserAuthCreateDatabase }, - // { "TestUserAuthCreateDatabaseWithoutArgs", TestUserAuthCreateDatabaseWithoutArgs }, - // { "TestUserAuthLogin", TestUserAuthLogin }, - // { "TestUserAuthAddAdmin", TestUserAuthAddAdmin }, - // { "TestUserAuthAddUser", TestUserAuthAddUser }, - // { "TestUserAuthModifyUser", TestUserAuthModifyUser }, - // { "TestUserAuthDeleteUser", TestUserAuthDeleteUser }, - // { "TestUserAuthEncoders", TestUserAuthEncoders }, { "TestCreateModule", TestCreateModule }, { "TestVUpdate", TestVUpdate }, { "TestCreateModuleEponymousOnly", TestCreateModuleEponymousOnly }, |