From f3e36de78aa9d13e74fabbb115bd7a20be57abaf Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 17 Nov 2021 14:40:39 +0100 Subject: [PATCH] fix broken GetInstanceAccount selector (#311) * fix broken GetInstanceAccount selector * patch tests --- internal/db/bundb/account.go | 4 ++-- internal/db/bundb/admin_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 9def811fb..8d2cea272 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -127,13 +127,13 @@ func (a *accountDB) GetInstanceAccount(ctx context.Context, domain string) (*gts q := a.newAccountQ(account) - if domain == "" { + if domain != "" { q = q. Where("account.username = ?", domain). Where("account.domain = ?", domain) } else { q = q. - Where("account.username = ?", domain). + Where("account.username = ?", a.config.Host). WhereGroup(" AND ", whereEmptyOrNull("domain")) } diff --git a/internal/db/bundb/admin_test.go b/internal/db/bundb/admin_test.go index a4c380c03..74a8c2b7d 100644 --- a/internal/db/bundb/admin_test.go +++ b/internal/db/bundb/admin_test.go @@ -37,7 +37,7 @@ func (suite *AdminTestSuite) TestCreateInstanceAccount() { testrig.CreateTestTables(suite.db) // make sure there's no instance account in the db yet - acct, err := suite.db.GetInstanceAccount(context.Background(), suite.config.Host) + acct, err := suite.db.GetInstanceAccount(context.Background(), "") suite.Error(err) suite.Nil(acct) @@ -46,7 +46,7 @@ func (suite *AdminTestSuite) TestCreateInstanceAccount() { suite.NoError(err) // and now check it exists - acct, err = suite.db.GetInstanceAccount(context.Background(), suite.config.Host) + acct, err = suite.db.GetInstanceAccount(context.Background(), "") suite.NoError(err) suite.NotNil(acct) }