ankraft / ACME-oneM2M-CSE

An open source CSE Middleware for Education.
https://acmecse.net/
BSD 3-Clause "New" or "Revised" License
23 stars 16 forks source link

Error thrown when try to discover resource that use ACP with ty under acod #112

Closed samuelbles07 closed 1 year ago

samuelbles07 commented 1 year ago

Hi,

Currently i try to create ACP with ACOD like sample below

"acod": [
    {
        "ty": 2,
        "chty": [2, 3, 4, 23]
    }
]

As far as i know, in specification ty field is an int, but it throw error when i want to discover the resource that use the ACP.

Traceback (most recent call last):
  File "/ACME-oneM2M-CSE/acme/services/HttpServer.py", line 229, in _handleRequest
    responseResult = CSE.request.handleRequest(dissectResult.request)
  File "/ACME-oneM2M-CSE/acme/services/RequestManager.py", line 144, in handleRequest
    return self.requestHandlers[request.op].ownRequest(request)
  File "/ACME-oneM2M-CSE/acme/services/RequestManager.py", line 183, in retrieveRequest
    return CSE.dispatcher.processRetrieveRequest(request, request.originator)
  File "/ACME-oneM2M-CSE/acme/services/Dispatcher.py", line 198, in processRetrieveRequest
    if not (res := self.discoverResources(id, originator, request.fc, permission = permission)).status: # not found?
  File "/ACME-oneM2M-CSE/acme/services/Dispatcher.py", line 342, in discoverResources
    discoveredResources = self._discoverResources(rootResource,
  File "/ACME-oneM2M-CSE/acme/services/Dispatcher.py", line 398, in _discoverResources
    filterCriteria) and CSE.security.hasAccess(originator, resource, permission):
  File "/ACME-oneM2M-CSE/acme/services/SecurityManager.py", line 272, in hasAccess
    if acp.checkPermission(originator, requestedPermission, ty):
  File "/ACME-oneM2M-CSE/acme/resources/ACP.py", line 183, in checkPermission
    if ty not in eachAcod.get('ty'):
TypeError: argument of type 'int' is not iterable

Then i check https://github.com/ankraft/ACME-oneM2M-CSE/blob/master/acme/resources/ACP.py#L183, that line try to iterate ty value when it suppose to compare. I change that line and now it works fine.

if ty is not None and ty is not eachAcod.get('ty'):
    continue

ACME CSE using release version 0.11.2

ankraft commented 1 year ago

@samuelbles07 Good catch! And thanks a lot for providing a solution. I applied it with a slight modification ( ... and ty != eachAcod.get('ty'):) and added two new test cases. I will release it in a few minutes