Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
305f696
fix: use unique ID for linked accounts
sreya Aug 9, 2022
b4ab301
fixup a bunch of stuff
sreya Aug 9, 2022
dd2df9c
gofmt
sreya Aug 9, 2022
0356f46
make fake db happy
sreya Aug 9, 2022
6b1b900
make audit happy
sreya Aug 9, 2022
8f63d5c
fix some tests
sreya Aug 10, 2022
de7db33
make gen
sreya Aug 10, 2022
5fdf899
fix tests
sreya Aug 10, 2022
3a4d049
fmt
sreya Aug 10, 2022
4108ece
begin refactoring PR
sreya Aug 11, 2022
14b5382
finish migration
sreya Aug 12, 2022
8553501
use main sql.dump
sreya Aug 12, 2022
f748d3d
lift error
sreya Aug 12, 2022
c1b9871
new migration
sreya Aug 12, 2022
e41c103
more rewriting
sreya Aug 12, 2022
bb9b777
even more rewriting
sreya Aug 12, 2022
d940dae
finish up some test fixing
sreya Aug 12, 2022
c97d572
typos
sreya Aug 12, 2022
10bfe77
Merge branch 'main' into jon/userauth
sreya Aug 12, 2022
28a37f1
fix some remaining tests
sreya Aug 12, 2022
c889bf0
fix a gnarly bug
sreya Aug 12, 2022
0196a49
add a down migration
sreya Aug 12, 2022
b5dc95b
add fkey on user_links, fix tests, add comments
sreya Aug 12, 2022
f2f76e9
add login_type to users table
sreya Aug 12, 2022
940ced4
Merge branch 'main' into jon/userauth
sreya Aug 12, 2022
eb266db
fix login_type query
sreya Aug 13, 2022
4671bf6
fix tests
sreya Aug 13, 2022
c41f4e6
fix audit
sreya Aug 13, 2022
f3d8392
fix down
sreya Aug 13, 2022
cc8400b
fix one more test
sreya Aug 13, 2022
5c7cbae
Merge branch 'main' into jon/userauth
sreya Aug 17, 2022
083d256
pr comments
sreya Aug 17, 2022
92c185d
fix conflicting migration file
sreya Aug 17, 2022
05595d8
generate.sh
sreya Aug 17, 2022
aa90148
butcher the english language to appease colin
sreya Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
even more rewriting
  • Loading branch information
sreya committed Aug 12, 2022
commit bb9b77760543a6f4bb0fda0f773f3364e53ce9e1
77 changes: 77 additions & 0 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type data struct {
organizations []database.Organization
organizationMembers []database.OrganizationMember
users []database.User
userLinks []database.UserLink

// New tables
auditLogs []database.AuditLog
Expand Down Expand Up @@ -2252,3 +2253,79 @@ func (q *fakeQuerier) GetDeploymentID(_ context.Context) (string, error) {

return q.deploymentID, nil
}

func (q *fakeQuerier) GetUserLinkByLinkedID(_ context.Context, id string) (database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, link := range q.userLinks {
if link.LinkedID == id {
return link, nil
}
}
return database.UserLink{}, sql.ErrNoRows
}

func (q *fakeQuerier) GetUserLinkByUserIDLoginType(_ context.Context, params database.GetUserLinkByUserIDLoginTypeParams) (database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, link := range q.userLinks {
if link.UserID == params.UserID && link.LoginType == params.LoginType {
return link, nil
}
}
return database.UserLink{}, sql.ErrNoRows
}

func (q *fakeQuerier) InsertUserLink(_ context.Context, params database.InsertUserLinkParams) (database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

link := database.UserLink{
UserID: params.UserID,
LoginType: params.LoginType,
LinkedID: params.LinkedID,
OAuthAccessToken: params.OAuthAccessToken,
OAuthRefreshToken: params.OAuthRefreshToken,
OAuthExpiry: params.OAuthExpiry,
}

q.userLinks = append(q.userLinks, link)

return link, nil
}

func (q *fakeQuerier) UpdateUserLinkedID(_ context.Context, params database.UpdateUserLinkedIDParams) (database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for i, link := range q.userLinks {
if link.UserID == params.UserID && link.LoginType == params.LoginType {
link.LinkedID = params.LinkedID

q.userLinks[i] = link
return link, nil
}
}

return database.UserLink{}, sql.ErrNoRows
}

func (q *fakeQuerier) UpdateUserLink(_ context.Context, params database.UpdateUserLinkParams) (database.UserLink, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for i, link := range q.userLinks {
if link.UserID == params.UserID && link.LoginType == params.LoginType {
link.OAuthAccessToken = params.OAuthAccessToken
link.OAuthRefreshToken = params.OAuthRefreshToken
link.OAuthExpiry = params.OAuthExpiry

q.userLinks[i] = link
return link, nil
}
}

return database.UserLink{}, sql.ErrNoRows
}
1 change: 0 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions coderd/database/migrations/000034_linked_user_id.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS user_links (
linked_id text DEFAULT ''::text NOT NULL,
oauth_access_token text DEFAULT ''::text NOT NULL,
oauth_refresh_token text DEFAULT ''::text NOT NULL,
oauth_id_token text DEFAULT ''::text NOT NULL,
oauth_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL,
UNIQUE(user_id, login_type)
);
Expand All @@ -18,7 +17,6 @@ INSERT INTO user_links
linked_id,
oauth_access_token,
oauth_refresh_token,
oauth_id_token,
oauth_expiry
)
SELECT
Expand All @@ -27,7 +25,6 @@ SELECT
'',
keys.oauth_access_token,
keys.oauth_refresh_token,
keys.oauth_id_token,
keys.oauth_expiry
FROM
(
Expand Down
1 change: 0 additions & 1 deletion coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 6 additions & 17 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion coderd/httpmw/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs, redirectToLogin bool
OAuthRefreshToken: link.OAuthRefreshToken,
OAuthExpiry: link.OAuthExpiry,
})

if err != nil {
write(http.StatusInternalServerError, codersdk.Response{
Message: internalErrorMessage,
Detail: fmt.Sprintf("update user_link: %s.", err.Error()),
})
return
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ func addUser(t *testing.T, db database.Store, roles ...string) (database.User, s
Email: "[email protected]",
Username: "admin",
RBACRoles: roles,
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/organizationparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func TestOrganizationParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)
_, err = db.InsertAPIKey(r.Context(), database.InsertAPIKeyParams{
Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/templateparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestTemplateParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/templateversionparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestTemplateVersionParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
8 changes: 3 additions & 5 deletions coderd/httpmw/userparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ func TestUserParam(t *testing.T) {
})

user, err := db.InsertUser(r.Context(), database.InsertUserParams{
ID: uuid.New(),
Email: "[email protected]",
Username: "admin",
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
ID: uuid.New(),
Email: "[email protected]",
Username: "admin",
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/workspaceagentparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestWorkspaceAgentParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/workspacebuildparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestWorkspaceBuildParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/httpmw/workspaceparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestWorkspaceParam(t *testing.T) {
Username: username,
CreatedAt: database.Now(),
UpdatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)

Expand Down
2 changes: 0 additions & 2 deletions coderd/provisionerjobs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func TestProvisionerJobLogs_Unit(t *testing.T) {
_, err = fDB.InsertUser(ctx, database.InsertUserParams{
ID: userID,
RBACRoles: []string{"admin"},
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)
_, err = fDB.InsertWorkspaceBuild(ctx, database.InsertWorkspaceBuildParams{
Expand Down
4 changes: 0 additions & 4 deletions coderd/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func TestTelemetry(t *testing.T) {
_, err = db.InsertUser(ctx, database.InsertUserParams{
ID: uuid.New(),
CreatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)
_, err = db.InsertWorkspace(ctx, database.InsertWorkspaceParams{
Expand Down Expand Up @@ -107,8 +105,6 @@ func TestTelemetry(t *testing.T) {
ID: uuid.New(),
Email: "[email protected]",
CreatedAt: database.Now(),
LinkedID: uuid.NewString(),
LoginType: database.LoginTypePassword,
})
require.NoError(t, err)
snapshot := collectSnapshot(t, db)
Expand Down