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

API with an unknown path should return an error #2190

Closed
nopcoder opened this issue Jul 1, 2021 · 25 comments · Fixed by #2382
Closed

API with an unknown path should return an error #2190

nopcoder opened this issue Jul 1, 2021 · 25 comments · Fixed by #2382
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@nopcoder
Copy link
Contributor

nopcoder commented Jul 1, 2021

Currently lakeFS register openapi handlers and handle all specific routes.
In case of a call to /api/v1/test, the unknown path under the API prefix, the mux will serve the request by the UI handler and return a valid HTML (UI) page.

The expected behaviour is to return a non-2xx status code with JSON error - prefered the internal error format, so the developer will handle an error and not fail to parse the response in case of a bad API call.

@nopcoder nopcoder added the bug Something isn't working label Jul 1, 2021
@nopcoder nopcoder self-assigned this Jul 1, 2021
@arielshaqed arielshaqed added the good first issue Good for newcomers label Jul 1, 2021
@nopcoder
Copy link
Contributor Author

nopcoder commented Jul 8, 2021

The above bug also affects hadoop-lakefs when the lakefs api endpoint is configured currently.
Example: https://prod.lakefs.dev/api/v/
No handler registered to handle this call and it falls to the default, which is UI handler that returns html with 2xx.

@DataDavD
Copy link
Contributor

DataDavD commented Jul 9, 2021

Hey @nopcoder I haven't dug into the code specifics yet but I am hoping to take this up if that is fine, ok? Thanks in advance!

Best,
David D

@nopcoder
Copy link
Contributor Author

nopcoder commented Jul 9, 2021

sure, thanks!

@nopcoder
Copy link
Contributor Author

nopcoder commented Jul 9, 2021

@DataDavD let me know if you have any questions or need help in this one.

@DataDavD
Copy link
Contributor

DataDavD commented Jul 9, 2021

Ok great, thank you @nopcoder. I'll take a close look this weekend and return with any questions I'll probably have.

Thanks again!!!!
David

@DataDavD
Copy link
Contributor

hey @nopcoder just wanted to give you an update. I was able to take a look at the code and believe I understand the specific issue at hand. I intend to look much more closely tomorrow or the following day now that I pinpointed the code at issue; I will most likely send you some clarifying questions then.

Thank you,
dd

@nopcoder
Copy link
Contributor Author

nopcoder commented Jul 13, 2021

Thanks for the updates @DataDavD , here for anything that will help you get this one moving.

@DataDavD
Copy link
Contributor

hey @nopcoder I am assuming the issue is centered around this line of code. I've been having a little trouble reading through the code because a number of objects/types like HandlerFromMuxWithBaseURL show as unresolved refs and I believe are causing my make build to fail with error error generating code: error generating Go handlers for Paths: error generating inlined spec: template: inline.tmpl:5:8: executing "inline.tmpl" at <.>: range can't iterate over . Do you know what the issue is or does this even prevent correcting it, or is just an annoyance for now?

Also to clarify, for any route past /api/v1 return json 401 error instead of UIHandler, correct?

@nopcoder
Copy link
Contributor Author

Hi @DataDavD, make build should run go generate and fill the missing parts - the specific one is lakefs.gen.go which includes the openapi generated code.
Verify that you have Go 1.16 and try to run go generate command found in serve.go - maybe it will have more information about the source of the error.

The main issue is any route under /api/v1 (ex: /avi/v1/unknown) will continue to fall to the UI handler and serve the UI html with status code 200.
We would like to return the default error with 500 with writeError so the caller will identify there is an issue.

@DataDavD
Copy link
Contributor

Ahh ok that makes sense; maybe my issue was maybe go 1.15 related, not totally sure though.

Thanks for confirming the issue; I thought that was it but want to verify before I start writing code to handle that. Thank you!!!!

@DataDavD
Copy link
Contributor

hey @nopcoder took another look/try and still getting the same error for some reason. I'll try and dig in more tomorrow, but in meantime here is the full error

For some reason it freaks out over the swaggerSpec in inline.tmpl. I'll look into why it could be doing this tomorrow as I'm still a bit green with regards to how oapi-codegen is generating the code specifically.

full error:
error generating code: error generating Go handlers for Paths: error generating inlined spec: templateinline.tmpl:5:8: executing "inline.tmpl" at <.>: range can't iterate over {[H4sIAAAAAAAC/+x9eXPbOLL4V0Hxt1W/ZEu27CRv5q23tl5lnGO8k8PlY2e3xnkqiGxSGJMABwBtazz6 7q9w8BJBUkp0WB7/lVjE0ehudDca3eh7z2dJyihQKbyjey/FHCcggeu/TnFEKJaE0dehBK5+CkD4nKTq N+/I4yAzThGRkAiEVRskJ0SgGxxn4A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VDn99b/b fNX1AkdrksUXONpemaKwhWuennjteN1Kal6YY81+0TS8lzha4FHXnNX6YrPV5n4sj/E4Udr+jqsTRQcb 2xc7dLhqQeyGr7BkIT2XOKcIkFk6ivG10v3qvNGWYJGl60qO1WMvHkq3mtvVsqT+z0ROzsHn4FTuupay DTpyCIANXPeMcYB4nqq2WgO5dU7NFegWC4RjDjiYIh/H3/rgTr0uZyVRTE9mC5ZiGpRFE0PCbTlrr6US qf7WlQxrEsLdBYZXyE6VaVqYyHUTbrPVW2r/1lF27/16K0c6V14hUMmAMRbEH+nm9hefsWsC5U8Kz5oK riKVtWq2CGiQMqKv/TIee0feEKdkeHPozb7M/i8AAP//8GNnXeXpAAA=] map[]} serve.go:3: running "oapi-codegen": exit status 1

@nopcoder
Copy link
Contributor Author

nopcoder commented Jul 21, 2021

@DataDavD looks from the output that you get a newer version of the oapi-codegen.
As part of the root project we got 'tools.go' that reference the oapi-codegen in order to lock the specific version. (we use v1.5.6)
Verify that you didn't go get -u by checking if your go.mod and go.sum are unmodified.
Running make gen on the root project should try to install the specifc versions and generate the code.
I'll check what changed in the oapi-codegen and maybe it is time to update and update the templates.

@nopcoder nopcoder changed the title API with unkown path should return an error API with unknown path should return an error Jul 22, 2021
@nopcoder
Copy link
Contributor Author

@DataDavD any luck build the generated code with the specific oapi-codegen library?

@DataDavD
Copy link
Contributor

hey @nopcoder sorry for the delayed response. Was very busy over weekend so didn't get to touch/look at the code, but I should tonight. I'll let ya know how it goes.

Thanks again for helping me debug!

@DataDavD
Copy link
Contributor

Hey @nopcoder, I feel dumb as I realized for some reason my Go version tried to update the oapi-codegen library when I must have done a run a bit ago. Your suggested fixed the issue and now everything appears fine.

I will start working on this issue now that I'm in a non-buggy state in my local repo.

I can't thank you enough for being patient and very helpful. Thanks again for allowing me to contribute.

best,
dd

@nopcoder
Copy link
Contributor Author

nopcoder commented Aug 7, 2021

Hi dd, did you had any progress with this issue? would like to have this bug fix for the next release if possible. Will it be possible to frame it for the following week or two?

@DataDavD
Copy link
Contributor

hey @nopcoder sorry for the delayed response. I thought I had messaged you prior about being out of town last week. I actually just got back in so I should be able to get this complete or at least a good place within the next week or two. If I have any further issues or think that it won't be doable by EOD Wednesday I'll let ya know and seek your guidance.

Thanks again for your help; and sorry for the delay.

best,
dd

@nopcoder
Copy link
Contributor Author

Appreciate it, thank you! I can post a test code that will break that you can use if it will help.

@DataDavD
Copy link
Contributor

Yea sure anything will help. Currently, I have something of the sorts, but I'm not too sure the specific place to put it although I believe it should be placed in api.NewHandlerWithDefault
if r.URL.Path != BaseURL + "/" { writeError(w, http.StatusInternalServerError, err) return }

@DataDavD
Copy link
Contributor

hey @nopcoder I was wondering if you saw my last message. I'm still having a little trouble, but am hoping/wanting to finish this before the end of the weekend although I'm a bit unsure of myself, so if this is holding y'all up please tell me as I don't want to do that. In the meantime I will carry on trying to get something working, properly.

Thank you.

Best,
dd

@nopcoder
Copy link
Contributor Author

@DataDavD yea, I missed your previous message - sorry about that.
When we set up the routes we have the API's base URL - if you register a handler on that point it will handle all the calls that are not handled by the registered handlers of the open-api. So without any 'if' it will handle this specific case.

Regarding test code - hope this one helps:

// part of serve_test.go

func TestInvalidRoute(t *testing.T) {
	handler, _ := setupHandler(t, "")
	server := setupServer(t, handler)
	clt := setupClientByEndpoint(t, server.URL, "", "")
	cred := createDefaultAdminUser(t, clt)

	// setup client with invalid endpoint base url
	basicAuthProvider, err := securityprovider.NewSecurityProviderBasicAuth(cred.AccessKeyID, cred.SecretAccessKey)
	if err != nil {
		t.Fatal("basic auth security provider", err)
	}
	clt, err = api.NewClientWithResponses(server.URL+api.BaseURL+"//", api.WithRequestEditorFn(basicAuthProvider.Intercept))
	if err != nil {
		t.Fatal("failed to create api client:", err)
	}

	ctx := context.Background()
	resp, err := clt.ListRepositoriesWithResponse(ctx, &api.ListRepositoriesParams{})
	if err != nil {
		t.Fatalf("failed to get lakefs server version")
	}
	if resp.JSONDefault == nil {
		t.Fatalf("client api call expected default error, got nil")
	}
	expectedErrMsg := api.ErrInvalidAPIEndpoint.Error()
	errMsg := resp.JSONDefault.Message
	if errMsg != expectedErrMsg {
		t.Fatalf("client response error message: %s, expected: %s", errMsg, expectedErrMsg)
	}
}

// part of serve.go

var ErrInvalidAPIEndpoint = errors.New("invalid API endpoint")

@DataDavD
Copy link
Contributor

Thank you for the info and help @nopcoder !!! I'll try and get this finalized tonight/tomorrow. If I still don't have something PR ready I'll hold off to avoid delaying this getting in the next release.

Thanks again!!

dd

@DataDavD
Copy link
Contributor

DataDavD commented Aug 16, 2021

Hey @nopcoder I believe I have (at least close to) what is required for the issue fix, but for some reason I have 2 tests failing. One f the failed tests is TestInvalidRoute you provided me but it is not failing on the specific part that tests the code I added; it is failing on the api client call (i.e. the code section with if resp.JSONDefault == nil), and for more details the second failed tests is the TestLocalLoad. Am I forgetting to set some auth configs or something?

Last, here is my existing code for this issue fix DataDavD@dfc3b78

@DataDavD
Copy link
Contributor

@nopcoder FYI I submitted a PR (#2382). The tests passed, but I still had one test, TestLocalLoad that still wouldn't pass for some reason. However, I created the PR so we have a good place to review and maybe can also discuss why I'm getting an issue with that particular "local" test.

Thank you for your patience on this and letting me contribute.

Best,
dd

@nopcoder
Copy link
Contributor Author

@DataDavD thanks! looking into the PR and I'll add my comments there.
Regarding the failed test - I wanted the error format to match our current default error format, so when the invalid API route fails, all the clients that use the same definition will parse an error as described in the swagger.

DataDavD added a commit to DataDavD/lakeFS that referenced this issue Aug 19, 2021
This commit works to close issue treeverse#2190 by creating handler that returns
ErrInvalidAPIEndpoint when called. This will be used by chi Mount'ing
the handler to a specified route so that any calls to a route downstream
the Mount'd pattern will respond with the ErrInvalidAPIEndpoint error.

Also add corresponding test, TestInvalidRoute, to test
InvalidAPIEndpointHandler.

Create middleware to catch downstream routes from BaseURL

This commit works to close issue treeverse#2190 by creating middleware to ensure
users that call routes downstream of the BaseURL (i.e. /api/v1) are
return an invalid endpoint error and internal error status.

Remove BaseURLHandler
@nopcoder nopcoder linked a pull request Aug 20, 2021 that will close this issue
@guy-har guy-har changed the title API with unknown path should return an error API with an unknown path should return an error Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants