Skip to content

Conversation

@jjrodrig
Copy link
Contributor

@jjrodrig jjrodrig commented Apr 2, 2019

Overview

This PR solves the problem described at the issue #1988

PUT & POST operations for creating documents in a database enforce different validation rules over the attachment names of the new document.

When a document is created with a PUT operation "_foo.txt" is not accepted as a valid attachment name. If the document is created by a POST operation the "_foo.txt" attachment name is accepted.

This is an inconsistent behavoiur in the API as not accepted attachment names can be created.

Testing recommendations

make elixir tests=test/attachment_names_test.exs

Related Issues or Pull Requests

This PR fixes #1988

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

@jjrodrig jjrodrig changed the title Fix apache/couchdb#1988 - Validate attachment names at POST /db/doc and GET /db/doc/attachment Fix #1988 - Validate attachment names at POST /db/doc and GET /db/doc/attachment Apr 2, 2019
@wohali
Copy link
Member

wohali commented Mar 13, 2020

Hi @jjrodrig , any desire to get this updated and merged into the 3.x and 3.0.x branches as well?

@jjrodrig
Copy link
Contributor Author

Sure @wohali

As soon this PR is accepted, I'll open PRs to merge into the 3.x and 3.0.x branches

@jjrodrig jjrodrig force-pushed the 1988-fix-attachment-name-validation branch from 81ab659 to b5c4daa Compare March 20, 2020 00:03
@jjrodrig jjrodrig force-pushed the 1988-fix-attachment-name-validation branch from b5c4daa to a69c401 Compare April 2, 2020 18:32
db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNameParts) ->
FileName = list_to_binary(mochiweb_util:join(lists:map(fun binary_to_list/1,
FileNameParts),"/")),
validate_attachment_name(FileName),
Copy link
Member

Choose a reason for hiding this comment

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

why validate on GET?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be consistent in the API response and return 400 when the attachment name is not valid.
We can remove the validation and just return 404

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rnewson Do you think that we should return 404 and not 400 when a not allowed attachment name is requested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

finally I've removed the attachment name validation on GET

validate_partitioned_db_enabled(Req) ->
case couch_flags:is_enabled(partitioned, Req) of
true ->
true ->
Copy link
Member

Choose a reason for hiding this comment

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

remove whitespace only change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jjrodrig jjrodrig force-pushed the 1988-fix-attachment-name-validation branch 2 times, most recently from 83847fb to 515368b Compare April 4, 2020 16:04
@wohali
Copy link
Member

wohali commented Oct 9, 2020

@jjrodrig @rnewson any plans to get this in? I am preparing to mass-close old PRs that never got merged.

@jjrodrig
Copy link
Contributor Author

@wohali I'll update this and move it to main

@jjrodrig jjrodrig force-pushed the 1988-fix-attachment-name-validation branch from ceea9bf to 2711564 Compare October 13, 2020 15:57
@jjrodrig jjrodrig changed the base branch from master to main October 13, 2020 17:54
@jjrodrig jjrodrig changed the base branch from main to master October 13, 2020 17:54
@jjrodrig jjrodrig changed the title Fix #1988 - Validate attachment names at POST /db/doc and GET /db/doc/attachment Fix #1988 - Validate attachment names at POST /db/doc Oct 13, 2020
@jjrodrig jjrodrig changed the title Fix #1988 - Validate attachment names at POST /db/doc Fix #1988 - Validate attachment names on POST /db/doc Oct 13, 2020
@jjrodrig jjrodrig changed the base branch from master to main October 14, 2020 22:40
@jjrodrig jjrodrig force-pushed the 1988-fix-attachment-name-validation branch from 2711564 to 2bf4f41 Compare October 14, 2020 22:41
@jjrodrig jjrodrig requested a review from rnewson October 15, 2020 07:15
Copy link
Member

@rnewson rnewson left a comment

Choose a reason for hiding this comment

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

lgtm

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.

Attachments operations PUT /db/doc & POST /db perform inconsistent attachment name validation

4 participants