telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
59 stars 84 forks source link

Service header inconsistently case sensitive #1528

Closed fbuedding closed 2 weeks ago

fbuedding commented 7 months ago

IoT Agent Node Lib version the issue has been seen with

3.3.0

Bound or port used (API interaction)

Northbound (Provision API and NGSI Interactions)

NGSI version

NGSIv2

Are you running a container?

Yes, I am using a contaner (Docker, Kubernetes...)

Image type

normal

Expected behaviour you didn't see

That the fiwareservice header (or better everthing) is consistently case-sensitive or case-insensitive.

Unexpected behaviour you saw

When creating a service group with the header:

fiwareservice: Test fiware-servicepath: /Test

a service group is created as follows

{
  "service": "test",
  "subservice": "/Test",
}

Now you can use this header

fiwareservice: Test fiware-servicepath: /Test

To list and read the create service group, but not to delete or update the service group.

Steps to reproduce the problem

curl --location 'http://localhost:4061/iot/services' \
--header 'fiware-service: Test' \
--header 'fiware-servicepath: /Test' \
--header 'Content-Type: application/json' \
--data '{
    "services": [
        {
            "apikey": "5a7ba897-61a6-43de-94b4-e0d91b261870",
            "cbroker": "http://orion:1026",
            "entity_type": "House",
            "resource": "",
            "type": "House",
            "autoprovision": "true"
        }
    ]
}'

curl --location 'http://localhost:4061/iot/services' \
--header 'fiware-service: Test' \
--header 'fiware-servicepath: /Test' \
--data ''

Response:

{
    "count": 1,
    "services": [
        {
            "commands": [],
            "lazy": [],
            "attributes": [],
            "_id": "6555fb29563294ae401de5e4",
            "resource": "",
            "apikey": "5a7ba897-61a6-43de-94b4-e0d91b261870",
            "service": "test",
            "subservice": "/Test",
            "autoprovision": true,
            "__v": 0,
            "static_attributes": [],
            "internal_attributes": [],
            "entity_type": "House"
        }
    ]
}
curl --location --request DELETE 'http://localhost:4061/iot/services/?resource=&apikey=5a7ba897-61a6-43de-94b4-e0d91b261870' \
--header 'fiware-service: Test' \
--header 'fiware-servicepath: /Test' \
--data ''

Response of the last curl:

{
    "name": "MISMATCHED_SERVICE",
    "message": "The declared service didn't match the stored one in the entity"
}

Configs

environment:
    - "IOTA_CB_HOST=orion"
    - "IOTA_CB_PORT=1026"
    - "IOTA_NORTH_PORT=4061"
    - "IOTA_REGISTRY_TYPE=mongodb"
    - "IOTA_MONGO_HOST=mongodb"
    - "IOTA_MONGO_PORT=27017"
    - "IOTA_MONGO_DB=iotagent-ul"
    - "IOTA_PROVIDER_URL=http://iot-agent:4061"
    - "IOTA_AUTOCAST=true"
    - "IOTA_MQTT_HOST=mosquitto"
    - "IOTA_MQTT_PORT=1883"

Log output

time=2023-11-16T11:23:09.829Z | lvl=DEBUG | corr=661f3e7e-7798-4805-9c07-9f996f3955c1 | trans=661f3e7e-7798-4805-9c07-9f996f3955c1 | op=IoTAgentNGSI.GenericMiddlewares | from=n/a | srv=Test | subsrv=/Test | msg=Body:
2023-11-16 12:23:09 
2023-11-16 12:23:09 {
2023-11-16 12:23:09     "defaultEntityNameConjunction": ":"
2023-11-16 12:23:09 }
2023-11-16 12:23:09 
2023-11-16 12:23:09  | comp=IoTAgent
2023-11-16 12:23:09 time=2023-11-16T11:23:09.830Z | lvl=DEBUG | corr=661f3e7e-7798-4805-9c07-9f996f3955c1 | trans=661f3e7e-7798-4805-9c07-9f996f3955c1 | op=IoTAgentNGSI.MongoDBGroupRegister | from=n/a | srv=n/a | subsrv=n/a | msg=Looking for group params ["resource","apikey"] with queryObj {"apikey":"5a7ba897-61a6-43de-94b4-e0d91b261870"} | comp=IoTAgent
2023-11-16 12:23:09 time=2023-11-16T11:23:09.845Z | lvl=DEBUG | corr=1837960c-18c0-4096-b814-3673f25cab12 | trans=1837960c-18c0-4096-b814-3673f25cab12 | op=IoTAgentNGSI.MongoDBGroupRegister | from=n/a | srv=test | subsrv=/Test | msg=Device group data found: {"_id":"6555fb29563294ae401de5e4","resource":"","apikey":"5a7ba897-61a6-43de-94b4-e0d91b261870","type":"House","service":"test","subservice":"/Test","autoprovision":true} | comp=IoTAgent
2023-11-16 12:23:09 time=2023-11-16T11:23:09.845Z | lvl=DEBUG | corr=1837960c-18c0-4096-b814-3673f25cab12 | trans=1837960c-18c0-4096-b814-3673f25cab12 | op=IoTAgentNGSI.GenericMiddlewares | from=n/a | srv=n/a | subsrv=n/a | msg=Error [MISMATCHED_SERVICE] handling request: The declared service didn't match the stored one in the entity | comp=IoTAgent
AlvaroVega commented 7 months ago

The reason is:

https://github.com/telefonicaid/iotagent-node-lib/blob/4528abd8cc58b06f6604cf2e2462830b5b191c3c/lib/model/Group.js#L49

fgalan commented 7 months ago

From https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md#multi-tenancy

Orion Context Broker interprets the tenant name in lowercase, thus, although you can use tenants such as in update MyService it is not advisable, as the notifications related with that tenant will be sent with myservice and, in that sense, it is not coherent the tenant you used in update requests compared with the one that Orion sends in notifications

(a different repository, but the it applies to this one)

Bottom line: it is not advisable to use service names in no-lowercase format.

fbuedding commented 7 months ago

I think having the tenant name in only lowercase is okay and documented.

What I think is unexpected and/or inconsistent, is that you can create and list service groups with no-lowercase tenant names (fiware-service header) but not update or delete with the same tenant name (fiware-service header). Thus leading to unexpected behavior.

But it's also not like a big issue, just thought to share it here :)

Madhu1029 commented 1 month ago

Hi @AlvaroVega ,

I am working on this issue. Please assign this issue to me.

fgalan commented 2 weeks ago

Fixed by PR https://github.com/telefonicaid/iotagent-node-lib/pull/1613

@fbuedding could you pull again telefonicaiot/iotagent-json:latest and confirm it works as expected now, please?

fbuedding commented 6 days ago

Hello @fgalan and sorry for the late response, I'm currently quite busy due my master thesis. I tested it with 'telefonicaiot/iotagent-json:latest' and it's now working as expected.

fgalan commented 4 days ago

@fbuedding thanks for the feedback!