Skip to content

Check if db exists in /db/_ensure_full_commit call#1588

Merged
eiri merged 1 commit intoapache:masterfrom
cloudant:fix/ensure_full_commit-database-check
Aug 30, 2018
Merged

Check if db exists in /db/_ensure_full_commit call#1588
eiri merged 1 commit intoapache:masterfrom
cloudant:fix/ensure_full_commit-database-check

Conversation

@eiri
Copy link
Copy Markdown
Member

@eiri eiri commented Aug 29, 2018

Overview

We removed a security call in do_db_req in #1246 to avoid duplicate authorization check and as a result there are now no db validation in noop call /db/_ensure_full_commit. This makes it always return a success code, even for the missing databases.

This fix places the security check directly in _ensure_full_commit call and adds eunit tests for a good measure.

Testing recommendations

make eunit apps=chttpd suites=chttpd_db_test for isolated tests

Related Issues or Pull Requests

Closes #1585

Checklist

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

db_req(#httpd{method='POST', path_parts=[DbName, <<"_ensure_full_commit">>],
user_ctx=Ctx}=Req, _Db) ->
chttpd:validate_ctype(Req, "application/json"),
fabric:get_security(DbName, [{user_ctx, Ctx}]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there is a need for a comment here to describe why the call is needed and the reason for fabric:get_security/2 to be used for database existence check (get_security uses local shards while fabric:get_db_info for example uses non local shards as well)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm using get_security here because 1) it is what old code was using 2) get security calls fabric_util:get_db that actually does open remote shards, but gives priority to local ones, so it allows to avoid round-trip when possible 3) it presumably also confirms user to be reader, that what old code was saying, but I don't see it in fabric, tbh.

I can drop a comment here or I can switch to fabric:get_db_info if you think that'd be less subtle.

@eiri
Copy link
Copy Markdown
Member Author

eiri commented Aug 29, 2018

@iilyak ok, updated with the comment. does it look sufficient for you?

Copy link
Copy Markdown
Contributor

@iilyak iilyak left a comment

Choose a reason for hiding this comment

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

+1

@eiri eiri force-pushed the fix/ensure_full_commit-database-check branch from 0db097b to 171d135 Compare August 30, 2018 12:11
We removed a security call in `do_db_req` to avoid
a duplicate authorization check and as a result
there are now no db validation in noop call
`/db/_ensure_full_commit`. This makes it always
return a success code, even for missing databases.

This fix places the security check directly
in _ensure_full_commit call and adds eunit tests
for a good measure.
@eiri eiri force-pushed the fix/ensure_full_commit-database-check branch from 171d135 to 5c0548e Compare August 30, 2018 12:13
@eiri eiri merged commit b2b6988 into apache:master Aug 30, 2018
@eiri eiri deleted the fix/ensure_full_commit-database-check branch August 30, 2018 12:40
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.

/_{db}/_ensure_full_commit returns success for non-existent databases

2 participants