ging / fiware-idm

OAuth 2.0-based authentication of users and devices, user profile management, Single Sign-On (SSO) and Identity Federation across multiple administration domains.
https://keyrock-fiware.github.io
MIT License
36 stars 81 forks source link

Sequelize findOrCreate(...).spread is not a function #310

Closed jason-fox closed 1 year ago

jason-fox commented 1 year ago

Can’tpass an Updated Policy Set to Authzforce

Related https://github.com/FIWARE/tutorials.Administrating-XACML/issues/9

Updating an existing XACML role should cause Keyrock to sent an updated Policy set to Authzforce:

curl -X POST \
   http://localhost:3005/v1/applications/tutorial-dckr-site-0000-xpresswebapp/roles/security-role-0000-0000-000000000000/permissions/alrmbell-ring-24hr-xaml-000000000000 \
   -H 'Content-Type: application/json' \
   -H 'X-Auth-token: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'

The actual result is an Internal Error in Keyrock:

2023-01-06T08:19:59.371Z idm:api-role_permission_assignments --> create
TypeError: models.role_permission.findOrCreate(...).spread is not a function
    at exports.create (/opt/fiware-idm/controllers/api/role_permission_assignments.js:80:8)
    at ....

Looking at role_permission_assignments.js, it is assuming that the model is returning an Array - but with Sequelize 6 it returns a Promise<Model, boolean> - the function signature has changed between Sequelize 4 and Sequelize 6

    models.role_permission
      .findOrCreate({
        where: { role_id: req.role.id, permission_id: req.permission.id },
        defaults: { role_id: req.role.id, permission_id: req.permission.id }
      })
      .spread(function (assignment, created) { ...

... so I think that with the update to Sequelize 6 the code needs updating

The .findOrCreate{}.spread() paradigm is used in multiple places in the code base, can you check which functions have not been updated and fix and test them.

sanpago commented 1 year ago

Fixed

Regards Santiago

El 6 ene 2023, a las 10:12, Jason Fox @.***> escribió:

Can’tpass an Updated Policy Set to Authzforce

Related FIWARE/tutorials.Administrating-XACML#9 https://github.com/FIWARE/tutorials.Administrating-XACML/issues/9 Updating an existing XACML role should cause Keyrock to sent an updated Policy set to Authzforce:

curl -X POST \ http://localhost:3005/v1/applications/tutorial-dckr-site-0000-xpresswebapp/roles/security-role-0000-0000-000000000000/permissions/alrmbell-ring-24hr-xaml-000000000000 \ -H 'Content-Type: application/json' \ -H 'X-Auth-token: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' The actual result is an Internal Error in Keyrock:

2023-01-06T08:19:59.371Z idm:api-role_permission_assignments --> create TypeError: models.role_permission.findOrCreate(...).spread is not a function at exports.create (/opt/fiware-idm/controllers/api/role_permission_assignments.js:80:8) at .... Looking at role_permission_assignments.js, it is assuming that the model is returning an Array - but with Sequelize 6 it returns a Promise<Model, boolean> - the function signature has changed between Sequelize 4 and Sequelize 6

models.role_permission
  .findOrCreate({
    where: { role_id: req.role.id, permission_id: req.permission.id },
    defaults: { role_id: req.role.id, permission_id: req.permission.id }
  })
  .spread(function (assignment, created) { ...

... so I think that with the update to Sequelize 6 the code needs updating https://stackoverflow.com/questions/63368787/sequelize-findorcreate-spread-is-not-a-function The .findOrCreate{}.spread() paradigm is used in multiple places https://github.com/ging/fiware-idm/search?q=spread in the code base, can you check which functions have not been updated and fix and test them.

— Reply to this email directly, view it on GitHub https://github.com/ging/fiware-idm/issues/310, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFPBAHX2DX65XRGDWTRF4DWQ7OZRANCNFSM6AAAAAATS34B3M. You are receiving this because you are subscribed to this thread.

jason-fox commented 1 year ago

Thanks for that @sanpago - will there be a Docker image made available (e.g. updated 8.3.1 or 8.3.2 maybe?) which includes this fix, so that the tutorial can be updated?