-
Notifications
You must be signed in to change notification settings - Fork 22
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
[HELP]: questions in desc #148
base: main
Are you sure you want to change the base?
Conversation
mockMode does not work on redirected paths - 1. I needed paths to be redirected before requests are checked, so I took the functionality out of callApi() and put it on lines 143-144 in `handle_request.go`. This does not seem like good code, but I dont know if this breaks anything or not since there's no tests :(. But hey, it works and the tests pass. Is this ok? 2. For some reason, auth is dropped from the original header in my request when it comes FROM THE BROWSER - MockMode works when curling the endpoint with authentication added as headers, but when the request comes from the browser, it fails. So on line 145 in `handle_request.go` I added the header back, but this seems like a hack. Am I missing something? What am I missing? I cannot tell since there are no tests :( 3. Wiretap really needs tests. I really want to write a test like in `wireap_service_test.go`, but I just dont know how to get it to work. Any pointers? (this test is commented out to show you that my changes to wiretap in 1.,2., work)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR needs to broken down, I really don't know why the UI has been modified.
Can you remove the UI code? I am planning on stripping out 99% of the UI from wiretap and moving it to another repo - if you want to add UI changes, please do so in another PR so it's a composed set of PRs that build on top of each other.
Also, I don't think you have used gofmt
as there are a bunch of whitespace changes.
|
||
// create a new request from the original request, but replace the path | ||
wiretapConfig := configStore.(*shared.WiretapConfiguration) | ||
func (ws *WiretapService) rewritingPath(req *http.Request, wiretapConfig *shared.WiretapConfiguration) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename this to rewritingPath
to checkForPathRewrite
@@ -58,6 +59,10 @@ func (ws *WiretapService) handleMockRequest( | |||
} | |||
} | |||
|
|||
const mocked = "this response has been mocked" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a place holder for the future. Eventually I want to return to the UI what was used for mocking (examples, example, schema) and if there is a name, the name as well
@@ -58,6 +59,10 @@ func (ws *WiretapService) handleMockRequest( | |||
} | |||
} | |||
|
|||
const mocked = "this response has been mocked" | |||
request.HttpResponseWriter.Header().Set("wiretap-mock", fmt.Sprintf(mocked)) | |||
header.Add("wiretap-mock", fmt.Sprintf(mocked)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this? why are we adding custom headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted the UI to be able to differentiate between mocked data & non-mocked data. Since this is a 'simulated response to send up to the monitor UI, I thought that I could simply add wiretap specific data to the header
ws.config.Logger.Info("MockMode enabled; skipping validation") | ||
ws.rewritingPath(request.HttpRequest, config) | ||
ws.rewritingPath(newReq, config) | ||
request.HttpRequest.Header.Set("Authorization", apiRequest.Header.Get("Authorization")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong place to do this. I think there is something missing during the request cloning process https://github.com/pb33f/wiretap/blob/main/daemon/clone_request.go
Every request is cloned before being parsed because you can only ready the body once, therefore to allow the chain to continue, each time you read the body, you need to replace it with a fresh stream, because its dead.
I investigate what the browser is sending first and then try to fix this, because if the header is being set correctly via a cURL command, but failing with the browser - there is a failure to parse the header the browser is sending..
Start there, because this is a hack and we can't do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the advice, thats what I thought
@@ -0,0 +1,122 @@ | |||
package daemon | |||
|
|||
// this test does not work. I have no idea how to test the platform. It will take a decent amount of work to dig deep. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to test the platform, you need to test the logic, all can be mocked using the standard library.
mockedhttps://www.cloudbees.com/blog/testing-http-handlers-go
// https://swagger.io/docs/specification/v3_0/data-models/oneof-anyof-allof-not/ | ||
// anyOf, oneOf, allOf, not | ||
// only supports v3 model, f the rest LOL | ||
func (rme *ResponseMockEngine) GetSchemaCombination(mediaType *v3.MediaType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this is, delete please unless we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so sorry. I did not mean for you to review the MR. This function was not finished. I only inteded for help.
The mockGenerator does not support anyOf, oneOf, allOf, not. I was going to implement it. The use case is that there exists different shapes of data that are returned from a singular endpoint (bad api design)
Why does it seem like bad code? All you did was shift logic around a little? The code is the same from what I can tell, you just moved things around a little?
I left a comment about this, I would investigate the request cloning process first and check out exactly what is going on with the browser sending headers that cannot be parsed, because if a cURL command works, but a browser request does not - then there is a major issue with parsing the header correctly, - because the logic is working.
I think you need to take a step back and learn about http mock testing in go. You don't need to run the whole platform, you just need to use the standard library for testing HTTP, it's got a rich set of APIs for this. https://github.com/pb33f/wiretap/blob/main/mock/mock_engine_test.go There are limited tests in wiretap because the vast majority of logic lives outside this tool, it lives
I would really like to discuss the UI work first it, I am extremely fussy in this area :), it should come in as another PR.
|
Hey, sorry! I forgot to mark this as a DRAFT mr. My intentions were to ask for help - code is not ready which is why the code looks like shit. Sorry about that 🙏 |
I am rewriting the path only for mockMode. I feel like we should only have to rewrite a path once for all of the cases.
Thank you, that makes sense. Will take a step back 🙏
100% will put them in another PR. I do have several more changes - 2 new services planned. I'll propose them in issues. |
mockMode does not work on redirected paths -
handle_request.go
. This does not seem like good code, but I don't know if this breaks anything or not since there's no tests :(. But hey, it works and the tests pass. Is this ok?handle_request.go
I added the header back and it works but this seems like a hack. Am I missing something? What am I missing? I cannot tell since there are no tests :(wireap_service_test.go
, but I just dont know how to get it to work(this test is commented out to show you that my changes to wiretap in 1.,2., work). Can you help me formulate the best testing strategy moving forward? What do I need to learn? I am seriously willing to beef wiretap tf up. It's going to need it after my planned changes (which I havent mentioned yet)PS: extra changes which dont need review yet but I will describe them if you are curious-
