Skip to content
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

RepositoriesClient.GetAllPublic() fails on GitHub Enterprise due to incorrect endpoint Uri #1204

Merged
merged 3 commits into from
Mar 29, 2016

Conversation

ryangribble
Copy link
Contributor

Due to shenanigans with the way dotnet joinsUri objects together, if any relative Uri endpoint starts with a leading slash, this "wipes out" the /api/v3/ component of the BaseAddress for GitHub Enterprise.

There were 2 occurrences of endpoint Uri's being set in ApiUrls helper class that had incorrect leading slashes on them, causing these calls (both for RepositoriesClient.GetAllPublic()) to return HTTP 406 "NotAccepted" errors when run against GitHub Enterprise due to the Url being incorrect. These have now been corrected.

Additionally I have added a safety in HttpClientAdapter class, when constructing the full uri, to trim any leading slashes off relative Uri endpoint before joining it to BaseAddress.
@shiftkey is this OK or is there another way you'd prefer to guard against this?

@ryangribble ryangribble force-pushed the fix-repositories-uri branch 2 times, most recently from 40a63f0 to 44df426 Compare March 22, 2016 11:42
@shiftkey
Copy link
Member

is this OK or is there another way you'd prefer to guard against this?

I'm a bit 👎 on the guard clause as-is but I'll sleep on it - or we can discuss it in a separate PR.

Everything else is 💎

@ryangribble
Copy link
Contributor Author

I'm a bit 👎 on the guard clause as-is but I'll sleep on it - or we can discuss it in a separate PR.
Yeah it was a bit clunky due to code analysis not allowing combining a Uri and string and also the StartsWith() needing to have StringCompareInfo set etc.

I'm not a huge fan of the guard either... but given that we aren't running integration tests against github enterprise it pretty much means that we could break any "normal" call from working against GHE if we miss that innocuous leading slash when reviewing PRs.

Other things I considered were doing something in the FormatUri() extension method, or having a convention test that checked the endpoint Uris in ApiArls.cs helper class... but in both cases that didn't protect against a contribution that doesnt use the helper class or extension method (assuming we dont pull up the contributor in the PR and ask them to use the helper class and extension method).

Then we have the other situation of any consumers of octokit that are using the client.Connection.Get<T> etc methods, and passing in their own endpoint Uri. Perhaps we dont need to "stop" them since they can fix their code (although whether they would know that the HTTP 406 is because the Uri fragments got eaten due to a leading slash, and not being able to easily debug right down into the guts of the octokit plumbing, it would lead to much hair pulling!!).

But yeah my main concern was the fact we can inadvertently break API methods from working on Enterprise and it doesnt get picked up in tests or at runtime. We could throw an exception I guess (again, that's too late if we've shipped the release though!). So that's how I came to the conclusion that there doesnt seem to be a reason NOT to trim leading slashes off. The check that it isnt an AboluteUri is needed because when dealing with multple paginated calls, the subsequent requests have the full absolute Uri in the endpoint...

@shiftkey
Copy link
Member

@ryangribble I'd love to script out something so we can verify all these URIs are correctly formatted, rather that bake that behaviour into HttpClientAdapter which may go away if we move to having HttpClient at our core. I think we could probably hack something quick and dirty together with reflection to cover ourselves...

@ryangribble ryangribble force-pushed the fix-repositories-uri branch from 44df426 to b99d178 Compare March 29, 2016 03:10
@ryangribble
Copy link
Contributor Author

OK ive reverted the change in HttpClientAdapter for now, and will just push this PR in with the correction to the URI's

Will raise a new issue for the

script out something so we can verify all these URIs are correctly formatted

part...

@shiftkey
Copy link
Member

@ryangribble thanks!

@shiftkey shiftkey merged commit 1335f37 into octokit:master Mar 29, 2016
@shiftkey shiftkey added the bugfix label Apr 8, 2016
@shiftkey
Copy link
Member

shiftkey commented Apr 8, 2016

release_notes: RepositoriesClient.GetAllPublic() failed on GitHub Enterprise usage due to incorrect Uri formatting

@ryangribble ryangribble deleted the fix-repositories-uri branch August 6, 2016 22:22
@nickfloyd nickfloyd added Type: Bug Something isn't working as documented and removed category: bug labels Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants