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

[265] Add file upload to allow mocking of file operations #266

Merged
merged 17 commits into from
Apr 11, 2019

Conversation

JackCreativeCrew
Copy link
Contributor

I've added endpoints for file upload/download/deletion (PUT/GET/DELETE) to allow for testing using files. The code is pretty basic but fulfills my requirements at the moment and has test coverage of happy paths.

@JackCreativeCrew JackCreativeCrew mentioned this pull request Apr 8, 2019
@codecov
Copy link

codecov bot commented Apr 8, 2019

Codecov Report

Merging #266 into master will increase coverage by 0.23%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #266      +/-   ##
==========================================
+ Coverage   90.22%   90.45%   +0.23%     
==========================================
  Files         104      105       +1     
  Lines        5380     5500     +120     
==========================================
+ Hits         4854     4975     +121     
+ Misses        526      525       -1
Impacted Files Coverage Δ
src/WireMock.Net/Server/FluentMockServer.Admin.cs 86.7% <100%> (+0.13%) ⬆️
src/WireMock.Net/Serialization/MappingConverter.cs 100% <100%> (ø) ⬆️
src/WireMock.Net/ResponseMessageBuilder.cs 100% <100%> (ø) ⬆️
...WireMock.Net/Server/FluentMockServer.AdminFiles.cs 100% <100%> (ø)
...rc/WireMock.Net/Handlers/LocalFileSystemHandler.cs 100% <100%> (ø) ⬆️
src/WireMock.Net/RequestMessage.cs 97.97% <0%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c32b9c...90d0efb. Read the comment docs.

@StefH
Copy link
Collaborator

StefH commented Apr 8, 2019

Thanks for this idea + implementation.

I'll refactor the code in this branch to match the solution logic.

@StefH
Copy link
Collaborator

StefH commented Apr 8, 2019

@JackCreativeCrew
I did update the code, and also added a PostFile.

@JackCreativeCrew
Copy link
Contributor Author

JackCreativeCrew commented Apr 9, 2019

Yeah thanks, looks good. Mine wasn't using the already provided functions, sorry I only started using this ~3 days ago. The rest of the code looks good though.

The only functional change I'd suggest is returning the path of the created/updated file when put/posting, reason being I'm testing files going through a rest API and I'd like to access them after they've been uploaded etc from another program which would require the path.

EDIT: Also I can't approve this because it's mine but I'm ok to merge if you are.

…gin with, otherwise the file upload fails with 404 (can't find the folder to upload to).
@JackCreativeCrew
Copy link
Contributor Author

Minor change to create the __admin/mapping folder if it doesn't exist otherwise the file upload fails. I'd imagine this is a problem in other places too (scenarios etc)?

@StefH
Copy link
Collaborator

StefH commented Apr 9, 2019

Actually I was just thinking about that scenario.

Also your remark bout returning the path.
--> this does not make sense because I think I will only allow writing files in the __admin/mapping and no not allow sub-folders.
Because withe current code you can use:
POST https://{{wm_hostname}}/__admin/files/x/1.cs which will try to save the file in the __admin/mapping/x folder.
And this fails because the "x" folder does not exists.

And actually, I think this is also a security risk to allow sub-folders or different paths like /../../system32.dll (as an example...)

So I think I will add logic to the code to take the filename only and change path into filename in the interface

@JackCreativeCrew
Copy link
Contributor Author

Yeah, ok, I hadn't considered that.

Something else I've come across, the file is being written as everything in the multipart body which isn't just the file. I've stuffed around trying to get this to write just the file but as yet failed.
I get for instance

----------------------------566196384670995956765212
Content-Disposition: form-data; name=""; filename="pdf_viewer_resources.pak"
Content-Type: application/octet-stream

at the head and


----------------------------566196384670995956765212--

at the tail. At the moment I'm only using one file i.e. that file, is there any way to only write the first piece of content and just chop the rest?

@StefH
Copy link
Collaborator

StefH commented Apr 9, 2019

First I will fix the unit-tests
Second I will think about multipart...

@StefH
Copy link
Collaborator

StefH commented Apr 9, 2019

Second
When I just upload a single file using Postman, only the file-content is uploaded, nothing to see as multipart...

@JackCreativeCrew
Copy link
Contributor Author

I must be doing something wrong on my end then. Thanks for checking that out.

@StefH
Copy link
Collaborator

StefH commented Apr 10, 2019

If you have tested all scenarios in this branch, and are confident that this code is correct, I can merge this PR and create a new NuGet.

@JackCreativeCrew
Copy link
Contributor Author

If you have tested all scenarios in this branch, and are confident that this code is correct, I can merge this PR and create a new NuGet.

I haven't had time today to review/check my stuff against this today sorry. I'll get back to you by the end of tomorrow Sydney time though.

@JackCreativeCrew
Copy link
Contributor Author

Ok I've added a HEAD endpoint as well and a test for both file found and not found. It requires no body as the HEAD request can't have a body so the structure is a bit different. The code is now all working for me and if you accept those changes, I'm ok with merging it.

@StefH
Copy link
Collaborator

StefH commented Apr 11, 2019

Head is a good idea.

I did some small updates on code + tests, and I added this call also to the IFluentMockServerAdmin.cs

Also removed an unused method from "MappingConverter.cs" ?

@JackCreativeCrew
Copy link
Contributor Author

Yeah, I was using that for debugging which admin endpoints were available, must've not gotten deleted before the commit.

@StefH
Copy link
Collaborator

StefH commented Apr 11, 2019

I'll merge to master now.

@StefH StefH merged commit 12444cc into WireMock-Net:master Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants