telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 264 forks source link

in POST v2/subscriptions if expires has invalid date the subscription is created #2303

Closed iariasleon closed 1 week ago

iariasleon commented 8 years ago

in POST v2/subscriptions if expires has invalid date the subscription is created

dataset

      | expires                  |
      |--------------------------|
      | 2016-04-05T14:10:0x.00Z  |
      | 2016-04-05T14:10:00,00Z  |
      | 2016-04-05T14:10:00.h00Z |
      | 2016-04-05T14:10:00.0h0Z |
      | 2016-04-05T14:10:00.,00L |

subscription request

url: POST http://localhost:1026/v2/subscriptions
headers:
    Content-Type: application/json
    Fiware-Service: test_csub_expires
    Fiware-ServicePath: /test
payload: {"notification": {"http": {"url": "http://localhost:1234"}, "attrs": ["temperature"]}, "expires": "2016-04-05T14:10:00.,00L", "description": "my first subscription", "subject": {"entities": [{"idPattern": ".*", "type": "room"}], "condition": {"attrs": ["temperature_0", "temperature_1", "temperature_2"]}}}

subscription response

http code: 201 - Created
headers:
   date: Fri, 17 Jun 2016 14:09:55 GMT
   fiware-correlator: 2aba5c08-3495-11e6-9bff-005056a20feb
   connection: Keep-Alive
   content-length: 0
   location: /v2/subscriptions/576404b337f587249daaba45
payload:

expected response

http code: 400 - Bad Request
payload: {"error":"BadRequest","description":"expires has an invalid format"}
iariasleon commented 8 years ago

Re-tested in CB version and it issue still fails, it returns 201-Created

  "version" : "1.2.0-next",
  "git_hash" : "d81dcf28e71d8d63dc0929ef7a6b73d7db47421b"
kzangeli commented 7 years ago

I looked into this issue a little and found the following solution (detecting trailing garbage in the date string):

p = strptime(s.c_str(), " %Y-%m-%dT%T", &tm);
if (p == NULL)
{
  return -1;
}
else if (*p != 0)  // trailing garbage
{
  return -1;
}

This fix (the addition is the else part) works just fine, however, in many many of our functests we use dates with the following format:

2016-04-05T14:10:00:00.00Z

The fix receives .00Z as trailing garbage and the functest fails. Many many functests.

Now, what do we do with this? Change all functests? Accept .00Z as 'good garbage' :-) ?

fgalan commented 7 years ago

I haven read in deep last comment, sorry... My only concern here if is changing the way we deal with dates could break (or "make it worse" if already broken :) our support to ISO8601

fgalan commented 7 years ago

Take into account that rencelty (1.6.0, Nov 2016) we implemented the following functionality:

  • Add: support ISO8601 timezones at DateTime attributes and metadata creation/update time and filters (#2632)
  • Add: support for partial representation format at DateTime attributes and metadata creation/update and filters (#2631)

Take that into account (in particular, the PRs linked from these issues) in order to fix this issue.

In addition, the issue https://github.com/telefonicaid/fiware-orion/issues/2718 seems to be very related with this.

kzangeli commented 7 years ago

This issue seems to have been fixed. Functest added in PR #2814

iariasleon commented 7 years ago

Re-tested with:

"version" : "1.6.0-next",
  "git_hash" : "4bbe1edfcc8a5cbd3a91bc05a07d6671d089f2f2"

And all cases are OK, except the first case in the dataset:

url: POST http://localhost:1026/v2/subscriptions
headers:
    Content-Type: application/json
    Fiware-Service: test_csub_expires
    Fiware-ServicePath: /test
payload: {"notification": {"http": {"url": "http://localhost:1234"}, "attrs": ["temperature"]}, "expires": "2016-04-05T14:10:0x.00Z", "description": "my first subscription", "subject": {"entities": [{"idPattern": ".*", "type": "room"}], "condition": {"attrs": ["temperature_0", "temperature_1", "temperature_2"]}}}

 ----------------- Response ---------------------------------
http code: 201 - Created
headers:
   Connection: Keep-Alive
   Content-Length: 0
   Location: /v2/subscriptions/587c9b59c3373ce3dfe91fe3
   Fiware-Correlator: 922c8e3e-dbd3-11e6-9fd2-005056a20feb
   Date: Mon, 16 Jan 2017 10:07:21 GMT
payload:
fgalan commented 7 years ago

(As the issue is still open, then it seems I incorrectly put it in the 1.6.0 milestone. Moved back to NGSIv2SubscriptionValidation milestone)

fgalan commented 7 years ago

Related to https://github.com/telefonicaid/fiware-orion/issues/2718

fgalan commented 7 years ago

(feedback required from @fgalan)

ArqamFarooqui110719 commented 3 months ago

I think this issue also can be closed. similar to issue #4541 @fgalan what is your opinion.

fgalan commented 3 months ago

@ArqamFarooqui110719 maybe you could do a PR including a .test covering the cases:

      | expires                  |
      |--------------------------|
      | 2016-04-05T14:10:0x.00Z  |
      | 2016-04-05T14:10:00,00Z  |
      | 2016-04-05T14:10:00.h00Z |
      | 2016-04-05T14:10:00.0h0Z |
      | 2016-04-05T14:10:00.,00L |

That way we strengthen our test base and check that issue is actually solved.

fgalan commented 1 week ago

Fixed by PR https://github.com/telefonicaid/fiware-orion/pull/4584