Skip to content

feat: add oauth2 codes and tokens to database #11779

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

Closed
wants to merge 8 commits into from

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Jan 23, 2024

@code-asher code-asher changed the title Add OAuth2 provider codes and tokens to database feat: add oauth2 codes and tokens to database Jan 23, 2024
@code-asher code-asher marked this pull request as ready for review January 23, 2024 19:23
@code-asher code-asher requested review from johnstcn and Emyrk January 23, 2024 19:23
@code-asher
Copy link
Member Author

@johnstcn just FYI I requested you along with @Emyrk since we co-wrote some of this and seems like it makes sense to get another pair of eyes.

Might have no match, and a -1 will panic.
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

In the interest of avoiding later rework, would it be possible to add test coverage for the newly added methods in this PR?

Comment on lines +1250 to +1251
q.oauth2ProviderAppCodes[index] = q.oauth2ProviderAppCodes[len(q.oauth2ProviderAppCodes)-1]
q.oauth2ProviderAppCodes = q.oauth2ProviderAppCodes[:len(q.oauth2ProviderAppCodes)-1]
Copy link
Member

Choose a reason for hiding this comment

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

The thing about this is that it does change the slice order. If we care about order from a test assertion perspective, this will fail that assumption.

Tests should be written such that if the order is required, they should specify in the query though, so we can leave this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I think we will probably not have to worry about it since we do not rely on ordering of authentication codes (there is no method to get multiple codes right now either) but seems worth keeping in mind.

I lazily copied these lines from other implementations in this file but I think it might be better to add a remove and change all of these:

func remove[T any](slice []T, i int) []T {
    return append(slice[:i], slice[i+1:]...)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The way I have been doing it (for apps and secrets which do need ordering) is to sort them before returning in their Get* calls so the underlying slice can be in any order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooo 1.21 has a Delete for slices apparently.

@code-asher
Copy link
Member Author

code-asher commented Jan 24, 2024

In the interest of avoiding later rework, would it be possible to add test coverage for the newly added methods in this PR?

Good question, do the dbauthz tests look insufficient? They test all the methods and that they return the right thing, I think (I might have the wrong impression on some of the things it does though.)

There are also the coderd tests added in the next PR (#11778) that end up hitting these methods, maybe I made the wrong call to split the PR here. I can hold off merging this until both are good to merge.

@johnstcn
Copy link
Member

johnstcn commented Jan 24, 2024

Good question, do the dbauthz tests look insufficient?

Those just test authz assertions but don't necessarily call the actual SQL queries.

I can hold off merging this until both are good to merge.

That might not be a bad idea in case you need to make some changes here.

@code-asher
Copy link
Member Author

Those just test authz assertions but don't necessarily call the actual SQL queries.

Ohhhh I had the wrong impression, good to know.

@code-asher code-asher force-pushed the asher/oauth2-exchange-db branch from 5a662d0 to 7d10b9e Compare January 24, 2024 20:18
@code-asher code-asher force-pushed the asher/oauth2-exchange-db branch from 7d10b9e to 29a9e26 Compare January 24, 2024 20:23
@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 1, 2024
@github-actions github-actions bot closed this Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants