Skip to content

fix(enterprise/dbcrypt): do not skip deleted users when encrypting or deleting #9694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 15, 2023
Prev Previous commit
Next Next commit
fmt query
  • Loading branch information
johnstcn committed Sep 15, 2023
commit 3950c097a47b09ec35d82109a565c701660aaf1a
13 changes: 12 additions & 1 deletion enterprise/cli/server_dbcrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,18 @@ func genData(t *testing.T, db database.Store, n int) []database.User {

func dumpUsers(t *testing.T, db *sql.DB, header string) {
t.Logf("%s %s %s", strings.Repeat("=", 20), header, strings.Repeat("=", 20))
rows, err := db.QueryContext(context.Background(), `select u.id, u.status, u.deleted, ul.oauth_access_token_key_id as uloatkid, ul.oauth_refresh_token_key_id as ulortkid, gal.oauth_access_token_key_id as galoatkid, gal.oauth_refresh_token_key_id as galortkid from users u left outer join user_links ul on u.id = ul.user_id left outer join git_auth_links gal on u.id = gal.user_id;`)
rows, err := db.QueryContext(context.Background(), `SELECT
u.id,
u.status,
u.deleted,
ul.oauth_access_token_key_id AS uloatkid,
ul.oauth_refresh_token_key_id AS ulortkid,
gal.oauth_access_token_key_id AS galoatkid,
gal.oauth_refresh_token_key_id AS galortkid
FROM users u
LEFT OUTER JOIN user_links ul ON u.id = ul.user_id
LEFT OUTER JOIN git_auth_links gal ON u.id = gal.user_id
ORDER BY u.created_at ASC;`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a test that this function works as expected since it's static and will only be run on failure, meaning it will most likely be outdated by the time it's needed. 😆

Perhaps this could be motivation for a testqueries package. Similar to what I did here: #9519 to generate a new (slim) package that can be wrapped around sql.DB.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd definitely be in favour of this; I'm fairly sure there are at least a couple of queries that only ever get run in unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a test that this function works as expected since it's static and will only be run on failure, meaning it will most likely be outdated by the time it's needed. 😆

Golden files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think verifying a few fields in the test is enough. Otherwise you need to stabilize the generated IDs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of making that query more complex I'll go ahead and add a follow-up PR to dump the entire test database on failure (optional, opt-in). Less work, less fuss, more benefit.

require.NoError(t, err)
defer rows.Close()
for rows.Next() {
Expand Down