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

Exception occurred in setAtPath which is not caught and it changed the complete response of the workflow #1002

Open
gurjotkaur20 opened this issue Mar 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@gurjotkaur20
Copy link
Contributor

Version Information

@godspeedsystems/core: 2.4.7

Current Behavior

This is the yaml workflow:

summary: get user
on_error:
  continue: false
tasks:
  - id: user_one
    fn: crud.user.fetch_user
    args: <% inputs %>
  - id: return_response
    fn: com.gs.return
    authz:
      - id: authz_task
        fn: crud.user.authz_check_user
        args:
          inputs: <% inputs %>
          user_roles: <% outputs.user_one.data?.roles %>
    on_error:
      response: <% outputs.return_response.data %>
    args: <% outputs.user_one.data %>

This is the authz workflow:

import { GSContext, GSStatus } from '@godspeedsystems/core';
export default async function(ctx: GSContext, args: any) {
    const {childLogger, mappings, config} = ctx;
    const inputs_user_roles = args?.inputs?.roles;
    const user_roles = args?.user_roles?.map((role: any) => role.name);
    let success: boolean = false;
    let code = 403;
    let message: string = "Authorization Passed";
    try {
        if (inputs_user_roles.includes(mappings[config.bank].rbac_policies.rbac.ADMIN_ROLE)) {
          success = true;
          code = 200;
        } else if (inputs_user_roles.includes(mappings[config.bank].rbac_policies.rbac.SYSTEM_ADMIN_ROLE) && !user_roles.includes(mappings[config.bank].rbac_policies.rbac.ADMIN_ROLE)) {
          success = true;
          code = 200;
        } else {
          success = false;
          message = "Cannot access user with Admin privileges";
        }
      return new GSStatus(success, code, message);
    } catch (error: any) {
      const errorData = error.stack || error;
      return new GSStatus(false, 403, undefined, errorData, undefined);
    }
}  

An exception occurred in authz workflow which should have been set in <% outputs.return_response.data %>.
authz exception:

{"code":403,"success":false,"data":"TypeError: Cannot read properties of undefined (reading 'includes')\n    at GSFunction.<anonymous> (/home/dist/functions/crud/user/authz_check_user.js:58:35)\n    at Generator.next (<anonymous>)"}

setAtPath exception:

err: {
      "type": "TypeError",
      "message": "Cannot create property 'message' on string 'TypeError: Cannot read properties of undefined (reading 'includes')\n    at GSFunction.<anonymous> (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:58:35)\n    at Generator.next (<anonymous>)\n    at asyncGeneratorStep (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:17:28)\n    at _next (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:35:17)\n    at /home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:40:13\n    at new Promise (<anonymous>)\n    at GSFunction.<anonymous> (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:32:16)\n    at GSFunction._ref (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:74:17)\n    at GSFunction._default [as fn] (/home/gurjot/data/cli-test/test/dist/functions/crud/user/authz_check_user.js:45:17)\n    at GSFunction.<anonymous> (/home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:291:38)\n    at Generator.next (<anonymous>)\n    at /home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:4:12)\n    at GSFunction._executefn (/home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:219:16)\n    at GSFunction.<anonymous> (/home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:544:41)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/gurjot/data/cli-test/gs-node-service/dist/core/interfaces.js:5:58)'"

outputs.return_response

{"code":200,"success":true,"data":{"message":"Internal server error"}}

Expected Behavior

outputs.return_response

{"code":403,"success":false,"data":"TypeError: Cannot read properties of undefined (reading 'includes')\n    at GSFunction.<anonymous> (/home/dist/functions/crud/user/authz_check_user.js:58:35)\n    at Generator.next (<anonymous>)"}}
@gurjotkaur20 gurjotkaur20 added the bug Something isn't working label Mar 7, 2024
@mastersilv3r
Copy link
Contributor

mastersilv3r commented Mar 8, 2024

In the authorization handling, within godspeed.ts, if workflow response's GSStatus.success === true, then exitWithStatus is deleted from the GSSTatus. So the issue is within the workflow, it should return success false with code 503. Else auth flow will set code 403 by default..

@gurjotkaur20
Copy link
Contributor Author

Did not understand this. My authz workflow is returning success: false. See this in the authz workflow present in the issue description:

return new GSStatus(false, 403, undefined, errorData, undefined);

Why this output?

{"code":200,"success":true,"data":{"message":"Internal server error"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants