Skip to content

fix: Use membership endpoint to ensure user exists in a GitHub team #3129

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 1 commit into from
Jul 22, 2022

Conversation

kylecarbs
Copy link
Member

This was using the incorrect GitHub endpoint prior, which fetched a team
by slug. Any user in a GitHub organization can view all teams, so this
didn't block signups like intended.

I've verified this API returns an error when the calling user is not a
member of the team requested.

Fixes #3105.

This was using the incorrect GitHub endpoint prior, which fetched a team
by slug. Any user in a GitHub organization can view all teams, so this
didn't block signups like intended.

I've verified this API returns an error when the calling user is not a
member  of the team requested.

Fixes #3105.
@kylecarbs kylecarbs requested a review from Emyrk July 22, 2022 17:50
@kylecarbs kylecarbs changed the title fix: Use membership endpoint to ensure user exists in team fix: Use membership endpoint to ensure user exists in a GitHub team Jul 22, 2022
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Is there an easy way to test this against github's actual api? Not totally necessary, just curious. The docs say this endpoint retrusn a 404 in the case the user is not in the team. So I assume the sdk function returns an error in this case

Screenshot from 2022-07-22 13-49-28

@kylecarbs
Copy link
Member Author

I'd prefer to not test against the API, just mock it. I think now that the mocks are correct it's easier to understand.

It does return an error on 404!

@kylecarbs kylecarbs merged commit fd4954b into main Jul 22, 2022
@kylecarbs kylecarbs deleted the fixteams branch July 22, 2022 18:54
@Emyrk
Copy link
Member

Emyrk commented Jul 22, 2022

Oh I agree with the mocks. Just as a PR reviewer, I was going to run some curls to verify the docs.

Not that I don't trust the docs.... 👀

@Emyrk
Copy link
Member

Emyrk commented Jul 22, 2022

for posterity, just checked this and it works. 👍

curl \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: token <token>" \
  https://api.github.com/orgs/coder/teams/<team>/memberships/<user>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants