Skip to content

Commit

Permalink
Fix revalidate query (#329)
Browse files Browse the repository at this point in the history
* fix: use correct arguments in scan when revalidation disabled

* chore: update changelog
  • Loading branch information
bobhageman authored Aug 16, 2023
1 parent 439080a commit 9e0a3f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed
- Invalid amount of arguments in query scan when e-mail revalidation is disabled

## [0.13.0] - 2023-08-10
### Added
- E-mail address revalidation, addressing issues where user's e-mail addresses can be (temporary) invalid
Expand Down
11 changes: 9 additions & 2 deletions server/keyshare/myirmaserver/postgresdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (db *postgresDB) verifyLoginToken(ctx context.Context, token, username stri

func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {
var result user
revalidation := db.db.EmailRevalidation(ctx)

// fetch username
err := db.db.QueryUserContext(ctx, "SELECT username, language, (coredata IS NULL) AS delete_in_progress FROM irma.users WHERE id = $1",
Expand All @@ -188,7 +189,7 @@ func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {

query := "SELECT email, (delete_on IS NOT NULL) AS delete_in_progress {{revalidate}} FROM irma.emails WHERE user_id = $1 AND (delete_on >= $2 OR delete_on IS NULL)"

if db.db.EmailRevalidation(ctx) {
if revalidation {
query = strings.ReplaceAll(query, "{{revalidate}}", ", (revalidate_on IS NOT NULL) AS revalidate_in_progress")
} else {
query = strings.ReplaceAll(query, "{{revalidate}}", "")
Expand All @@ -200,7 +201,13 @@ func (db *postgresDB) user(ctx context.Context, id int64) (user, error) {
query,
func(rows *sql.Rows) error {
var email userEmail
err = rows.Scan(&email.Email, &email.DeleteInProgress, &email.RevalidateInProgress)

if revalidation {
err = rows.Scan(&email.Email, &email.DeleteInProgress, &email.RevalidateInProgress)
} else {
err = rows.Scan(&email.Email, &email.DeleteInProgress)
}

result.Emails = append(result.Emails, email)
return err
},
Expand Down

0 comments on commit 9e0a3f1

Please sign in to comment.