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

Bug/2763 bug fix not refactor #2821

Merged
merged 13 commits into from
Jan 18, 2017
Merged

Bug/2763 bug fix not refactor #2821

merged 13 commits into from
Jan 18, 2017

Conversation

kzangeli
Copy link
Member

@kzangeli kzangeli commented Jan 17, 2017

Three fixes:

@kzangeli kzangeli added this to the 1.7.0 milestone Jan 17, 2017
@crbrox
Copy link
Member

crbrox commented Jan 17, 2017

LGTM

@@ -15,6 +15,9 @@
- Fix: bug when tenants are over 44 bytes long (#2811)
- Add: Support for null values in string filters (#2359)
- Fix: Partial sanity check for custon url, only if the url contains no replacements using ${xxx} (#2280, #2279)
- Fix: if entity::type is given but as an empty string, an error is returned (#1985)
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to explain in which operations this fix has been done. Maybe this?

"Fix: if subject.entities*.type is given but as an empty string in POST /v2/subscriptions or PATCH /v2/subscriptions/{sub} , an error is returned (#1985)"

Copy link
Member Author

Choose a reason for hiding this comment

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

The checks are done in low level functions, parseEntity() and parseEntityObject(). Should be valid for all V2 requests that have entites, including GET /v2/entities and probably more ops.

Do you still want a list of all the ops in CNR ?

Copy link
Member

Choose a reason for hiding this comment

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

So you mean that before this PR entity creation with "type": "" was failing? A bit surprissing... I think we already have .test in place that check min and max length for all id-kind fields (entity id/type, attr name/type, md name/type)...

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my understanding, I may be wrong.
In the json parse stage (parseEntity() and parseEntityObject()), there were no checks for empty 'type'. Perhaps there are checks that cover part of the request set somewhere else ... ?

Copy link
Member Author

Choose a reason for hiding this comment

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

So, from what I've seen now, it seems all cases (except for /v2/subscriptions) of empty entity::type were caught already. just as @fgalan predicted :-), changing the CNR line

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in a93291f

@@ -15,6 +15,9 @@
- Fix: bug when tenants are over 44 bytes long (#2811)
- Add: Support for null values in string filters (#2359)
- Fix: Partial sanity check for custon url, only if the url contains no replacements using ${xxx} (#2280, #2279)
- Fix: if entity::type is given but as an empty string, an error is returned (#1985)
- Fix: admin requests with errors now return '400 Bad Request', not '200 OK'
Copy link
Member

Choose a reason for hiding this comment

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

"adming request" could be a big obscure, and example would help. I mean:

"Fix: admin requests (e.g. GET /version) with errors now return '400 Bad Request', not '200 OK'"

Btw, issue number is missing at the end of the line. If the fix is not related with any issue, that's perfect (asking only to check if that is the case...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, an example may make it easier to understand.
No, no issue here, as far as I know, see PR description:

admin requests with errors now return '400 Bad Request', not '200 OK' (no issue, I think)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 8fa9c69

@@ -109,7 +109,7 @@ std::string OrionError::smartRender(ApiVersion apiVersion)
*/
std::string OrionError::setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP)
{
if (apiVersion == V2)
if ((apiVersion == V2) || (apiVersion == ADMIN_API))
Copy link
Member

Choose a reason for hiding this comment

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

Great to see that the addition has not broken anything... setStatusCodeAndSmartRender() modifyication were hard in the past (at least to me...)

NTC

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I am not so sure. Seeing a few really strange errors in functests ...

Copy link
Member Author

@kzangeli kzangeli Jan 18, 2017

Choose a reason for hiding this comment

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

Errors under control again, fixed in f422157 (this line is intact, the problem was elsewhere)


echo "02. Make sure the entity doesn't exist in the database"
echo "======================================================"
echo "db.entities.findOne()" | mongo ftest
Copy link
Member

Choose a reason for hiding this comment

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

Why don't use the GET /v2/entities operation to check it? We should use keep direct mongo queries only as last resort measure when the API doesn't provide alternatives.

(Btw, I think we have a mongoCmd() function for test harness to avoid direct calls to mongo shell)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, GET /v2/entities works also. As we usually do. Not sure why I implemented like this (paranoia perhaps)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 159bd5f

@@ -0,0 +1,56 @@
# Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U
Copy link
Member

Choose a reason for hiding this comment

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

Looking again, I don't see the .test covering #1985.... Maybe you missed git add before commit? ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find one. I have created the directory but there is no functest inside ...
Also can't find any modified functest for this ...

Must check this, understand what's happened here.

Copy link
Member Author

@kzangeli kzangeli Jan 18, 2017

Choose a reason for hiding this comment

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

There wasn't any, and the problem wasn't even fixed.
I just assumed (and forgot about the functest), that the low level parse functions would take care of this (as they should). However subscriptions use their own implementation of entity parsing ...

Fixed in f422157

alarmMgr.badInput(clientIp, "invalid JSON type for entity id");
ciP->httpStatusCode = SccBadRequest;;
OrionError oe(SccBadRequest, "invalid JSON type for entity id", "BadRequest");
const char* errorText = "Invalid JSON type for entity id";
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bc960d4

alarmMgr.badInput(clientIp, "'id' is not a valid attribute");
ciP->httpStatusCode = SccBadRequest;;
OrionError oe(SccBadRequest, "invalid input, 'id' as attribute", "BadRequest");
const char* errorText = "invalid input, 'id' as attribute";
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h

return oe.toJson();
}
}
else if (name == "type")
{
if (type != "String")
{
alarmMgr.badInput(clientIp, "invalid JSON type for entity type");
const char* errorText = "Invalid JSON type for entity type";
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bc960d4


if (eP->type.empty())
{
const char* errorText = "entity type length: 0, min length supported: 1";
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h (in fact, I think the text is already there in a previous define)

{
return "Invalid characters in entity type";
return "entity type length: 0, min length supported: 1";
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h

@@ -384,6 +384,10 @@ static std::string parseEntitiesVector(ConnectionInfo* ciP, std::vector<EntID>*
{
return badInput(ciP, "max type length exceeded");
}
if (typeOpt.value.empty())
{
return badInput(ciP, "entity type length: 0, min length supported: 1");
Copy link
Member

Choose a reason for hiding this comment

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

Move to errorMessages.h

--SHELL--

#
# 01. Attempt to create a subscription with an empty entity type, see error
Copy link
Member

Choose a reason for hiding this comment

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

To make this complet and align with

"Fix: if entity::type is given but as an empty string, in payload of POST /v2/subscriptions or PATCH /v2/subscriptions/{sub}, an error is returned (#1985)"

I'd suggest to add

  1. Successfull creation of a subscription
  2. Attemp to update the existing subscription with an empty entity type, see error

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bc960d4

@fgalan
Copy link
Member

fgalan commented Jan 18, 2017

LGTM

@fgalan fgalan merged commit 6427083 into master Jan 18, 2017
@fgalan fgalan deleted the bug/2763_bug_fix_not_refactor branch January 18, 2017 18:06
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.

3 participants