2018-12-27 21:49:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-19 22:01:41 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.teamworkapps.com/shortcut/scsusers"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
2018-12-27 21:49:59 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
var email string
|
|
|
|
|
|
|
|
flag.StringVar(&email, "email", "", "Email address to use for registration test")
|
|
|
|
flag.Parse()
|
|
|
|
|
2018-12-27 22:09:23 +00:00
|
|
|
db, err:=sqlx.Open("sqlite3", ":memory:")
|
2018-12-27 21:49:59 +00:00
|
|
|
if err!=nil {
|
|
|
|
fmt.Println("Couldn't open sqlite3 in-memory db:" + err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
err=db.Ping()
|
|
|
|
if err!=nil {
|
|
|
|
fmt.Println("Couldn't ping sqlite3 in-memory db:" + err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
schema:=`CREATE TABLE test_auth (
|
2023-09-19 22:01:41 +00:00
|
|
|
id int primary key autoincrement,
|
|
|
|
username text NOT NULL unique key
|
|
|
|
password text NOT NULL);`
|
2018-12-27 21:49:59 +00:00
|
|
|
_ ,err=db.Exec(schema)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Schema creation failed: " + err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-01-02 19:04:40 +00:00
|
|
|
scsusers.Init(db, "test", "Example Test", "nobody@nowhere.com", "localhost:25")
|
2018-12-27 21:49:59 +00:00
|
|
|
a:=scsusers.UsernameAvailable("testuser")
|
|
|
|
fmt.Printf("Initial test of username available: %v\n", a)
|
|
|
|
a=scsusers.Register("testuser", email, "127.0.0.1")
|
|
|
|
fmt.Printf("Register returned %v\n",a)
|
2018-12-27 22:17:30 +00:00
|
|
|
fmt.Printf("Attempt to log in with invalid username returned %v\n", scsusers.Login("baduser", "badpass"))
|
2018-12-27 21:49:59 +00:00
|
|
|
fmt.Printf("Enter code from email:")
|
|
|
|
var code string
|
|
|
|
fmt.Scan(&code)
|
|
|
|
a=scsusers.Login("testuser", code)
|
|
|
|
fmt.Printf("Login returned %v\n",a)
|
|
|
|
|
|
|
|
|
|
|
|
}
|