|
|
|
|
@@ -112,11 +112,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -138,7 +138,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -165,7 +165,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -208,7 +208,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -248,7 +248,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
db, basePath, ctx := setupIntegrationTest(t)
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, uuid.New(), pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -296,7 +296,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
db, basePath, ctx := setupIntegrationTest(t)
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, uuid.New(), pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -415,7 +415,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
db, basePath, ctx := setupIntegrationTest(t)
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, uuid.New(), pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -451,10 +451,10 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM session WHERE session_id = ?", anonymousSession.Value).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM session WHERE session_id = ?", anonymousSession.Value).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM token WHERE token = ?", anonymousCsrfToken).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM token WHERE token = ?", anonymousCsrfToken).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -469,11 +469,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -548,7 +548,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
db, basePath, ctx := setupIntegrationTest(t)
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, uuid.New(), service.GetHashPassword("password", []byte("salt")), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -627,11 +627,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Contains(t, resp.Header.Get("Hx-Trigger"), "An activation link has been send to your email")
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE email = ? AND email_verified = FALSE", "mail@mail.de").Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE email = ? AND email_verified = FALSE", "mail@mail.de").Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
var token string
|
|
|
|
|
err = db.QueryRow("SELECT t.token FROM token t INNER JOIN user u ON u.user_id = t.user_id WHERE u.email = ? AND t.type = ?", "mail@mail.de", types.TokenTypeEmailVerify).Scan(&token)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT t.token FROM token t INNER JOIN user u ON u.user_id = t.user_id WHERE u.email = ? AND t.type = ?", "mail@mail.de", types.TokenTypeEmailVerify).Scan(&token)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.NotEmpty(t, token)
|
|
|
|
|
})
|
|
|
|
|
@@ -644,7 +644,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, []byte("pass"), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -658,7 +658,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = FALSE", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = FALSE", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -670,11 +670,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
token := "my-outdated-verifying-token"
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, []byte("pass"), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO token (token, user_id, type, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, ?, datetime("now", "-16 minute"), datetime("now", "-1 minute"))`, token, userId, types.TokenTypeEmailVerify)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -688,7 +688,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = FALSE", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = FALSE", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -700,11 +700,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
token := "my-verifying-token"
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, []byte("pass"), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO token (token, user_id, session_id, type, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, "", ?, datetime("now"), datetime("now", "+15 minute"))`, token, userId, types.TokenTypeEmailVerify)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -718,7 +718,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = TRUE", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND email_verified = TRUE", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -747,11 +747,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -765,7 +765,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var csrfToken string
|
|
|
|
|
err = db.QueryRow("SELECT token FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypeCsrf).Scan(&csrfToken)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT token FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypeCsrf).Scan(&csrfToken)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
req, err = http.NewRequestWithContext(ctx, http.MethodPost, basePath+"/api/auth/signout", nil)
|
|
|
|
|
@@ -785,7 +785,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, -1, cookie.MaxAge)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -825,13 +825,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -871,13 +871,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -964,22 +964,22 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM token WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM token WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM account WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM account WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM treasure_chest WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM treasure_chest WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM \"transaction\" WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM \"transaction\" WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1040,13 +1040,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1069,7 +1069,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1080,13 +1080,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1119,7 +1119,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1130,13 +1130,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1169,7 +1169,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1181,21 +1181,21 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userIdOther := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime(), datetime("now", "+1 day"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES ("second", ?, datetime(), datetime("now", "+1 day"))`, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
|
_, err = db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES ("other", ?, datetime(), datetime("now", "+1 day"))`, userIdOther)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1232,12 +1232,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
pass = service.GetHashPassword("MyNewSecurePassword1!", []byte("salt"))
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
|
|
|
|
|
var sessionIds []string
|
|
|
|
|
sessions, err := db.Query(`SELECT session_id FROM session WHERE NOT user_id = ? ORDER BY session_id`, uuid.Nil)
|
|
|
|
|
sessions, err := db.QueryContext(ctx, `SELECT session_id FROM session WHERE NOT user_id = ? ORDER BY session_id`, uuid.Nil)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
for sessions.Next() {
|
|
|
|
|
var sessionId string
|
|
|
|
|
@@ -1260,13 +1260,13 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES ("session-id", ?, datetime(), datetime("now", "+1 day"))`, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1288,7 +1288,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1317,7 +1317,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = d.QueryRow("SELECT COUNT(*) FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypePasswordReset).Scan(&rows)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT COUNT(*) FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypePasswordReset).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1363,7 +1363,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := db.Exec(`
|
|
|
|
|
_, err := db.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", TRUE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1399,7 +1399,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Contains(t, resp.Header.Get("Hx-Trigger"), msg)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = db.QueryRow("SELECT COUNT(*) FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypePasswordReset).Scan(&rows)
|
|
|
|
|
err = db.QueryRowContext(ctx, "SELECT COUNT(*) FROM token WHERE user_id = ? AND type = ?", userId, types.TokenTypePasswordReset).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1413,7 +1413,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1445,7 +1445,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = d.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1456,7 +1456,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1473,7 +1473,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
token := "password-reset-token"
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO token (token, user_id, session_id, type, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, datetime("now", "-16 minute"), datetime("now", "-1 minute"))`, token, userId, "", types.TokenTypePasswordReset)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1494,7 +1494,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = d.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1505,7 +1505,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1522,7 +1522,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.NotEmpty(t, anonymousCsrfToken)
|
|
|
|
|
|
|
|
|
|
token := "password-reset-token"
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO token (token, user_id, session_id, type, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, datetime("now"), datetime("now", "+15 minute"))`, token, userId, "", types.TokenTypePasswordReset)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1543,7 +1543,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = d.QueryRow("SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT COUNT(*) FROM user WHERE user_id = ? AND password = ?", userId, pass).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 1, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1554,12 +1554,12 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
|
|
|
|
|
pass := service.GetHashPassword("password", []byte("salt"))
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, pass, []byte("salt"))
|
|
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES ("session-id", ?, datetime(), datetime("now", "+1 day"))`, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1590,7 +1590,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
var token string
|
|
|
|
|
err = d.QueryRow("SELECT token FROM token WHERE type = ?", types.TokenTypePasswordReset).Scan(&token)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT token FROM token WHERE type = ?", types.TokenTypePasswordReset).Scan(&token)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
formData = url.Values{
|
|
|
|
|
@@ -1608,7 +1608,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
_ = resp.Body.Close()
|
|
|
|
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
|
|
|
|
|
|
|
|
|
sessions, err := d.Query("SELECT session_id FROM session WHERE user_id = ?", userId)
|
|
|
|
|
sessions, err := d.QueryContext(ctx, "SELECT session_id FROM session WHERE user_id = ?", userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.False(t, sessions.Next())
|
|
|
|
|
})
|
|
|
|
|
@@ -1623,11 +1623,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, []byte("pass"), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime("now", "-8 hour"), datetime("now", "-1 minute"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1643,7 +1643,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
assert.NotEqual(t, sessionId, newSession.Value)
|
|
|
|
|
|
|
|
|
|
var rows int
|
|
|
|
|
err = d.QueryRow("SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
err = d.QueryRowContext(ctx, "SELECT COUNT(*) FROM session WHERE user_id = ?", userId).Scan(&rows)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, 0, rows)
|
|
|
|
|
})
|
|
|
|
|
@@ -1670,11 +1670,11 @@ func TestIntegrationAuth(t *testing.T) {
|
|
|
|
|
userId := uuid.New()
|
|
|
|
|
sessionId := "session-id"
|
|
|
|
|
|
|
|
|
|
_, err := d.Exec(`
|
|
|
|
|
_, err := d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO user (user_id, email, email_verified, is_admin, password, salt, created_at)
|
|
|
|
|
VALUES (?, "mail@mail.de", FALSE, FALSE, ?, ?, datetime())`, userId, []byte("pass"), []byte("salt"))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
_, err = d.Exec(`
|
|
|
|
|
_, err = d.ExecContext(ctx, `
|
|
|
|
|
INSERT INTO session (session_id, user_id, created_at, expires_at)
|
|
|
|
|
VALUES (?, ?, datetime("now", "-8 hour"), datetime("now", "-1 minute"))`, sessionId, userId)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
@@ -1769,7 +1769,7 @@ func TestIntegrationAccount(t *testing.T) {
|
|
|
|
|
_ = resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
var id uuid.UUID
|
|
|
|
|
err = db.Get(&id, "SELECT id FROM account")
|
|
|
|
|
err = db.GetContext(ctx, &id, "SELECT id FROM account")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
|
|